/*================================================
 * FUNZIONE: VerificaSelezione
 * INGRESSO: nome del campo.
 * USCITA: true se esiste una selezione, false
 * altrimenti.
 * VARIABILI GLOBALI USATE: nessuna.
 * VARIABILI GLOBALI MODIFICATE: nessuna.
 * DESCRIZIONE: verifica che il campo passato abbia
 * almeno una selezione.
 *================================================*/
function VerificaCampi(NomeForm, ListaCampi) {
	var CampiOb, emailID;
	emailID=NomeForm.Email;
	
	   // crea il vettore dei campi da controllare
          CampiOb = ListaCampi.split(":");
          // se uno dei campi e' vuoto visualizza l'errore
          // e torna falso
          for (i=0; i < CampiOb.length; i++) {
                    if (NomeForm[CampiOb[i]].value == "" ||
                    	(NomeForm[CampiOb[i]].name == "acconsente_uno" &&
                    	NomeForm[CampiOb[i]].value == "no") ||
                    	(NomeForm[CampiOb[i]].name == "acconsente_due" &&
                    	NomeForm[CampiOb[i]].value == "no") ||
                    	(NomeForm[CampiOb[i]].name == "acconsente_tre" &&
                    	NomeForm[CampiOb[i]].value == "no") ||
                    	(NomeForm[CampiOb[i]].name == "Tipo_di_pagamento" &&
                    	NomeForm[CampiOb[i]].value == "-") &&
                        NomeForm[CampiOb[i]].type != "submit" &&
                        NomeForm[CampiOb[i]].type != "reset" &&
                        NomeForm[CampiOb[i]].type != "button" &&
                        NomeForm[CampiOb[i]].type != "hidden") {
                        alert("*Si ricordi di compilare i campi obbligatori e di accettare la normativa sulla privacy.");
			 NomeForm[CampiOb[i]].focus();
	                 return false;
                    }
          }
		  
		  if (echeck(emailID.value)==false){
			emailID.value="";
			emailID.focus();
			return false;
			}
			
          // i campi richiesti sono ok!
          return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("L'indirizzo e-mail non è formattato correttamente")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("L'indirizzo e-mail non è formattato correttamente")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("L'indirizzo e-mail non è formattato correttamente")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("L'indirizzo e-mail non è formattato correttamente")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("L'indirizzo e-mail non è formattato correttamente")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("L'indirizzo e-mail non è formattato correttamente")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("L'indirizzo e-mail non è formattato correttamente")
		    return false
		 }

 		 return true					
	}
