//these global variables are used in the option find functions 
var v=''
var starttime=0;
var lasttime=0;
var endtime=0;
var v_collection=""
var selectedIt=false
var start=0
var char1=0
var char2=1
var char3=2 

var v_start=0  //used by quickOptionFind function
var setFirst=true //used by quickOptionFind function


//*****Key Hunt functions include file******

//this function is called by the keydown event on a page to allow multiple keys to be
//entered on the drop-down box to move to the closest match starting with first letter, subsequent letters
//resets first letter if there is a pause greater than 2 sec or if same letter is hit 3 times in a row
function quickOptionFind(objname){

	starttime=starttimer()
	v_time=(starttime-lasttime)/2000 //get secs elapsed
	lasttime=starttime
	v=event.keyCode //get keycode from keydown event
	if(v>95 && v<106 ) v=v-48; //this will convert numpad keys to corresponding number values
	char3=char2
	char2=char1
	char1=v
	if(char1==char2 && char2==char3 && char3==char1) v_time=3;
	
	if(v_time>2){ //if more that 2 secs has passed reset v_collection
 		v_collection=""; //reset search string
		setFirst=true
		char1=0
		char2=1
		char3=2
		//starttime=starttimer()//its a new search string
	}
	else{
		setFirst=false
		
	}
	
	
	x=String.fromCharCode(v) //convert it to character
	v_collection=v_collection+x  //add to the search string
	
	if(setFirst==false){ //if its not the first letter run the search otherwise let onkeypress setIndex, much faster
	selectedIt=false //reset found match flag
	
	var i=0
	var count=0
	var optqty=0
	//narrow search to closet 2 elements
	valueComp(eval("document.all."+objname+".length"),0,v_collection,objname);
 	i=v_start //sets index starting point to final value from valueComp func
 
 	optqty=eval("document.all."+objname+".length")-i
	//alert(optqty)
 	do{
		s=eval("document.all."+objname+".options["+i+"].text.toUpperCase()") //get text from next option
		//s=employee[i][1].toUpperCase()
		if(s.indexOf(v_collection)==0 ){ //does it find the sting at the start of the option text
			eval("document.all."+objname+".selectedIndex=i")//this is needed to allow one selection in multiple boxes
			eval("document.all."+objname+".options[i].selected=true")// select matching option, this may be redundant after setting selectedIndex
			x=" "+eval("document.all."+objname+".onchange")//get onchange function from object
			if(x!=" null"){
				x2=x.substring(x.indexOf("{")+1,x.length-1)
				eval(x2)//exec on change function
			}
			selectedIt=true// set this to true the loop will end now that is has match
		} //if
	i++ //index number for options
	count++ //used to make sure we dont go past end of array or loop through more than ten since its already narrowed down
	if(count==optqty || count==10) break; //kick out of loop if we hit end of file or after you have checked ten, 10 is arbitrary, it may only need to be 2 but not sure yet
	}while(selectedIt==false )
	selectedIt=true
	event.returnValue=true
	}//if it's the first letter skip the search and let default onkeypress action find first letter,much faster on slow machines, don't know why
}//end function


//this function is used to find the closest option match by quickOptionFind func 
function valueComp(qty,top,v_str,objname){

	qty=Math.round(qty/2)
	v=qty+top-1
	opt=eval("document.all."+objname+".options["+v+"].text.toUpperCase()")
	
	if (v_str>opt){
		top=top+qty-1 //set new start point
	}//end if
	if(qty>2 ){
		valueComp(qty,top,v_str,objname)
	}//if >2
	else
	{	
		v_start=top
		
	}// end if >50
}//end function

//used by quickOptionFind func to set timing on key entry
function starttimer() {
d_start = new Date(); 
v_starttimer = d_start.getTime();
return v_starttimer
} 

//******End Functions******


