﻿// Create a namespace for contract services.
CargoTrak.Register("ct.UI");

// Create an object for contract navigator operations.
ct.UI = (function () {
   return {
      enhanceContent: enhanceContent
   };

   function enhanceContent($scope) {
      // Make sure the content div is unhidden.
      $("#contentdiv", $scope).removeClass("hidden");

      enhanceSmartDopdowns();

      // Set focus on the first item having the .focus class.
      // set initial focus. ALWAYS DO THIS LAST.
      $(".focus", $scope).first().focus();
   }

   // Adds behavior to Telerik combobox so that it gets cleared
   // when no dropdown match is highlighted. This is done by attaching
   // a function to the blur event of the input element used by the Telerik
   // dropdown.
   function enhanceSmartDopdowns($scope) {      
      $(".smartdropdown input.rcbInput", $scope).blur(function () {         
         // Telerik dropdown client id looks like this:
         // ctl00_phMain_Panel1_cboVoyages_ddComboBox_Input
         // Need to drop '_Input' to get reference to the Telerik dropdown
         // client object.
         var idArray = $(this).attr("id").split("_");
         var id = idArray.slice(0, idArray.length - 1).join("_");
         var dropdown = $find(id);
         if (!dropdown.get_highlightedItem()) {
            dropdown.set_text("");
            dropdown.clearSelection();
         }
      });
   }
})();
