window.onload = function() {
  loginForm = document.getElementById('iscrizione');
		loginForm.onsubmit = function () {
			return validateForm();
		}
}

function validateForm(){
	//recuperiamo i valori dei campi delle form
var nome = document.getElementById('nome').value;
var cognome = document.getElementById('cognome').value;
var parrocchia = document.getElementById('parrocchia').value;
var mail = document.getElementById('mail').value;
var telefono = document.getElementById('telefono').value;


var numCampiVuoti = 0;
var altriErrori =0;
var stringErrori="";
if ((nome == "") || (nome == "undefined")) {
   document.getElementById('nome').focus();
   document.getElementById("campoNome").className = "evidenziata";
 	numCampiVuoti++;
} 
else{
	document.getElementById("campoNome").className = "";
	
	}
	
	
if ((cognome == "") || (cognome == "undefined")) {
   document.getElementById('cognome').focus();
   document.getElementById("campoCognome").className = "evidenziata";
 numCampiVuoti++;
} 
else{
	document.getElementById("campoCognome").className = "";
	}
	
	if ((parrocchia == "") || (parrocchia == "undefined")) {
   document.getElementById('parrocchia').focus();
   document.getElementById("campoParrocchia").className = "evidenziata";
 numCampiVuoti++;
} 
else{
	document.getElementById("campoParrocchia").className = "";
	}

if (((mail.indexOf('@')== -1) || (mail.indexOf('.') == -1 ))|| mail==""){
      stringErrori+="Inserire un indirizzo mail valido nella forma: mail@provider.it \n";
   document.getElementById("mail").value="";
   document.getElementById("campoMail").className = "evidenziata";
 altriErrori++;
       
    }
	else{document.getElementById("campoMail").className = "";}

	
if(isNaN(telefono)||(telefono == "") || (telefono == "undefined")){
		 document.getElementById('telefono').value="";
	stringErrori+="Il campo telefono deve contenere almeno un valore numerico \n";
 document.getElementById('telefono').focus();
   document.getElementById("campoTelefono").className = "evidenziata";
   altriErrori++;
	}
else{document.getElementById("campoTelefono").className = "";}

if(numCampiVuoti>0){
	stringErrori+=("Tutti i campi con il simbolo (*) vanno completati obbligatoriamente \n");
	}
	
if(numCampiVuoti>0 || altriErrori >0){
window.alert("Attenzione si sono verificati i seguenti errori: \n"+stringErrori+"Controlla i campi evidenziati da un rettangolo blu");
return false;
}
else
{
	return true;
	}

	}

