var strglobalName;

function Menu_Appear(strName, strDataName, strTop, strLeft) {
//
//  Move the menu to a new place and make it appear.
//
	document.all(strName).style.visibility='visible';
	document.all(strName).style.display='inline';
	document.all(strName).size=10;
	document.all(strName).style.position='absolute';
	document.all(strName).style.top = strTop;
	document.all(strName).style.left = strLeft;

	strglobalName = strDataName
}

function Menu_Disappear(strName) {
//
//  Make the menu disappear
//
	document.all(strName).style.visibility='hidden';
	document.all(strName).size=0;
}

function Select_Option(object) {
//
//  The user has clicked on an entry in the <SELECT> control.
//
	document.all(strglobalName).value=object.options[object.selectedIndex].text;
	object.style.visibility='hidden';
	object.size=0;
        document.form1.addr_street.focus
	return true;
}
function Search_Menu(object,strName) {
//
//  This will search the <SELECT> control defined by strName jumping to the appropariate entry based
//   on what the user types.  If the user clicks or presses the <ENTER> key the results will be places
//   in the object control.
//
//  strName is the name of the <SELECT> control.
//  object is the target to place the street name
//
	var intStart, intEnd, intMid, intMax;
	var strOne, strTwo;

	intStart = 0;
	intEnd = document.all(strName).length;
	intMax = intEnd -1;
	intLen = object.value.length;

	switch (event.keyCode) {
		case 40 :  // Down arrrow
			if (document.all(strName).selectedIndex < intMax) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex + 1;
			}
			break;
		case 38 :  // Up arrow
			if (document.all(strName).selectedIndex > 0) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex - 1;
			}
			break;
		case 34 :  // Page Down
			if (document.all(strName).selectedIndex + 10 < intMax) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex + 10;
			}
			else {
				document.all(strName).selectedIndex = intMax;
			}
			break;
		case 33 :  // Page Up
			if (document.all(strName).selectedIndex > 10) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex - 10;
			}
			else {
				document.all(strName).selectedIndex = 0
			}
			break;
		case 13 :  // Enter
			object.value=document.all(strName).options[document.all(strName).selectedIndex].value;
			Menu_Disappear(strName);
			break;
		default :
			if (intLen > 0) {
			do {
				intMid = Math.floor((intStart + intEnd) /2);
				strOne = object.value.toUpperCase();
				strTwo = document.all(strName).options[intMid].text.substring(0,intLen).toUpperCase();

				if (strOne > strTwo) {
					intStart = intMid;
				} 
				else {
					intEnd = intMid;
				}
			}
			while (intStart+ 1 < intEnd );
//
//  Found it perhaps
//
			if (intEnd != document.all(strName).length) {
//
//  Start from the bottom of the list so that the selcted item is on the top (as opposed to the bottom)
//
				document.all(strName).options[document.all(strName).length-1].selected=true;
				document.all(strName).options[intEnd].selected=true;
			}
		}
	}
}

function REVSearch_Menu(object,strName) {
//
//  This will search the <SELECT> control defined by strName jumping to the appropariate entry based
//   on what the user types.  If the user clicks or presses the <ENTER> key the results will be places
//   in the object control.
//
//  strName is the name of the <SELECT> control.
//  object is the target to place the street name
//
	var intStart, intEnd, intMid, intMax;
	var strOne, strTwo;

	intStart = 0;
	intEnd = document.all(strName).length;
	intMax = intEnd -1;
	intLen = object.value.length;

	switch (event.keyCode) {
		case 40 :  // Down arrrow
			if (document.all(strName).selectedIndex < intMax) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex + 1;
			}
			break;
		case 38 :  // Up arrow
			if (document.all(strName).selectedIndex > 0) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex - 1;
			}
			break;
		case 34 :  // Page Down
			if (document.all(strName).selectedIndex + 10 < intMax) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex + 10;
			}
			else {
				document.all(strName).selectedIndex = intMax;
			}
			break;
		case 33 :  // Page Up
			if (document.all(strName).selectedIndex > 10) {
				document.all(strName).selectedIndex = document.all(strName).selectedIndex - 10;
			}
			else {
				document.all(strName).selectedIndex = 0
			}
			break;
		case 13 :  // Enter
			object.value=document.all(strName).options[document.all(strName).selectedIndex].value.toUpperCase();
			Menu_Disappear(strName);
			break;
		default :
			if (intLen > 0) {
			do {
				intMid = Math.floor((intStart + intEnd) /2);
				strOne = object.value.toUpperCase();
				strTwo = document.all(strName).options[intMid].text.substring(0,intLen).toUpperCase();
				if (strOne < strTwo) {
					intStart = intMid;
				} 
				else {
					intEnd = intMid;
				}
			}
			while (intStart+ 1 < intEnd );
//alert('DONE' + strOne + ' - ' + strTwo + ' Start:' + intStart + ' Mid:' + intMid + ' End:' + intEnd + ' Last:' + document.all(strName).length);
//
//  Found it perhaps
//
			if (intEnd != document.all(strName).length) {
//
//  Start from the bottom of the list so that the selcted item is on the top (as opposed to the bottom)
//
				document.all(strName).options[document.all(strName).length-1].selected=true;
				document.all(strName).options[intEnd].selected=true;
//alert('Selected ' + intEnd );
			}
		}
	}
}

