var req;
var elementId
function loadXMLDoc(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			idElement=document.getElementById(elementId);
			idElement.innerHTML=req.responseText;
			idElement.style.display="block";
			//alert(req.responseText);
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

function selectModels(url){

	loadXMLDoc(url);
	if(req){
		req.onreadystatechange = processReqChange;
		elementId='suburbs';
		req.open("GET", url, true);
		req.send("");
	}
	
}

function selectModels_search(url){
	idp=document.search.id_prov.selectedIndex
	if(idp!=0){prov_id=document.search.id_prov.options[idp].value}
	else{prov_id=0;}
	ida=document.search.id_area.selectedIndex
	if(ida!=0){area_id=document.search.id_area.options[ida].value}
	else{area_id=0;}
	idt=document.search.id_town.selectedIndex
	if(idt!=0){town_id=document.search.id_town.options[idt].value}
	else{town_id=0;}
	url=url+"&prov_id="+prov_id+"&area_id="+area_id+"&town_id="+town_id;
	//alert(url);
	
	loadXMLDoc(url);
	if(req){
		req.onreadystatechange = processReqChange;
		elementId='suburbs';
		req.open("GET", url, true);
		req.send("");
	}
	
}

function hidelist(){
	idElement=document.getElementById(elementId);
	idElement.style.display="none";
}

function select_zone(idp, ida, idt, ids){
	
	option_length=document.prop.id_prov.options.length;
	for(i=1;i<option_length;i++){
			if(document.prop.id_prov.options[i].value==idp){document.prop.id_prov.options[i].selected=true; changeArea(); break;}
	}

	option_length=document.prop.id_area.options.length;
	for(i=1;i<option_length;i++){
			if(document.prop.id_area.options[i].value==ida){document.prop.id_area.options[i].selected=true; changeTown(); break;}
	}

	option_length=document.prop.id_town.options.length;
	for(i=1;i<option_length;i++){
			if(document.prop.id_town.options[i].value==ids+"_"+idt){document.prop.id_town.options[i].selected=true; break;}
	}

	//option_length=document.prop.id_suburb.options.length;
	//for(i=1;i<option_length;i++){
	//		if(document.prop.id_suburb.options[i].value==ids){document.prop.id_suburb.options[i].selected=true; break;}
	//}

}

function select_zone_s(idp, ida, idt, ids, suburbname){
	
	option_length=document.search.id_prov.options.length;
	for(i=1;i<option_length;i++){
			if(document.search.id_prov.options[i].value==idp){document.search.id_prov.options[i].selected=true; changeArea(); break;}
	}

	option_length=document.search.id_area.options.length;
	for(i=1;i<option_length;i++){
			if(document.search.id_area.options[i].value==ida){document.search.id_area.options[i].selected=true; changeTown(); break;}
	}


	option_length=document.search.id_town.options.length;
	for(i=1;i<option_length;i++){
			if(document.search.id_town.options[i].value==idt){document.search.id_town.options[i].selected=true; break;}
	}

	document.search.id_suburb.value=ids;
	document.search.suburb_name.value=suburbname;
	/*option_length=document.search.id_suburb.options.length;
	for(i=1;i<option_length;i++){
			if(document.search.id_suburb.options[i].value==ids){document.search.id_suburb.options[i].selected=true; break;}
	}*/

}


