//****** The following code is required to get the vb dropdown like functionality on the hardware edit combo
//This was sourced from http://www.petenelson.com/aspwatch/ASPWatch%20%20Make%20HTML%20Combo%20Boxes%20Behave%20Like%20VB%20Combo%20Boxes.htm
//Written by Pete Nelson
// This is a global value to determine which item to select
var selectedOption = 0;
var KeyPressEnabled = true;
var _RunOnBlur = true;
//This keeps track of what the user has typed so far in the dropdown
var typedText = ""
function SelectChange(comboObj)
{
   // We use this function to disable any dynamic selecting of the
   // combo-box when the user uses the mouse to select items.
   //alert("Keppressenabled" + KeyPressEnabled);
   if (KeyPressEnabled)
   {
	   comboObj.selectedIndex = selectedOption;   
//      feForm.state_hwEditCombo.selectedIndex = selectedOption;   
   }
}

function RunOnBlur()
{
if (_RunOnBlur) 
{
  _RunOnBlur=true;
  return true;
}
else 
{
  _RunOnBlur=true;
  return false;
}
}

function KeyPress(comboObj)
{
  //Need to refocus it so that if it is dropped down (open) it will close, this ensures the keypress stuff
  //works correctly. Set runonblur to false because this focus will cause a blur event on which we don't want to
  //run the onblur of the dropdownlist.
  _RunOnBlur=false;
   comboObj.focus();
  

   KeyPressEnabled = true;

//   var editCombo = feForm.state_hwEditCombo;
	   var editCombo = comboObj;

   // Keycode 38 and 40 are the up and down arrow buttons, in case the user
   // uses the arrow keys to select items. We reset the value of what they
   // have typed and change the global selected item value.
   if (event.keyCode == 38)
   {
      typedText = "";
      selectedOption = editCombo.selectedIndex - 1;
      return;
   }
   
   if (event.keyCode == 40)
   {
      typedText = "";
      selectedOption = editCombo.selectedIndex + 1;
      return;
   }


   // Keycode 27 is escape, so the user can clear out what
   // they have typed so far
   if (event.keyCode == 27)
   {
      editCombo.selectedIndex = 0;
      typedText = "";
      return;
   }

   // Keycode 32 is a space
   if (event.keyCode != 32)
   {
      // Only process the key if it's a letter or number
      if (event.keyCode < 48 || event.keyCode > 90)
         return;
   }

 

   // Convert the ASCII keycode value to a character and add the key
   // entered to a "buffer". 
   typedText += String.fromCharCode(event.keyCode).toLowerCase();
   //Capital A
   //if (event.keyCode == 65)
   //{
    //alert(typedText);
   //}


   // Loop through the select list to find any matches   
   for (x = 0; x < editCombo.length; x++)
   {
   
      var OptionText = editCombo.options[x].text;
      var tmpOptionText = "";
         
      // Loop through the value of each select item, and if there is a
      // match on what they have typed in, set the global variable for that value.
       // The browser will run the onChange event since you typed a key. We'll
      // run SelectChange() in the onChangeEvent just to be sure.
      for (y = 0; y < OptionText.length; y ++)
      {
         tmpOptionText += OptionText.charAt(y).toLowerCase();
      
         if (tmpOptionText == typedText)
         {
         //alert("Match tmpOptionText - " + tmpOptionText  + " typedText - " + typedText);
            editCombo.selectedIndex = x;
            selectedOption = x;
            return;
         }
      }
   }
}
