var to_find    = "";
var timeoutCtr = 0;
var selectBox;
var txtFind;
var keycode;
var codeBox;

function findMatch2(s, t, c){
	timeoutCtr = new Date().getTime();
	selectBox  = s;
	txtFind    = t;
	codeBox    = c;
	keycode    = event.keyCode;
	
	setTimeout("findMatch()", 10);
}
 
function findMatch() {
	if (new Date().getTime() - timeoutCtr < 0) return false;
	if (txtFind == '' || keycode == 16) {
		return false;
	}

	to_find = txtFind.value
	if(keycode==8) to_find = to_find.substr(0, to_find.length-1);

	if(to_find.length==0){
		txtFind.value='';
		return false;
	}

	allWords    = selectBox.options;
	var posLow  = 0;
	var posHigh = allWords.length;
	var foundIt = false;
	s2          = to_find.toLowerCase();
	while (posLow <= posHigh) { 
		posMid = Math.floor((posLow + posHigh) / 2); 
		s1     = allWords[posMid].text;
		s      = allWords[posMid].text.toLowerCase();
		if (s.indexOf(s2) == 0){
			go = true;
			for (var i=posMid; i>=0; i--){
				if(allWords[i].text.toLowerCase().indexOf(s2) == 0){
					s1     = allWords[i].text;
					s      = allWords[i].text.toLowerCase();
				} else {
					break;
				}
			}
			posMid                  = i+1;
			foundIt                 = true;
			selectBox.selectedIndex = posMid;
			codeBox.value           = selectBox[selectBox.selectedIndex].value;
			var t                   = s.length - (s.length - s2.length);
			end_string              = s.substr(t, s.length);
			txtFind.value           = s1;
			if (end_string != "") {
				var range = txtFind.createTextRange();
				range.moveStart('character', txtFind.value.toLowerCase().lastIndexOf(end_string));
				range.select();
			}
 			return true;
		} else {
			if (s2 < s) {
				posHigh = posMid - 1;
			} else {
				posLow  = posMid + 1;
			}
		}
	}
}
function getInfo(e, obj,c){
	if(e.selectedIndex>=1) obj.value=e[e.selectedIndex].text;
	if(e.selectedIndex>=1) c.value=e[e.selectedIndex].value;
}
