// JavaScript Document
	var outputid = "";
	var genqstr = "";
	
	function GetXmlHttpObject(handler){  
   		var objXMLHttp=null  
   		if(window.XMLHttpRequest){  
       		objXMLHttp=new XMLHttpRequest()  
		}else if (window.ActiveXObject){  
       		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")  
   		}  
   		return objXMLHttp  
	}  
	
	function stateChanged(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {  
           document.getElementById(outputid).innerHTML= xmlHttp.responseText; 
		   if(outputid=="locationsbox"){
		   		outputid = "searchresultsbox";
		   		htmlData("searchresults.php", genqstr+"&loc=*", "searchresultsbox");
		   }
   		}else{  
           //alert(xmlHttp.status);
		}  
	}  
  
	// Will populate data based on input  
	function htmlData(url, qStr, idbox){ 
		if(url.length==0){  
			document.getElementById(idbox).innerHTML="";  
       		return;  
   		}  
   		xmlHttp=GetXmlHttpObject()  
   		if(xmlHttp==null){  
       		alert ("Browser does not support HTTP Request");  
       		return;  
   		}
		outputid = idbox;
		
		url=url+"?"+qStr; 
		genqstr = qStr; 
   		url=url+"&sid="+Math.random();  
   		xmlHttp.onreadystatechange=stateChanged;  
   		xmlHttp.open("GET",url,false) ;  
   		xmlHttp.send(null);
		
	}  


	var wait = 7500;
	var nextad =Math.floor(Math.random()*3)
	nextad++;
	
	// the function that performs the fade
	function swapFade(adtype,numberofads) {
		htmlData('adbanner.php', 'nextad='+nextad+'&adtype='+adtype, 'adbox')	
		nextad++;
		if(nextad>numberofads){
			nextad=1;
		}
	}
	
	// the onload event handler that starts the fading.
	function startPage(adtype,numberofads) {
		swapFade(adtype,numberofads);
		setInterval('swapFade('+adtype+','+numberofads+')',wait);
	}
	function backtosearch(adtype,numberofads,category,location){
			if(category>0){
				if(location=="*"){
					dosearch('locations.php', 'cat='+category, 'locationsbox')	
				}else{
					htmlData('locations.php', 'cat='+category+'&loc='+location, 'locationsbox')	
					htmlData('searchresults.php', 'cat='+category+'&loc='+location, 'searchresultsbox')
				}
			}
			startPage(adtype,numberofads);
	}
	function dosearch(url, qStr, idbox){
		htmlData(url,qStr,idbox);
	}
