	var myRequest = null;
	var myRequest1 = null;
	var myRequest2 = null;
	var myRequest3 = 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_invia() {
		if (myRequest1.readyState == 4 && myRequest1.status == 200) {
			document.getElementById("newsletter").innerHTML = myRequest1.responseText;
			alert("Il tuo indirizzo email sarą aggiunto alla nostra newsletter al pił presto, grazie.");
		}
	}
	
	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 populate_regioni(pag, lang) {
		var r = Math.random();
		myRequest = CreateXmlHttpReq(myHandler);
		if(lang)
		    myRequest.open("GET",pag+"?rand="+escape(r)+"&lang="+lang);
		else
		    myRequest.open("GET",pag+"?rand="+escape(r));
		myRequest.send(null);
	}
	
	function populate_province(lang) {		
		myRequest2 = CreateXmlHttpReq(myHandler_prov);
		i = document.getElementById('cod_regione').selectedIndex;
		if (lang)
		    myRequest2.open("GET","province.php?cod_regione="+document.getElementById('cod_regione').options[i].value + "&lang="+lang);
		else
		    myRequest2.open("GET","province.php?cod_regione="+document.getElementById('cod_regione').options[i].value);
		myRequest2.send(null);
		document.getElementById('cod_regione_h').value=document.getElementById('cod_regione').options[i].value;
	}
	
	function populate_comuni(lang) {	
		myRequest3 = CreateXmlHttpReq(myHandler_com);
		i = document.getElementById('cod_provincia').selectedIndex;		
		if(lang)
		    myRequest3.open("GET","comuni.php?cod_provincia="+document.getElementById('cod_provincia').options[i].value + "&lang=" + lang);
	    else
			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() {	
		i = document.getElementById('cod_comune').selectedIndex;
		document.getElementById('cod_comune_h').value=document.getElementById('cod_comune').options[i].value;
	}
	
	function invia() {
		if (confirm('Cliccando su OK autorizzi Casaqui ad utilizzare il tuo indirizzo per inviarti materiale promozionale')) {
			var r = Math.random();		
			var posta = document.getElementById('posta').value;			
			myRequest1 = CreateXmlHttpReq(myHandler_invia);
			myRequest1.open("GET","dformed.php?posta="+posta+"&rand="+escape(r));
			myRequest1.send(null);
		}
	}
	
	function invia() {
		if (confirm('CClick OK to authorize Casaqui use your address to send you promotional material')) {
			var r = Math.random();		
			var posta = document.getElementById('posta').value;			
			myRequest1 = CreateXmlHttpReq(myHandler_invia);
			myRequest1.open("GET","dformed.php?posta="+posta+"&rand="+escape(r));
			myRequest1.send(null);
		}
	}
