var searchString = "";

function resetSearch() {
	searchString = "";
}

function search(event, form, fieldName) {

  if(!event){ event = window.event;}
  
  if(event.keyCode == 16 || event.keyCode == 17) {//Shift OR Ctrl Key
    return false;
  }
  
  if( event.keyCode >= 96 && event.keyCode <= 105 ) {//is a number pad entry
    searchString += getNumKeyPadEntry(event);
  }else{
    searchString += String.fromCharCode(event.keyCode);
  }
  
  var theMatches = [];
  for(var i = 0; i < form.elements[fieldName].length; i++){
    var anOption = form.elements[fieldName][i].innerHTML;
    if (anOption.indexOf(searchString) == 0) { 
      theMatches.push(i);
    }
  }
  
  //pass the first of the match to select the first option
  var theSelectedIndex = -1;
  if(theMatches[0] != undefined){
    theSelectedIndex = theMatches[0];
  }
  
  form.elements[fieldName].selectedIndex = theSelectedIndex;

}

//the keypad entry was acting funky so handle it here
function getNumKeyPadEntry(event){
  var keyPressValue = "";
  switch (event.keyCode)
  {
    case 96:
      keyPressValue = "0";
      break;
    case 97:
      keyPressValue = "1";
      break;
    case 98:
      keyPressValue = "2";
      break;
    case 99:
      keyPressValue = "3";
      break;
    case 100:
      keyPressValue = "4";
      break;
    case 101:
      keyPressValue = "5";
      break;
    case 102:
      keyPressValue = "6";
      break;
    case 103:
      keyPressValue = "7";
      break;
    case 104:
      keyPressValue = "8";
      break;
    case 105:
      keyPressValue = "9";
      break;                                         
  }
  return keyPressValue;
}