        /*
        document.write("<script type='text/javascript' src='inc.js'></script>");
        */
        //var web_server="10.1.1.12/jiong/";
        var web_server="/jiong/";

	var desc_ajaxBox_offsetX = 0;
	var desc_ajaxBox_offsetY = 0;
        /*
	var desc_ajax_list_externalFile_part = "http://"+web_server+"PartSearchAjax.jsp";	
	var desc_ajax_list_externalFile_acct = "http://"+web_server+"AcctSearchAjax.jsp";	
	var desc_ajax_list_externalFile_desc = "http://"+web_server+"DescSearchAjax.jsp";	
        */

        var desc_ajax_list_externalFile_part = "/jiong/PartSearchAjax.jsp";       
        var desc_ajax_list_externalFile_acct = "/jiong/AcctSearchAjax.jsp";       
        var desc_ajax_list_externalFile_desc = "/jiong/DescSearchAjax.jsp";
        var desc_ajax_list_externalFile_doc = "/jiong/AdminDocSearchAjax.jsp";
        var desc_ajax_list_externalFile_docdelete = "/jiong/AdminDocDeleteSearchAjax.jsp";

	var minimumLettersBeforeLookup_part= 2;	// Number of letters entered before a lookup is performed.
	var minimumLettersBeforeLookup_acct= 1;	// Number of letters entered before a lookup is performed.
	var minimumLettersBeforeLookup_desc= 2;	// Number of letters entered before a lookup is performed.
	var minimumLettersBeforeLookup_doc= 2;	// Number of letters entered before a lookup is performed.
	var minimumLettersBeforeLookup_docdelete= 2;	// Number of letters entered before a lookup is performed.
	
	var desc_ajax_list_objects = new Array();
	var desc_ajax_list_cachedLists = new Array();
	var desc_ajax_list_activeInput = false;
	var desc_ajax_list_activeItem;
	var desc_ajax_list_optionDivFirstItem = false;
	var desc_ajax_list_currentLetters = new Array();
	var desc_ajax_optionDiv = false;
	var desc_ajax_optionDiv_iframe = false;

	var desc_ajax_list_MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)desc_ajax_list_MSIE=true;
	
	var currentListIndex = 0;
	
	function desc_ajax_getTopPos(inputObj)
	{
		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	function desc_ajax_list_cancelEvent()
	{
		return false;
	}
	
	function desc_ajax_getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  
	  return returnValue;
	}
	
	function desc_ajax_option_setValue(e,inputObj)
	{
		if(!inputObj)inputObj=this;
		var tmpValue = inputObj.innerHTML;
		if(desc_ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
		if(!tmpValue)tmpValue = inputObj.innerHTML;
		desc_ajax_list_activeInput.value = tmpValue;
		if(document.getElementById(desc_ajax_list_activeInput.name + '_hidden'))document.getElementById(desc_ajax_list_activeInput.name + '_hidden').value = inputObj.id; 
		desc_ajax_options_hide();
	}
	
	function desc_ajax_options_hide()
	{
		if(desc_ajax_optionDiv)desc_ajax_optionDiv.style.display='none';	
		if(desc_ajax_optionDiv_iframe)desc_ajax_optionDiv_iframe.style.display='none';
	}

	function desc_ajax_options_rollOverActiveItem(item,fromKeyBoard)
	{
		if(desc_ajax_list_activeItem)desc_ajax_list_activeItem.className='optionDiv';
		item.className='optionDivSelected';
		desc_ajax_list_activeItem = item;
		
		if(fromKeyBoard){
			if(desc_ajax_list_activeItem.offsetTop>desc_ajax_optionDiv.offsetHeight){
				desc_ajax_optionDiv.scrollTop = desc_ajax_list_activeItem.offsetTop - desc_ajax_optionDiv.offsetHeight + desc_ajax_list_activeItem.offsetHeight + 2 ;
			}
			if(desc_ajax_list_activeItem.offsetTop<desc_ajax_optionDiv.scrollTop)
			{
				desc_ajax_optionDiv.scrollTop = 0;	
			}
		}
	}
	
	function desc_ajax_option_list_buildList(letters,paramToExternalFile)
	{
		
		desc_ajax_optionDiv.innerHTML = '';
		desc_ajax_list_activeItem = false;
		if(desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){
			desc_ajax_options_hide();
			return;			
		}
		
		
		
		desc_ajax_list_optionDivFirstItem = false;
		var optionsAdded = false;
		for(var no=0;no<desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){
			if(desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
			optionsAdded = true;
			var div = document.createElement('DIV');
			var items = desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi);
			
			if(desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && desc_ajax_list_activeInput.value == items[0]){
				desc_ajax_options_hide();
				return;						
			}
			
			
			div.innerHTML = items[items.length-1];
			div.id = items[0];
                        /*div.style.width="20px"; */
			div.className='optionDiv';
			div.onmouseover = function(){ desc_ajax_options_rollOverActiveItem(this,false) }
			div.onclick = desc_ajax_option_setValue;
			if(!desc_ajax_list_optionDivFirstItem)desc_ajax_list_optionDivFirstItem = div;
			desc_ajax_optionDiv.appendChild(div);
		}	
		if(optionsAdded){
			desc_ajax_optionDiv.style.display='block';
			if(desc_ajax_optionDiv_iframe)desc_ajax_optionDiv_iframe.style.display='';
			desc_ajax_options_rollOverActiveItem(desc_ajax_list_optionDivFirstItem,true);
		}
					
	}
	
	function desc_ajax_option_list_showContent(desc_ajaxIndex,inputObj,paramToExternalFile,whichIndex)
	{
		if(whichIndex!=currentListIndex)return;
		var letters = inputObj.value;
		var content = desc_ajax_list_objects[desc_ajaxIndex].response;
		var elements = content.split('|');
		desc_ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
		desc_ajax_option_list_buildList(letters,paramToExternalFile);

              //alert("inside desc_ajax_option_list_showContent, letters="+letters+" content="+content+" elements="+elements);
		
	}
	
	function desc_ajax_option_resize(inputObj)
	{
		desc_ajax_optionDiv.style.top = (desc_ajax_getTopPos(inputObj) + inputObj.offsetHeight + desc_ajaxBox_offsetY) + 'px';
		desc_ajax_optionDiv.style.left = (desc_ajax_getLeftPos(inputObj) + desc_ajaxBox_offsetX) + 'px';
		if(desc_ajax_optionDiv_iframe){
			desc_ajax_optionDiv_iframe.style.left = desc_ajax_optionDiv.style.left;
			desc_ajax_optionDiv_iframe.style.top = desc_ajax_optionDiv.style.top;			
		}		
		
	}
	
	function desc_ajax_showOptions(which, inputObj,paramToExternalFile,e)
	{
          var acct_category="acct_regular";
          var desc_display="front";
          var elements=document.getElementsByTagName('input');
          /*
          if (which=="Desc") 
             document.getElementById('desc').setAttribute("autocomplete","off");
          else if (which=="Acct") 
                   document.getElementById('login_id').setAttribute("autocomplete","off");
          else 
              document.getElementById('part').setAttribute("autocomplete","off");
          if (which=="Desc") {
             document.getElementById('desc').setAttribute("autocomplete","off");
             }
          else if (which=="Acct") {
                   document.getElementById('login_id').setAttribute("autocomplete","off");
                   }
          else {
               document.getElementById('part').setAttribute("autocomplete","off");
              }
          */


          if (which=="Acct" || which=="Desc" || which=="Doc") {
             for (var i=0; i<elements.length; i++ ) {
                if (elements[i].type=="radio" && elements[i].name=="acct_category" && elements[i].checked )
                   acct_category=elements[i].value;
                if (elements[i].type=="radio" && elements[i].name=="desc_display" && elements[i].checked )
                   desc_display=elements[i].value;
                }
             }
          if (which=="Desc" && desc_display=="background")
             return; 

         if (document.getElementById('ajax_listOfOptions')!=null ) {
             document.getElementById('ajax_listOfOptions').style.display="none";
             if (document.getElementById('ajax_listOfOptions_iframe')!=null )
                document.getElementById('ajax_listOfOptions_iframe').style.display="none";
             if (document.getElementById('ajax_listOfOptions_iframe_desc')!=null )
                document.getElementById('ajax_listOfOptions_iframe_desc').style.display="none";
             }

                
		if(e.keyCode==13 || e.keyCode==9)return;
		if(desc_ajax_list_currentLetters[inputObj.name]==inputObj.value)return;
		if(!desc_ajax_list_cachedLists[paramToExternalFile])desc_ajax_list_cachedLists[paramToExternalFile] = new Array();
		desc_ajax_list_currentLetters[inputObj.name] = inputObj.value;
                //alert("0, desc_ajax_optionDiv->"+desc_ajax_optionDiv);
		if(!desc_ajax_optionDiv){
			desc_ajax_optionDiv = document.createElement('DIV');
			desc_ajax_optionDiv.id = 'desc_ajax_listOfOptions';	
                        /*
                        if (which=="Desc" || which=="Acct") 
    			   desc_ajax_optionDiv.style.width = '390px';	
                        else 
    			   desc_ajax_optionDiv.style.width = '250px';	
                        */
			document.body.appendChild(desc_ajax_optionDiv);
			
			if(desc_ajax_list_MSIE){
				desc_ajax_optionDiv_iframe = document.createElement('IFRAME');
				desc_ajax_optionDiv_iframe.border='0';
                                /*
                                if (which=="Desc") 
				   desc_ajax_optionDiv_iframe.style.width = 300 + 'px';
                                else
				   desc_ajax_optionDiv_iframe.style.width = desc_ajax_optionDiv.clientWidth + 'px';
                                if (which=="Desc" || which=="Acct") 
                                   desc_ajax_optionDiv_iframe.style.width = '390px';
                                else
                                   desc_ajax_optionDiv_iframe.style.width = '250px';
                                */
				desc_ajax_optionDiv_iframe.style.height = desc_ajax_optionDiv.clientHeight + 'px';
				desc_ajax_optionDiv_iframe.id = 'desc_ajax_listOfOptions_iframe';
				
				document.body.appendChild(desc_ajax_optionDiv_iframe);
                               
			}
			
			var desc_allInputs = document.getElementsByTagName('INPUT');
			//var allInputs = document.getElementsByTagName('html:text');
                        //alert("01, allInputs="+allInputs+" allInputs.length="+allInputs.length);
                        //alert("no="+no+" value is "+desc_ajax_options_hide);
                        /*
			for(var no=0;no<desc_allInputs.length;no++){
				if(!desc_allInputs[no].onkeyup)desc_allInputs[no].onfocus = desc_ajax_options_hide;
			}
                        document.getElementById(desc_allInputs[no]).setAttribute("autocomplete","off");
                        alert(" why ?="+document.getElementById('part').value);
                        */
                        /*document.getElementById("login_id").setAttribute("autocomplete","off"); */
			for(var no=0;no<desc_allInputs.length;no++){
                           //alert("no="+no+" value is "+desc_ajax_options_hide);
                           //alert("allInputs value is "+allInputs[no].value);
                		if(!desc_allInputs[no].onkeyup)desc_allInputs[no].onfocus = desc_ajax_options_hide;
                        }
                        			
			var desc_allSelects = document.getElementsByTagName('SELECT');
			for(var no=0;no<desc_allSelects.length;no++){
				desc_allSelects[no].onfocus = desc_ajax_options_hide;
			}

			var oldonkeydown=document.body.onkeydown;
			if(typeof oldonkeydown!='function'){
				document.body.onkeydown=desc_ajax_option_keyNavigation;
			}else{
				document.body.onkeydown=function(){
					oldonkeydown();
				desc_ajax_option_keyNavigation() ;}
			}
			var oldonresize=document.body.onresize;
			if(typeof oldonresize!='function'){
				document.body.onresize=function() {desc_ajax_option_resize(inputObj); };
			}else{
				document.body.onresize=function(){oldonresize();
				desc_ajax_option_resize(inputObj) ;}
			}
				
		}
		
		if (which=="Part" && inputObj.value.length<minimumLettersBeforeLookup_part){
                   desc_ajax_options_hide();
                   return;
                   } 
		if (which=="Acct" && inputObj.value.length<minimumLettersBeforeLookup_acct){
                   desc_ajax_options_hide();
		   return;
		   }
                if (which=="Desc" && inputObj.value.length<minimumLettersBeforeLookup_desc){
                   desc_ajax_options_hide();
                   return;
                   }
                if (which=="Doc" && inputObj.value.length<minimumLettersBeforeLookup_doc){
                   desc_ajax_options_hide();
                   return;
                   }
                if (which=="DocDelete" && inputObj.value.length<minimumLettersBeforeLookup_docdelete){
                   desc_ajax_options_hide();
                   return;
                   }
				

		desc_ajax_optionDiv.style.top = (desc_ajax_getTopPos(inputObj) + inputObj.offsetHeight + desc_ajaxBox_offsetY) + 'px';
		desc_ajax_optionDiv.style.left = (desc_ajax_getLeftPos(inputObj) + desc_ajaxBox_offsetX) + 'px';
		if(desc_ajax_optionDiv_iframe){
			desc_ajax_optionDiv_iframe.style.left = desc_ajax_optionDiv.style.left;
			desc_ajax_optionDiv_iframe.style.top = desc_ajax_optionDiv.style.top;			
		}
		
		desc_ajax_list_activeInput = inputObj;
		desc_ajax_optionDiv.onselectstart =  desc_ajax_list_cancelEvent;
		currentListIndex++;
		if(desc_ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){
                        //alert("cachedlist, ->1");
			desc_ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex);			
		}else{
			var tmpIndex=currentListIndex/1;
			desc_ajax_optionDiv.innerHTML = '';
			var desc_ajaxIndex = desc_ajax_list_objects.length;
                        //alert("not cachedlist, ->20");
			desc_ajax_list_objects[desc_ajaxIndex] = new sack();
			//var url = desc_ajax_list_externalFile + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                        if (which=="DocDelete")
   			   var url = desc_ajax_list_externalFile_docdelete + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                        if (which=="Doc")
   			   var url = desc_ajax_list_externalFile_doc + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                        if (which=="Desc")
   			   var url = desc_ajax_list_externalFile_desc + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                        if (which=="Acct") {
                           if (acct_category=="acct_company" )
                              url=ajax_list_externalFile_acct + '?acct_category=acct_company&' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                           else if (acct_category=="acct_zipcode" )
                                   url=ajax_list_externalFile_acct + '?acct_category=acct_zipcode&' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                           else
                                   url=ajax_list_externalFile_acct + '?acct_category=acct_regular&' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                           }
                        if (which=="Part")
   			   var url = desc_ajax_list_externalFile_part + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+");
                        //alert("not cachedlist, ->21, url is "+url);
			desc_ajax_list_objects[desc_ajaxIndex].requestFile = url;	// Specifying which file to get
			desc_ajax_list_objects[desc_ajaxIndex].onCompletion = function(){ desc_ajax_option_list_showContent(desc_ajaxIndex,inputObj,paramToExternalFile,tmpIndex); };	// Specify function that will be executed after file has been found
			desc_ajax_list_objects[desc_ajaxIndex].runAJAX();		// Execute AJAX function		
                        //alert("not cachedlist, ->22, url is "+url);
		}
		
			
	}
	
	function desc_ajax_option_keyNavigation(e)
	{
		if(document.all)e = event;
		
		if(!desc_ajax_optionDiv)return;
		if(desc_ajax_optionDiv.style.display=='none')return;
		
		if(e.keyCode==38){	// Up arrow
			if(!desc_ajax_list_activeItem)return;
			if(desc_ajax_list_activeItem && !desc_ajax_list_activeItem.previousSibling)return;
			desc_ajax_options_rollOverActiveItem(desc_ajax_list_activeItem.previousSibling,true);
		}
		
		if(e.keyCode==40){	// Down arrow
			if(!desc_ajax_list_activeItem){
				desc_ajax_options_rollOverActiveItem(desc_ajax_list_optionDivFirstItem,true);
			}else{
				if(!desc_ajax_list_activeItem.nextSibling)return;
				desc_ajax_options_rollOverActiveItem(desc_ajax_list_activeItem.nextSibling,true);
			}
		}
		
		if(e.keyCode==13 || e.keyCode==9){	// Enter key or tab key
			if(desc_ajax_list_activeItem && desc_ajax_list_activeItem.className=='optionDivSelected')desc_ajax_option_setValue(false,desc_ajax_list_activeItem);
			if(e.keyCode==13)return false; else return true;
		}
		if(e.keyCode==27){	// Escape key
			desc_ajax_options_hide();			
		}
	}
	
	
	document.documentElement.onclick = autoHideList;
	
	function autoHideList(e)
	{
		if(document.all)e = event;
		
		if (e.target) source = e.target;
			else if (e.srcElement) source = e.srcElement;
			if (source.nodeType == 3) // defeat Safari bug
				source = source.parentNode;		
		if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')desc_ajax_options_hide();
		
	}
