
	var currentPos=1;

	function updateCategories(id){
		var cats=document.getElementById("businessWanted" + id);
		
		//set up the location of the processing page
		var objAJAX = new sack('users/include/display/subBusinesses.cfm');
		
		// Set variables 
		objAJAX.setVar("businessCatParent", cats.value);
		objAJAX.setVar("retID", id);
		
		// Set response handler
		objAJAX.responseHandler = updateCategories_handler;
		// Send command
		objAJAX.runAJAX();
	}
	
	function updateCategories_handler(strXmlData){
			//Set up the variables
			var arrXmlData = null;
			
			//split out the processing info and the actual data
			
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<data>))|((</data>\\s*)$)", "gi"), "");
	
			arrXmlData = strXmlData.split("</data><data>");
				
			myID=arrXmlData[0];
			
			strXmlData=arrXmlData[1];
			
			//get the results element
			var objDisplayResults = document.getElementById("businessWanted_sub" + myID);
			
			//reset the display
			objDisplayResults.options.length = 0;
			
			//split the results to its components
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<record>))|((</record>\\s*)$)", "gi"), "");

			arrXmlData = strXmlData.split("</record><record>");
			
			for (var intIndex = 0 ; intIndex < arrXmlData.length ; intIndex++){		
				id=arrXmlData[intIndex].replace(new RegExp("(.*<id>)|(</id>.*)", "gi"), "");				
				category=arrXmlData[intIndex].replace(new RegExp("(.*<category>)|(</category>.*)", "gi"), "");
				objDisplayResults.options[intIndex] = new Option(category,id);
			}
	}
	
	function updatecountry(id){
		var country=document.getElementById("country" + id);
		var state=document.getElementById("state" + id);
		var county=document.getElementById("county" + id);
			
		if(country.value == 'USA' || country.value == 'CANADA'){
			state.disabled=false;
			county.disabled=false;	
			
			//set up the location of the processing page
			var objAJAX = new sack('users/include/display/getStates.cfm');
			
			// Set variables 
			objAJAX.setVar("coID", country.value);
			objAJAX.setVar("retID", id);
			
			
			// Set response handler
			objAJAX.responseHandler = updatecountry_handler;
			// Send command
			objAJAX.runAJAX();
			
		}else{
			state.options.length = 0;
			state.options[0] = new Option('Select State',0);
			state.disabled=true;
			county.options.length = 0;
			county.options[0] = new Option('Select County',0);
			county.disabled=true;
			
		}
	}
	
	function updatecountry_handler(strXmlData){
			//Set up the variables
			var arrXmlData = null;
			
			//split out the processing info and the actual data
			
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<data>))|((</data>\\s*)$)", "gi"), "");
	
			arrXmlData = strXmlData.split("</data><data>");
				
			myID=arrXmlData[0];
			
			strXmlData=arrXmlData[1];
			
			//get the results element
			var objDisplayResults = document.getElementById("state" + myID);
			
			//reset the display
			objDisplayResults.options.length = 0;
			
			//split the results to its components
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<record>))|((</record>\\s*)$)", "gi"), "");

			arrXmlData = strXmlData.split("</record><record>");
			
			for (var intIndex = 0 ; intIndex < arrXmlData.length ; intIndex++){		
				id=arrXmlData[intIndex].replace(new RegExp("(.*<id>)|(</id>.*)", "gi"), "");				
				state=arrXmlData[intIndex].replace(new RegExp("(.*<state>)|(</state>.*)", "gi"), "");
				objDisplayResults.options[intIndex] = new Option(state,id);
			}	
			
			updateCounty(myID);
	}
	
	function updateCounty(id){
	
		var state=document.getElementById("state" + id);
		
		//alert(state.text);
			//set up the location of the processing page
			var objAJAX = new sack('users/include/display/getCounties.cfm');
			
			// Set variables 
			objAJAX.setVar("stID", state.value);
			objAJAX.setVar("retID", id);
			
			
			// Set response handler
			objAJAX.responseHandler = updateCounty_handler;
			// Send command
			objAJAX.runAJAX();
		
	
	}
	
	function updateCounty_handler(strXmlData){
	
			//Set up the variables
			var arrXmlData = null;
			
			//split out the processing info and the actual data
			
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<data>))|((</data>\\s*)$)", "gi"), "");
	
			arrXmlData = strXmlData.split("</data><data>");
				
			myID=arrXmlData[0];
			
			strXmlData=arrXmlData[1];
			
			
			//get the results element
			var objDisplayResults = document.getElementById("county" + myID);
			
			//reset the display
			objDisplayResults.options.length = 0;
			
			//split the results to its components
			strXmlData = strXmlData.replace(new RegExp("(^(\\s*<record>))|((</record>\\s*)$)", "gi"), "");

			arrXmlData = strXmlData.split("</record><record>");
			objDisplayResults.options[0] = new Option("","");
			for (var intIndex = 0 ; intIndex < arrXmlData.length ; intIndex++){		
				id=arrXmlData[intIndex].replace(new RegExp("(.*<id>)|(</id>.*)", "gi"), "");				
				county=arrXmlData[intIndex].replace(new RegExp("(.*<county>)|(</county>.*)", "gi"), "");
				objDisplayResults.options[intIndex+1] = new Option(county,id);
			}	
	}
	
	function getNextSearch(){
			updatePos();
			var objAJAX = new sack('users/include/display/searchBlock.cfm');
			// Set variables 
			objAJAX.setVar("i", currentPos);
			
			// Set response handler
			objAJAX.responseHandler = getNextSearch_handler;
			// Send command
			objAJAX.runAJAX();
	}
	
	function getNextSearch_handler(strData){
			var results=document.getElementById("resultsBlock");
			var objNewDiv = document.createElement("div");
			
			var objHTML = document.createElement("span");
			objHTML.innerHTML = strData;
			
			objNewDiv.appendChild(objHTML);			
			results.appendChild(objNewDiv);
			
			
	}
	
							
							
	function buildSearch(pos,businessCatID,downpaymentID,cashflowId,countryId,stateId,countyId){
			var objAJAX = new sack('users/include/display/buildsearchBlock.cfm');
			
			// Set variables 
			objAJAX.setVar("i", pos);
			objAJAX.setVar("businessCatID", businessCatID);
			objAJAX.setVar("downpaymentID", downpaymentID);
			objAJAX.setVar("cashflowId", cashflowId);
			objAJAX.setVar("countryId", countryId);
			objAJAX.setVar("stateId", stateId);
			objAJAX.setVar("countyId", countyId);
			
			// Set response handler
			objAJAX.responseHandler = getNextSearch_handler;
			// Send command
			objAJAX.runAJAX();
	}
	
	function updatePos(){
		currentPos++;
		document.getElementById("searchCount").value=currentPos;
	}
