var typeAheadInfo = {last:0, 
                     currentString:"", 
                     delay:500,
                     timeout:null, 
                     reset:function() {this.last=0; this.currentString=""}
                    };

function typeAhead() {
	var thekey = window.event.keyCode;
	if (thekey==9) return true;
      if (window.event && !window.event.ctrlKey) {
	var now = new Date();

      if (typeAheadInfo.currentString == "" || now - typeAheadInfo.last < typeAheadInfo.delay) {

         var myEvent = window.event;
         var selectElement = myEvent.srcElement;
         var keyCode = myEvent.keyCode;

		 // The NumPad returns slightly differant keyCodes then the numbers on the type of the keyboard.
		 // If we subtract 48 it will return the correct keyCode.
		 if (keyCode >= 96 && keyCode <=105) {
		 keyCode = keyCode - 48;
		 }         
         
         var newChar =  String.fromCharCode(keyCode).toUpperCase();
         typeAheadInfo.currentString += newChar;

         var selectOptions = selectElement.options;
         var txt, nearest;
         for (var i = 0; i < selectOptions.length; i++) {
            // change this from .text to .value to use the value of the item instead of the visual text if desired
            txt = selectOptions[i].text.toUpperCase();
            nearest = (typeAheadInfo.currentString > 
                       txt.substr(0, typeAheadInfo.currentString.length)) ? i : nearest;

            if (txt.indexOf(typeAheadInfo.currentString) == 0) {
               clearTimeout(typeAheadInfo.timeout);
               typeAheadInfo.last = now;
               typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
               selectElement.selectedIndex = i;

               myEvent.cancelBubble = true;
               myEvent.returnValue = false;

               return false;   
            }            
         }
         if (nearest != null) {
            selectElement.selectedIndex = nearest;
         }
      } else {
         clearTimeout(typeAheadInfo.timeout);
      }
      typeAheadInfo.reset();
   }
   return true;
}