function checkMail(campo) {
	
	if (campo.value == "") {
		return "il campo EMAIL e' obbligatorio \n";
	}
	var ok=true;
	var a=campo;
	var pe=a.value.indexOf('.');
	var ss=a.value.indexOf(' ');
	var lch=a.value.length-1;
	var atr=a.value.indexOf('@');
	var att=atr+1;
	var sq=a.value.substring(0,atr); 
	var sw=a.value.substring(atr,pe); 
	var se=a.value.substring(pe,lch);
	if((atr<1) || (pe==lch) || (pe<1)  || (ss != -1) || (sq.length<=2) || (sw.length<=3) || (se.length<=1)) {
		return "l'indirizzo EMAIL inserito non e' corretto \n";
	} else {
		return "";
	}
}

function checkGlobal(ilForm) {
	
	var errore = "";
	
	if (document.getElementById("nome").value == "") {errore = errore + "il campo NOME e' obbligatorio \n";}
	if (document.getElementById("cognome").value == "") {errore = errore + "il campo COGNOME e' obbligatorio \n";}
	if (document.getElementById("indirizzo").value == "") {errore = errore + "il campo INDIRIZZO e' obbligatorio \n";}
	if (document.getElementById("localita").value == "") {errore = errore + "il campo CITTA' e' obbligatorio \n";}
	if (document.getElementById("provincia").value == "") {errore = errore + "il campo PROVINCIA e' obbligatorio \n";}
	if (document.getElementById("telefono").value == "") {errore = errore + "il campo TELEFONO e' obbligatorio \n";}
	if (document.getElementById("password").value != document.getElementById("confermapassword").value) {errore = errore + "le password non coincidono \n";}
	
	errore = errore + checkMail(document.getElementById("email"));
	
	if (errore == "") {
		return true;
	} else {
		alert(errore);
		return false;
	}
	
}

