	var myRequest = null;
	var myRequest2 = null;
	var myRequest3 = null;
	var myRequest4 = null;


	function CreateXmlHttpReq(handler) {
	  var xmlhttp = null;
	  try {
		xmlhttp = new XMLHttpRequest();
	  } catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	  xmlhttp.onreadystatechange = handler;
	  return xmlhttp;
	}
	
	
	
	function myHandler() {
		if (myRequest.readyState == 4 && myRequest.status == 200) {
			document.getElementById("regioni_SP").innerHTML = myRequest.responseText;
		}
	}
	
	function myHandler_prov() {
		if (myRequest2.readyState == 4 && myRequest2.status == 200) {
			document.getElementById("province_SP").innerHTML = myRequest2.responseText;
		}
	}
	
	function myHandler_com() {
		if (myRequest3.readyState == 4 && myRequest3.status == 200) {
			document.getElementById("comuni_SP").innerHTML = myRequest3.responseText;
		}
	}
	
	function myHandler_fraz() {
		if (myRequest4.readyState == 4 && myRequest4.status == 200) {
			document.getElementById("frazioni_SP").innerHTML = myRequest4.responseText;
		}
	}
	
	
		
	function populate_regioni(pag) {
		var r = Math.random();
		myRequest = CreateXmlHttpReq(myHandler);
		myRequest.open("GET",pag+"?rand="+escape(r));
		myRequest.send(null);
	}
		
	function populate_province() {	
		myRequest2 = CreateXmlHttpReq(myHandler_prov);
		if (document.getElementById('cod_regione')) {
			var i = document.getElementById('cod_regione').selectedIndex;
			var cod_regione = document.getElementById('cod_regione').options[i].value;
		}
		else var cod_regione = "";
		
		myRequest2.open("GET","province.php?cod_regione="+cod_regione);
		myRequest2.send(null);
		
		document.getElementById('cod_regione_h').value = cod_regione;		
	}
	
	function populate_comuni() {
		myRequest3 = CreateXmlHttpReq(myHandler_com);	
		
		var i = document.getElementById('cod_provincia').selectedIndex;	
		
		myRequest3.open("GET","comuni.php?cod_provincia="+document.getElementById('cod_provincia').options[i].value);
		myRequest3.send(null);
		
		document.getElementById('cod_provincia_h').value = document.getElementById('cod_provincia').options[i].value;
	}
	
	function salva_comuni() {	
		var i = document.getElementById('cod_comune').selectedIndex;
		document.getElementById('cod_comune_h').value = document.getElementById('cod_comune').options[i].value;
	}
	
	function populate_frazioni() {
		myRequest4 = CreateXmlHttpReq(myHandler_fraz);	
		
		var i = document.getElementById('cod_comune').selectedIndex;	
		
		myRequest4.open("GET","frazioni.php?cod_comune="+document.getElementById('cod_comune').options[i].value);
		myRequest4.send(null);
		
		document.getElementById('cod_comune_h').value = document.getElementById('cod_comune').options[i].value;
	}
	
	function salva_frazioni() {	
		var i = document.getElementById('cod_frazione').selectedIndex;
		document.getElementById('cod_frazione_h').value = document.getElementById('cod_frazione').options[i].value;
	}
	
	
	
	function selFasciaPrezzo(fascia,extfrm){
		var stroption="<select name='prezzo' style='width:150px'>";
		if (fascia == "affitto"){
			stroption += "<option value=\"0\" selected > - Qualsiasi - </option>";
			stroption += "<option value=\"6\">da 0 a 500</option>";
			stroption += "<option value=\"7\">da 500 a 800</option>";
			stroption += "<option value=\"8\">da 800 a 1000</option>";
			stroption += "<option value=\"9\">da 1000 a 2000</option>";
			stroption += "<option value=\"10\">oltre 2000</option>";
		}
		else {
			stroption += "<option value=\"0\" selected > - Qualsiasi - </option>";
			stroption += "<option value=\"1\">da 0 a 100000</option>";
			stroption += "<option value=\"2\">da 100000 a 200000</option>";
			stroption += "<option value=\"3\">da 200000 a 300000</option>";
			stroption += "<option value=\"4\">da 300000 a 500000</option>";
			stroption += "<option value=\"5\">oltre 500000</option>";
		}
		stroption += "</select>";
		var obj = document.getElementById('idprezzo'+extfrm);
		obj.innerHTML = stroption;
	}
	
	