var myRequest = 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) {
		var errore=myRequest.responseText;
		if (errore==0){
			document.getElementById("formreg").submit();
		}else{
			//errore = errore.replace("&egrave;","è");

			alert(errore);
			//e = document.getElementById("result_div");
			//e.innerHTML = "errore="+errore;
			
		}
	}
}


function doPost(){
	myRequest = CreateXmlHttpReq(myHandler);
	myRequest.open("POST", "/common/controlloForm1.php", true);

	
	myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	var body="nome="+document.getElementById("nome").value+"&cognome="+document.getElementById("cognome").value+"&email="+document.getElementById("email").value+"&confemail="+document.getElementById("confemail").value+"&ggN="+document.getElementById("ggN").value+"&mmN="+document.getElementById("mmN").value+"&aaN="+document.getElementById("aaN").value+"&privacy="+document.getElementById("privacy").checked+"&newsletter="+document.getElementById("newsletter").checked;
	myRequest.setRequestHeader("Content-length", body.length);
	myRequest.setRequestHeader("Connection", "close");
	myRequest.send(body);
}
function doPost1(){
	myRequest = CreateXmlHttpReq(myHandler);
	myRequest.open("POST", "/common/controlloForm2.php", true);
	myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	var body="nome="+document.getElementById("nome").value+"&cognome="+document.getElementById("cognome").value+"&email="+document.getElementById("email").value+"&confemail="+document.getElementById("confemail").value+"&ggN="+document.getElementById("ggN").value+"&mmN="+document.getElementById("mmN").value+"&aaN="+document.getElementById("aaN").value+"&privacy="+document.getElementById("privacy").checked+"&newsletter="+document.getElementById("newsletter").checked+"&raccolta="+document.getElementById("raccolta").checked+"&indirizzo="+document.getElementById("indirizzo").value+"&civico="+document.getElementById("civico").value+"&localita="+document.getElementById("localita").value+"&provincia="+document.getElementById("provincia").value+"&cap="+document.getElementById("cap").value+"&telefono="+document.getElementById("telefono").value+"&selfigli="+document.getElementById("selfigli").value+"&selfiglio01="+document.getElementById("selfiglio01").value+"&selfiglio02="+document.getElementById("selfiglio02").value+"&selfiglio03="+document.getElementById("selfiglio03").value;
	myRequest.setRequestHeader("Content-length", body.length);
	myRequest.setRequestHeader("Connection", "close");
	myRequest.send(body);
}
function openfigli(){
	var nfigli=document.getElementById("selfigli").value;
	document.getElementById("selfiglio01").value=0;
	document.getElementById("selfiglio02").value=0;
	document.getElementById("selfiglio03").value=0;
	switch (nfigli){
		case "0":
			document.getElementById("figlio1").style.display="none";
			document.getElementById("figlio2").style.display="none";
			document.getElementById("figlio3").style.display="none";
		break;
		case "1":
			document.getElementById("figlio1").style.display="block";
			document.getElementById("figlio2").style.display="none";
			document.getElementById("figlio3").style.display="none";
		break;
		case "2":
			document.getElementById("figlio1").style.display="block";
			document.getElementById("figlio2").style.display="block";
			document.getElementById("figlio3").style.display="none";		
		break;
		case "3":
			document.getElementById("figlio1").style.display="block";
			document.getElementById("figlio2").style.display="block";
			document.getElementById("figlio3").style.display="block";			
		break;
	}
}