	/*
	Enable repopulation of some form fileds on the client, no need to reload the whole page.
	Change Control
	CID		Date		Who	Description
	Cid1	21/06/2004	ST	Rephrase error message.
	CID2        22/05/2008  AF  Add trapping of key enter on SearchName Field
	*/

	//Global vars
	var DisplayLength = 2048;		/* Maximum number of records to return from Database? */
	var allOptArrays = new Array(DisplayLength); /* keep additional product details */
	//var companyID = 0;		/*current company id*/
	var selIndex = 0;			/*number of selected situations, used to enable or disable buttons*/
	var iSelCount = 0;			/*number of selected situations*/
	var iSelType = 0;			/*ID of product type, used to narrow down number of returned pests*/
	var iMaxSituation = 32;		/*maximum number of situations allowed to be sumbited*/
	var bSearch = true;      /*to prevent resubmiting search requests while previous search is in progress*/
	var sSearchString = '';  /*holds current search string*/
	//alert(MasterTypeID);
	var keyTimeout;
	var bEnter = false;

    function refresh_list(){
		if (keyTimeout){
		 clearTimeout(keyTimeout);
		}
		keyTimeout= setTimeout('doRefresh_list()',30);
	}
    function refresh_list2(){
		if (keyTimeout){
		 clearTimeout(keyTimeout);
		}
		if (!bEnter){
		    keyTimeout= setTimeout('doRefresh_list()',4000);
		}
		
		
	}
    function doRefresh_list(){
		//called on 'onkeyup'
		//make remote call back to server

		//jsrsPOST doesn't work, GET used instead
		//jsrsPOST = document.forms['frmPost']['chkPost'].checked;
		//jsrsPOST = true;
		//alert(document.forms['frmRmt'].rbLookWhere[0].checked + "\n" + document.forms['frmRmt'].rbLookWhere[1].checked);

		jsrsPOST = '';

	    document.frmRmt.NameList.length = 0					/*reset current list*/

	    var inValue  = document.frmRmt.SearchName.value;	/*current typed value, used for remote lookup*/
	    //iSelType = document.frmRmt.SelectedType.value;
	    if (bSearch){
			if (inValue.length > 0) /*number of characters after we go search*/
			{
				bSearch = false;
				sSearchString = inValue;

				if (document.forms['frmRmt'].rbLookWhere[1].checked){
					inValue = "%" + inValue;
				}
				inValue = inValue.replace(/\?/g,'_');
				//alert(inValue);
                //alert(sourceDB);
                //alert(companyID);
			  //jsrsExecute("/webservices/rmtServerPest_rs.asp", fCallBack, "getRmt", Array(inValue, DisplayLength, sourceDB, companyID, MasterTypeID, iSelType, "oneProduct"));
			  jsrsExecute("/webservices/rmtServerPest_rs_Req.asp", fCallBack, "getRmt", Array(inValue, DisplayLength, sourceDB, companyID, MasterTypeID, iSelType, sRequestor, "oneProduct"),false);
			  //	jsrsExecute("/webservices/rmtServerPest_rs.asp", fCallBack, "getRmt", Array(inValue, DisplayLength, sourceDB, companyID, MasterTypeID, iSelType, "", "oneProduct"));
			}
		}
    }
    function fCallBack( returnstring ){
		//parse returned string and populate NameList options
		//alert(returnstring);
		//window.prompt("SQL",returnstring);
		bSearch = true;
		document.frmRmt.SearchName.value = sSearchString;
		var myArray = returnstring.split(":");
		//alert(myArray.length);
		for (i = 0; i < myArray.length-1; i++)		
		{
			var myOpt = new Option
			var optArray = myArray[i].split("^");
			allOptArrays[i] = optArray;

			lastIndex = i;			  
			myOpt.value = optArray[1];
			myOpt.text  = optArray[0];			

			if (i < myArray.length) 
			{
			  document.frmRmt.NameList.options[i] = myOpt;
			}
		}
		if (document.frmRmt.NameList.length > 0){
			if (document.getElementById)
			{
				document.getElementById("msgSearchName").style.color = "black";
				document.getElementById("msgSearchName").innerText = " ";
			}
			else if (document.all)
			{
				document.all["msgSearchName"].style.color = "black";				
				document.all["msgSearchName"].innerText = " ";
			}
			else if (document.layers)
			{
				document.layers["msgSearchName"].style.color = "black";							 	
				document.layers["msgSearchName"].innerText = " ";
			}

			document.frmRmt.NameList.options[0].selected = true;
		}else{	
			if (document.getElementById)
			{
				document.getElementById("msgSearchName").style.color = "red";
				//Cid1	21/06/2004	ST	Rephrase error message.				
				//document.getElementById("msgSearchName").innerText = "No product found, please try again for different name!";
				document.getElementById("msgSearchName").innerText = "No product found. Please try a different name!";				
			}
			else if (document.all)
			{
				document.all["msgSearchName"].style.color = "red";				
				document.all["msgSearchName"].innerText = "No product found. Please try a different name!";
			}
			else if (document.layers)
			{
				document.layers["msgSearchName"].style.color = "red";							 	
				document.layers["msgSearchName"].innerText = "No product found. Please try a different name!";
			}
		
		}	
      
    } 
	function frmSubmit_old(){
		//update ProductID with selected option before submiting the form, as it is needed for next step
		
		objList = document.frmRmt.NameList;		
		document.frmRmt.ProductID.value = objList.options[objList.selectedIndex].value;		
		document.frmRmt.ProductName.value = objList.options[objList.selectedIndex].text;				
		if (document.frmRmt.ProductID.value > 0){
			document.frmRmt.submit();
		}	
	}	
	function frmSubmit(){
		//update ProductID with selected option before submiting the form, as it is needed for next step

		//alert("Please select an Option top!");
		objList = document.frmRmt.NameList;		
		//alert(objList.length);
		//alert(objList.selectedIndex);

		if (objList.selectedIndex > -1){
			document.frmRmt.ProductID.value = objList.options[objList.selectedIndex].value;		
			document.frmRmt.ProductName.value = objList.options[objList.selectedIndex].text;				
			//alert(document.frmRmt.ProductID.value);
			if (document.frmRmt.ProductID.value >0){		
				//document.frmRmt.action = "searchproxy.asp";
				document.frmRmt.submit();
			}else{	
				alert("Please enter the search terms!");
				document.frmRmt.SearchName.focus();
			}
		}else{	
			alert("Please enter the search terms!");
			document.frmRmt.SearchName.focus();
		}

	}	
	function frmPdaSubmit(){
		//submit searchString
		document.frmRmt.ProductID.value = 0; //reset productid for new search	
		document.frmRmt.SearchWhere.value = 0
		if (document.forms['frmRmt'].rbLookWhere[1].checked){
			document.frmRmt.SearchWhere.value = 1
		}

		document.frmRmt.submit();

	}	

	function showHelp() {
	    if (document.getElementById("trhelp")!= null)
	        document.getElementById("trhelp").style.display = document.getElementById("trhelp").style.display == "" ? "none" : "";

	}
    function startAgain() {
	    document.frmRmt.reset();
	    document.frmRmt.NameList.options.length = 0;
	}


