	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, April 2006
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	
	var ajaxBox_offsetX = 0;
	var ajaxBox_offsetY = 0;
	//var ajax_list_externalFile = 'productlist.asp';	// Path to external file
	var minimumLettersBeforeLookup = 1;	// Number of letters entered before a lookup. Default as 1
	
	var ajax_list_objects = new Array();
	var ajax_list_cachedLists = new Array();
	var ajax_list_activeInput = false;
	var ajax_list_activeItem;
	var ajax_list_optionDivFirstItem = false;
	var ajax_list_currentLetters = new Array();
	var ajax_optionDiv = false;
	var ajax_optionDiv_iframe = false;

	var ajax_list_MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true;
	
	function ajax_getTopPos(inputObj)
	{
		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	function ajax_list_cancelEvent()
	{
		return false;
	}
	
	function ajax_getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  
	  return returnValue;
	}
	
	function ajax_option_setValue(e,inputObj)
	{
		
		if(!inputObj)inputObj=this;
		ajax_list_activeInput.value = inputObj.innerHTML.replace(/&amp;/g , "&");
		InputName = ajax_list_activeInput.name;
		InputName = InputName.substring(InputName.indexOf('ID'));
		if(document.getElementById('Secondary_' + InputName)) {
			document.getElementById('Secondary_' + InputName).value = inputObj.id.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Tertiary_' + InputName)) {
			document.getElementById('Tertiary_' + InputName).value = inputObj.id1.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Quad_' + InputName)) {
			document.getElementById('Quad_' + InputName).value = inputObj.id2.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Pent_' + InputName)) {
			document.getElementById('Pent_' + InputName).value = inputObj.id3.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Hex_' + InputName)) {
			document.getElementById('Hex_' + InputName).value = inputObj.id4.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Hep_' + InputName)) {
			document.getElementById('Hep_' + InputName).value = inputObj.id5.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Oct_' + InputName)) {
			document.getElementById('Oct_' + InputName).value = inputObj.id6.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Sep_' + InputName)) {
			document.getElementById('Sep_' + InputName).value = inputObj.id7.replace(/&amp;/g , "&");
		}
		if(document.getElementById('Dec_' + InputName)) {
			document.getElementById('Dec_' + InputName).value = inputObj.id8.replace(/&amp;/g , "&");
		}		
		if(document.getElementById('P11_' + InputName)) {
			if(document.getElementById('P11_' + InputName).type=='checkbox') {
				if(inputObj.id9.replace(/&amp;/g , "&")=='1' || inputObj.id9.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P11_' + InputName).checked = true;
				} else {
					document.getElementById('P11_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P11_' + InputName).value = inputObj.id9.replace(/&amp;/g , "&");
			}
		}	
		if(document.getElementById('P12_' + InputName)) {
			if(document.getElementById('P12_' + InputName).type=='checkbox') {
				if(inputObj.id10.replace(/&amp;/g , "&")=='1' || inputObj.id10.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P12_' + InputName).checked = true;
				} else {
					document.getElementById('P12_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P12_' + InputName).value = inputObj.id10.replace(/&amp;/g , "&");
			}
		}	
		if(document.getElementById('P13_' + InputName)) {
			if(document.getElementById('P13_' + InputName).type=='checkbox') {
				if(inputObj.id11.replace(/&amp;/g , "&")=='1' || inputObj.id11.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P13_' + InputName).checked = true;
				} else {
					document.getElementById('P13_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P13_' + InputName).value = inputObj.id11.replace(/&amp;/g , "&");
			}
		}	
		if(document.getElementById('P14_' + InputName)) {
			if(document.getElementById('P14_' + InputName).type=='checkbox') {
				if(inputObj.id12.replace(/&amp;/g , "&")=='1' || inputObj.id12.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P14_' + InputName).checked = true;
				} else {
					document.getElementById('P14_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P14_' + InputName).value = inputObj.id12.replace(/&amp;/g , "&");
			}
		}	
		if(document.getElementById('P15_' + InputName)) {
			if(document.getElementById('P15_' + InputName).type=='checkbox') {
				if(inputObj.id13.replace(/&amp;/g , "&")=='1' || inputObj.id13.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P15_' + InputName).checked = true;
				} else {
					document.getElementById('P15_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P15_' + InputName).value = inputObj.id13.replace(/&amp;/g , "&");
			}
		}		
		if(document.getElementById('P16_' + InputName)) {
			if(document.getElementById('P16_' + InputName).type=='checkbox') {
				if(inputObj.id14.replace(/&amp;/g , "&")=='1' || inputObj.id14.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P16_' + InputName).checked = true;
				} else {
					document.getElementById('P16_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P16_' + InputName).value = inputObj.id14.replace(/&amp;/g , "&");
			}
		}
		if(document.getElementById('P17_' + InputName)) {
			if(document.getElementById('P17_' + InputName).type=='checkbox') {
				if(inputObj.id15.replace(/&amp;/g , "&")=='1' || inputObj.id15.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P17_' + InputName).checked = true;
				} else {
					document.getElementById('P17_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P17_' + InputName).value = inputObj.id15.replace(/&amp;/g , "&");
			}
		}		
		if(document.getElementById('P18_' + InputName)) {
			if(document.getElementById('P18_' + InputName).type=='checkbox') {
				if(inputObj.id16.replace(/&amp;/g , "&")=='1' || inputObj.id16.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P18_' + InputName).checked = true;
				} else {
					document.getElementById('P18_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P18_' + InputName).value = inputObj.id16.replace(/&amp;/g , "&");
			}
		}
		if(document.getElementById('P19_' + InputName)) {
			if(document.getElementById('P19_' + InputName).type=='checkbox') {
				if(inputObj.id17.replace(/&amp;/g , "&")=='1' || inputObj.id17.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P19_' + InputName).checked = true;
				} else {
					document.getElementById('P19_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P19_' + InputName).value = inputObj.id17.replace(/&amp;/g , "&");
			}
		}		
		if(document.getElementById('P20_' + InputName)) {
			if(document.getElementById('P20_' + InputName).type=='checkbox') {
				if(inputObj.id18.replace(/&amp;/g , "&")=='1' || inputObj.id18.replace(/&amp;/g , "&").toUpperCase()=='Y') {
					document.getElementById('P20_' + InputName).checked = true;
				} else {
					document.getElementById('P20_' + InputName).checked = false;
				}
			} else {
				document.getElementById('P20_' + InputName).value = inputObj.id18.replace(/&amp;/g , "&");
			}
		}		
		// use inputObj.id2, inputObj.id3, inputObj.id4 etc as necessary
		//alert(InputName);
		if(document.getElementById('Quad_' + InputName)) {
			//for POS focus during scanning
			if(InputName=='scanstr'){
				//alert('hi');
				document.getElementById('Quad_' + InputName).focus();
			}
		}
		ajax_options_hide();
	}
	
	function ajax_options_hide()
	{
		ajax_optionDiv.style.display='none';	
		if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none';
	}

	function ajax_options_rollOverActiveItem(item,fromKeyBoard)
	{
		if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv';
		item.className='optionDivSelected';
		ajax_list_activeItem = item;
		
		if(fromKeyBoard){
			if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){
				ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ;
			}
			if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop)
			{
				ajax_optionDiv.scrollTop = 0;	
			}
		}
	}
	
	function ajax_option_list_buildList(letters,paramToExternalFile)
	{
		ajax_optionDiv.innerHTML = '';
		ajax_list_activeItem = false;
		
		if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){
			ajax_options_hide();
			return;			
		}

		ajax_list_optionDivFirstItem = false;
		var optionsAdded = false;
		for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
			optionsAdded = true;
			var div = document.createElement('DIV');
			var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi);
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){
				ajax_options_hide();
				return;						
			}
			
			if (items[items.length-1] != "exclude") {
				div.innerHTML = items[items.length-1].replace(/&/g, "&amp;");
				div.id = items[0].replace(/&/g, "&amp;");
				if (items[1]) {
					div.id1 = items[1].replace(/&/g, "&amp;");
				}
				if (items[2]) {
					div.id2 = items[2].replace(/&/g, "&amp;");
				}
				if (items[3]) {
					div.id3 = items[3].replace(/&/g, "&amp;");
				}
				if (items[4]) {
					div.id4 = items[4].replace(/&/g, "&amp;");
				}
				if (items[5]) {
					div.id5 = items[5].replace(/&/g, "&amp;");
				}
				if (items[6]) {
					div.id6 = items[6].replace(/&/g, "&amp;");
				}
				if (items[7]) {
					div.id7 = items[7].replace(/&/g, "&amp;");
				}
				if (items[8]) {
					div.id8 = items[8].replace(/&/g, "&amp;");
				}			
				if (items[9]) {
					div.id9 = items[9].replace(/&/g, "&amp;");
				}			
				if (items[10]) {
					div.id10 = items[10].replace(/&/g, "&amp;");
				}				
				if (items[11]) {
					div.id11 = items[11].replace(/&/g, "&amp;");
				}		
				if (items[12]) {
					div.id12 = items[12].replace(/&/g, "&amp;");
				}		
				if (items[13]) {
					div.id13 = items[13].replace(/&/g, "&amp;");
				}					
				if (items[14]) {
					div.id14 = items[14].replace(/&/g, "&amp;");
				}		
				if (items[15]) {
					div.id15 = items[15].replace(/&/g, "&amp;");
				}	
				if (items[16]) {
					div.id16 = items[16].replace(/&/g, "&amp;");
				}	
				if (items[17]) {
					div.id17 = items[17].replace(/&/g, "&amp;");
				}				
				if (items[18]) {
					div.id18 = items[18].replace(/&/g, "&amp;");
				}					
				// use div.id1 = items[1], div.id2 = items[2] etc as necessary
				div.className='optionDiv';
				div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) }
				div.onclick = ajax_option_setValue;
				if(!ajax_list_optionDivFirstItem)ajax_list_optionDivFirstItem = div;
				ajax_optionDiv.appendChild(div);
			}
		}	
		if(optionsAdded){
			ajax_optionDiv.style.display='block';
			if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='';
		}
					
	}
	
	function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile) {
		var letters = inputObj.value;
		var content = ajax_list_objects[ajaxIndex].response;
		var elements = content.split('|');
		ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
		ajax_option_list_buildList(letters,paramToExternalFile);		
	}
	
	function ajax_option_resize(inputObj) {
		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}		
	}
	
	function ajax_showOptions(inputObj,paramToExternalFile, ajax_list_externalFile, minimumLettersBeforeLookup) {
		
		if (inputObj.readOnly != true) {
		//paramToExternalFile = paramToExternalFile.replace(/&/g,"%26");
		//paramToExternalFile = paramToExternalFile.replace(/\?/g,"%3F");
		//paramToExternalFile = paramToExternalFile.replace(/=/g,"%3D");
		//paramToExternalFile = paramToExternalFile.replace(/\+/g,"%2B");

		if (minimumLettersBeforeLookup != 0) {
		if(ajax_list_currentLetters[inputObj.name]==inputObj.value)return;
		}
		if(!ajax_list_cachedLists[paramToExternalFile])ajax_list_cachedLists[paramToExternalFile] = new Array();
		ajax_list_currentLetters[inputObj.name] = inputObj.value;
		
		if(!ajax_optionDiv){
			ajax_optionDiv = document.createElement('DIV');
			ajax_optionDiv.id = 'ajax_listOfOptions';	
			document.body.appendChild(ajax_optionDiv);
			
			if(ajax_list_MSIE){
				ajax_optionDiv_iframe = document.createElement('IFRAME');
				ajax_optionDiv_iframe.border='0';
				ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px';
				ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px';
				ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe';
				
				document.body.appendChild(ajax_optionDiv_iframe);
			}
			
			var allInputs = document.getElementsByTagName('INPUT');
			for(var no=0;no<allInputs.length;no++){
				if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide;
			}			
			var allSelects = document.getElementsByTagName('SELECT');
			for(var no=0;no<allSelects.length;no++){
				allSelects[no].onfocus = ajax_options_hide;
			}

			var oldonkeydown=document.body.onkeydown;
			if(typeof oldonkeydown!='function'){
				document.body.onkeydown=ajax_option_keyNavigation;
			}else{
				document.body.onkeydown=function(){
					oldonkeydown();
				ajax_option_keyNavigation() ;}
			}
			var oldonresize=document.body.onresize;
			if(typeof oldonresize!='function'){
				document.body.onresize=function() {ajax_option_resize(inputObj); };
			}else{
				document.body.onresize=function(){oldonresize();
				ajax_option_resize(inputObj) ;}
			}
				
		}
		
		if(inputObj.value.length<minimumLettersBeforeLookup){
			ajax_options_hide();
			return;
		}

		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}
		
		ajax_list_activeInput = inputObj;
		ajax_optionDiv.onselectstart =  ajax_list_cancelEvent;
		
		if (minimumLettersBeforeLookup != 0) {// only load from cache if minletters >=1
			//if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){ commented out so that never loads from cache
				//ajax_option_list_buildList(inputObj.value,paramToExternalFile);			
			//}else{
				ajax_optionDiv.innerHTML = '';
				var ajaxIndex = ajax_list_objects.length;
				ajax_list_objects[ajaxIndex] = new sack();
				
				var url = ajax_list_externalFile + '&param=' + encodeURIComponent(paramToExternalFile) + '&letters=' + encodeURIComponent(inputObj.value);
				ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
				ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile); };	// Specify function that will be executed after file has been found
				ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function	
			//}
		}
		else {
			ajax_optionDiv.innerHTML = '';
				var ajaxIndex = ajax_list_objects.length;
				ajax_list_objects[ajaxIndex] = new sack();
				//alert(encodeURIComponent(paramToExternalFile));
				var url = ajax_list_externalFile + '&param=' + encodeURIComponent(paramToExternalFile) + '&letters=' + encodeURIComponent(inputObj.value);
				ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
				ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile); };	// Specify function that will be executed after file has been found
				ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function
		}
		}
	}
	
	function ajax_option_keyNavigation(e)
	{
		if(document.all)e = event;
		
		if(!ajax_optionDiv)return;
		if(ajax_optionDiv.style.display=='none')return;
		
		if(e.keyCode==38){	// Up arrow
			if(!ajax_list_activeItem)return;
			if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return;
			ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true);
		}
		
		if(e.keyCode==40){	// Down arrow
			if(!ajax_list_activeItem){
				ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
			}else{
				if(!ajax_list_activeItem.nextSibling)return;
				ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true);
			}
		}
		
		if(e.keyCode==13 || e.keyCode==9){	// Enter key or tab key
			if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')ajax_option_setValue(false,ajax_list_activeItem);
			if(e.keyCode==13)return false; else return true;
		}
		if(e.keyCode==27){	// Escape key
			ajax_options_hide();			
		}
	}