function validEmail(mail) {

		invalidChars = " /:,;"			
		for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (mail.indexOf(badChar,0) > -1) {
				return false
				}
		}
		atPos = mail.indexOf("@",1)			// there must be one "@" symbol
		if (atPos == -1) {
			return false
		}
		if (mail.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
			return false
		}
		periodPos = mail.indexOf(".",atPos)
		if (periodPos == -1) {					// and at least one "." after the "@"
			return false
		}
		if (periodPos+3 > mail.length)	{		// must be at least 2 characters after the "."
			return false
		}
		return true
}

function controlla(nomeForm) {
	var nome = nomeForm.elements["nome"].value;
	var cognome = nomeForm.elements["cognome"].value;
	var cf = nomeForm.elements["cf"].value;
	var indirizzo = nomeForm.elements["indirizzo"].value;
	var cap = nomeForm.elements["cap"].value;
	var citta = nomeForm.elements["citta"].value;
	var provincia = nomeForm.elements["provincia"].value;
	var telefono = nomeForm.elements["telefono"].value;
	var email = nomeForm.elements["email"].value;
	var accetto = nomeForm.elements["accetto"].checked;
	var accetto2 = nomeForm.elements["accetto2"].checked;
	var username = nomeForm.elements["username"].value;
	var password = nomeForm.elements["password"].value;
	var password2 = nomeForm.elements["password2"].value;
	
	nomeForm.elements["nome"].style.backgroundColor=''
	nomeForm.elements["cognome"].style.backgroundColor=''
	nomeForm.elements["cf"].style.backgroundColor=''
	nomeForm.elements["cap"].style.backgroundColor=''
	nomeForm.elements["citta"].style.backgroundColor=''
	nomeForm.elements["provincia"].style.backgroundColor=''
	nomeForm.elements["telefono"].style.backgroundColor=''
	nomeForm.elements["email"].style.backgroundColor=''
	nomeForm.elements["telefono"].style.backgroundColor=''
	nomeForm.elements["accetto"].style.backgroundColor=''
	nomeForm.elements["accetto2"].style.backgroundColor=''
	nomeForm.elements["username"].style.backgroundColor=''
	nomeForm.elements["password"].style.backgroundColor=''
	nomeForm.elements["password2"].style.backgroundColor=''
	

	
	if (nome.length < 1) {
		alert("Attenzione, inserire il nome");
		nomeForm.elements["nome"].style.backgroundColor='FF5555'
		return false;
	}
	if (cognome.length < 1) {
		alert("Attenzione, inserire il cognome");
		nomeForm.elements["cognome"].style.backgroundColor='FF5555'
		return false;
	}
	if (cf.length < 1) {
		alert("Attenzione, inserire il Codice Fiscale");
		nomeForm.elements["cf"].style.backgroundColor='FF5555'
		return false;
	}
	if (cap.length < 1) { 
		alert("Attenzione, inserire il CAP");
		nomeForm.elements["cap"].style.backgroundColor='FF5555'
		return false;
	} 
	if (isNaN(cap) ) {
		alert("Attenzione, CAP non valido");
		nomeForm.elements["cap"].style.backgroundColor='FF5555'
		return false;
	}
	if (citta.length < 1) {
		alert("Attenzione, inserire la cittā");
		nomeForm.elements["citta"].style.backgroundColor='FF5555'
		return false;
	}
	if (provincia.length < 1) {
		alert("Attenzione, inserire la provincia");
		nomeForm.elements["provincia"].style.backgroundColor='FF5555'
		return false;
	}
	if (telefono.length < 1) { 
		alert("Attenzione, inserire il telefono");
		nomeForm.elements["telefono"].style.backgroundColor='FF5555'
		return false;
	} 
	if (isNaN(telefono)) {
		alert("Attenzione, telefono non valido, inserire solo valori numerici senza spazi");
		nomeForm.elements["telefono"].style.backgroundColor='FF5555'
		return false;
	}
	if (!validEmail(nomeForm.email.value)) {
		alert("Attenzione, la mail inserita non č valida");
		nomeForm.elements["email"].style.backgroundColor='FF5555'
		return false;
	}
	if (!accetto) {
		alert("Attenzione, bisogna accettare l'informativa sulla privacy");
		nomeForm.elements["accetto"].style.backgroundColor='FF5555'
		return false;
	}
	if (!accetto2) {
		alert("Attenzione, bisogna accettare i termini e le condizioni di utilizzo");
		nomeForm.elements["accetto2"].style.backgroundColor='FF5555'
		return false;
	}
	if (username.length < 1) {
		alert("Attenzione, inserire la username");
		nomeForm.elements["username"].style.backgroundColor='FF5555'
		return false;
	}
	if (password.length < 1) {
		alert("Attenzione, inserire la password");
		nomeForm.elements["password"].style.backgroundColor='FF5555'
		return false;
	}
	if (password2.length < 1) {
		alert("Attenzione, bisogna reinserire la password nell'apposito campo");
		nomeForm.elements["password2"].style.backgroundColor='FF5555'
		return false;
	}
	if (password2 != password) { 
		alert("Attenzione, le due password inserite non coincidono");
		nomeForm.elements["password"].style.backgroundColor='FF5555'
		nomeForm.elements["password2"].style.backgroundColor='FF5555'
		return false;
	}	
	else {
		return true;
	}	
}