var responsetext="";

    function updatesubcats(obj,url,querystring) {
	//alert(obj.name);
	//alert(querystring);
	
	//obj = document.getelementById(objid);
	
        if(querystring){
		url=url+"?"+querystring;
		
		url=url+"&ms="+new Date().getTime();
	
        //<?php //if($includepropertysearch || $includeagencysearch){ ?> 
		if((includepropertysearch) || (includeagencysearch)){ 	
		searchcriteriastring = buildquerystring();
		url= url + "&"+searchcriteriastring.substr(1);
		}
	    //<?php //} ?>
	
		}
						
		//alert(url); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		
		
        http_request.onreadystatechange = function() { returncontents(http_request,obj,querystring); };
				

		obj.options.length = 0;
        obj.options[obj.options.length] = new Option("Loading...",0);		
	

        http_request.open('GET', url, true);
        http_request.send(null);
       
    }
	
	
	

    function returncontents(http_request,obj,querystring) {
        //alert("BOO");
		
		//alert(querystring);
		temparray = querystring.split("&");
		vararray = new Array();
		for(var i in temparray){
		temparray[i] = temparray[i].split("=");
		thekey = unescape(temparray[i][0]);
		theval = unescape(temparray[i][1]);
		vararray[thekey] = theval;
		}
		//alert(vararray["label"]); //++++++++++++++++++++++++++++++++++++++++++++++++++
		
//alert(http_request.readyState);

	        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			
			
			//responsetext=null;
			responsetext=http_request.responseText;
               //alert(responsetext); //+++++++++++++++++++++++++++++++++++++++++++++
				
				optionarray= new Array();
			if(responsetext){
			optionarray = responsetext.split(",");
            }
			
			
			//setup default string
			if(vararray["loctype"]=="province"){defaultstring="Select Province";}
			if(vararray["loctype"]=="area"){defaultstring="Select Area";}
			if(vararray["loctype"]=="suburb"){defaultstring="Select Suburb";}
			
			obj.options.length=0;	
			getsubcats(obj,optionarray,defaultstring);
			
			if(obj.options.length>1){
			obj.style.display='';
			}
			else
			{
			obj.style.display='none';
			}
			
			//alert(obj.options[1].text);
			
			//<?php//if($multisuburbselect){ 	?>
			if(multisuburbselect){
			if(vararray["loctype"]=="suburb"){
			//obj.options[0].text = "All";
			obj.options[0] = null;
			}
			}
			//<?php  //} ?>
			
			/*
			if(vararray["loctype"]=="province"){
			theform.province.style.display='';
			theform.area.style.display='none';
			theform.suburblist.style.display='none';
			}
			
			if(vararray["loctype"]=="area"){
			theform.area.style.display='';
			theform.suburblist.style.display='none';
			}
			
			if(vararray["loctype"]=="suburb"){
			theform.suburblist.style.display='';
			}
			*/
			
			if((vararray["action"]=="addloc")||(vararray["action"]=="renloc")){
			//alert(getselectindex(obj,vararray["label"]));
			obj.selectedIndex = getselectindex(obj,vararray["label"]);
			thefield = document.getElementById("addnew"+vararray["loctype"]+"field");
			thefield.value="";
			
			
			if((vararray["loctype"]=="area") && (vararray["action"]=="addloc")){
			theform.suburblist.length=0;
			//theform.suburblist.style.display='none';
			}
			
			}
			
			
			
							
            } 
			else 
			{
                alert('There was a problem with the request.');
            //if(!querystring){
			//obj.options.length=0;
			//obj.style.display='none';
			//}
			
			}
        }
    }
	
	/*
	function getqstringvars(querystring){
		qarray = new Array();
		if(querystring){
		ary = querystring.split("&");
		for(var i in ary)
		ary[i] = ary[i].split("=");
		thekey = "'"+unescape(ary[i][0])+"'";
		qarray[thekey] = unescape(ary[i][1]);
		}
		}
		alert(qarray);
		
	}
	*/
/*	
function updatesubcats(obj,url,querystring){
makerequest(url,querystring);
//responsetext generated by above
optionarray = responsetext.split(",");
getsubcats(obj,optionarray);
}	
*/	
	
function getsubcats(obj,subcatarray,defaultstring){
//alert(subcatarray);
if(subcatarray){

obj.options.length=0;
obj.options[0] = new Option(defaultstring,0);
for(i=0;i<subcatarray.length;i++){

thissubcat = subcatarray[i].split(":");
obj.options[obj.options.length] = new Option(thissubcat[1],thissubcat[0]);
}
}	

	
}	
	
	//not sure if this actually used or not but was faulty but fixed but untested
function getselectindex(obj,thestring){
for(i=0;i<obj.options.length;i++){

//this was original
//if(obj.options[i].text==unescape(thestring)){

//this was added to search both value and string for match 
//if((obj.options[i].text==unescape(thestring) || obj.options[i].value==unescape(thestring))){


if((obj.options[i].text.toLowerCase()==unescape(thestring).toLowerCase() || obj.options[i].value.toLowerCase()==unescape(thestring).toLowerCase())){
return i;
}
}
return -1;
}	





/*
function showloading(obj){
obj.options.length = 0;
obj.options[obj.options.length] = new Option("Loading..."),0);
}
*/


//this is copy from topsiteslist
function menuselectedlist(obj){
if(!obj.options.length){
return 0;
}
temparray = new Array();
for(b=0;b<obj.options.length;b++){
if(obj.options[b].selected==true){
temparray[temparray.length] = obj.options[b].value;
}
}
return temparray.join(",");
}


