//=====================================================
//  FUNZIONE CHE CONTROLLA IL CAMPO EMAIL DI UN FORM
//=====================================================			
function isEmailOk(data) {
  if (data.indexOf(".") != -1) {
      if (data.indexOf("@") != -1)  { 
	      return true;
		  }
		}
	else return false;	  
}

//=============================================================
//  FUNZIONE CHE CONTROLLA IL RIEMPIMENTO DEL CAMPO DI UN FORM
//=============================================================		
function isSpace(data) {
	var contr2=0;
   	for(var i=0; i < data.length; i++){
		if(data.substring(i, i+1) != " ")
	   		contr2=1; 
	}   
	if  (contr2==1)   
		return(false);  
return(true);
}

//=============================================================
//  FUNZIONE CHE CONTROLLA I CAMPI DI UN FORM ( FormN )
//=============================================================			
function checkRequiredFields() {
		
	var message = new Array();
	var errorLevel;
	
	message[0]  = "";
	
	message[1] = "I campi contrassegnati con l'asterisco sono obbligatori";
	message[2] = "Indirizzo email non valido";
	
	errorLevel = 0;  
	
	if ((errorLevel == 0) && ((document.FormN.tessera.value.length == 0) || isSpace(document.FormN.tessera.value))) {
		errorLevel = 1;	
		document.FormN.tessera.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.compagnia.value.length == 0) || isSpace(document.FormN.compagnia.value))) {
		errorLevel = 1;	
		document.FormN.compagnia.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.nome.value.length == 0) || isSpace(document.FormN.nome.value))) {
		errorLevel = 1;	
		document.FormN.nome.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.cognome.value.length == 0) || isSpace(document.FormN.cognome.value))) {
		errorLevel = 1;	
		document.FormN.cognome.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.indirizzo.value.length == 0) || isSpace(document.FormN.indirizzo.value))) {
		errorLevel = 1;	
		document.FormN.indirizzo.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.cap.value.length == 0) || isSpace(document.FormN.cap.value))) {
		errorLevel = 1;	
		document.FormN.cap.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.citta.value.length == 0) || isSpace(document.FormN.citta.value))) {
		errorLevel = 1;	
		document.FormN.citta.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.provincia.value.length == 0) || isSpace(document.FormN.provincia.value))) {
		errorLevel = 1;	
		document.FormN.provincia.focus();
	}
	if ((errorLevel == 0) && ((document.FormN.telefono.value.length == 0) || isSpace(document.FormN.telefono.value))) {
		errorLevel = 1;	
		document.FormN.telefono.focus();
	}
    if ((errorLevel == 0) && ((document.FormN.email.value.length == 0) || isSpace(document.FormN.email.value))) {
		errorLevel = 1;	
		document.FormN.email.focus();
	}
	if ((errorLevel == 0) && (!(isEmailOk(document.FormN.email.value)))) {
		errorLevel = 2;
		document.FormN.email.focus();
	}
		
	if (errorLevel > 0 ) { 
		alert(message[errorLevel]); 
		return false;
	} 
	else {
		return true;
	}
}
