
function tornaindietro() {
	document.frmiscrizione2.submit();
}

var msg;
function trim(trim_string) { 
   // this will get rid of leading spaces 
   while (trim_string.substring(0,1) == ' ') 
       trim_string = trim_string.substring(1, trim_string.length);

   // this will get rid of trailing spaces 
   while (trim_string.substring(trim_string.length-1,trim_string.length) == ' ')
       trim_string = trim_string.substring(0, trim_string.length-1);

	return trim_string;
} 

function veremail(chi, messaggio1, messaggio2) {
	// verifica della sintassi dell' e-mail 
	if (trim(chi.value) != '') {
		var str;
		var vet1,vet2;
		 
		 str=chi.value;
		 vet1=str.split("@"); 
		 if (vet1[0]=="" || vet1[0].length < 2 || vet1.length>2) {
			msg = msg + messaggio2;
			return false;
		 }

		 if (typeof(vet1[1])!="undefined") {
			if (vet1[1].length<5) {
				msg = msg + messaggio2;
				return false;
			}
		 }
		 else {
			msg = msg + messaggio2;
			return false;
		 }
		 			
		 vet2=vet1[1].split(".");
		 if (vet2[0].length < 2) {
			msg = msg + messaggio2;
			return false;
		 }
		 if (typeof(vet2[1])!="undefined") {
			if (vet2[1].length<2){
				msg = msg + messaggio2;
				return false;
			}
		 }
		 else {
			msg = msg + messaggio2;
			return false;
		 }
		 
		 return true; 
	}else{
		msg = msg + messaggio1;
		return false;
	}
}
	
function validate(){
	msg = '';
	
	if (document.frmiscrizione.privacy[0].checked) {
		//ok

		if (document.frmiscrizione.email.value != '') {
			var a = veremail(document.frmiscrizione.email,"Inserisci un indirizzo email\n","Inserisci un corretto indirizzo email\n");
		}
		else {
			msg = msg + "Inserisci un indirizzo email\n";
		}
		
		if (trim(document.frmiscrizione.email.value) != trim(document.frmiscrizione.email2.value)) {
			msg = msg + "I campi Email e Conferma Email devono essere uguali\n";
		}
		
		
		if (trim(document.frmiscrizione.psw.value) == '') {
			msg = msg + "Inserisci la Password\n";
		}
		else
		{
			var trimString	= trim(document.frmiscrizione.psw.value);
			if (trimString.length < 6) {
				msg = msg + "La Password deve essere lunga almeno 6 caratteri\n";
			}
		}
		
		if (trim(document.frmiscrizione.verpsw.value) == '') {
			msg = msg + "Inserisci la conferma Password\n";
		}
		if (trim(document.frmiscrizione.psw.value) != trim(document.frmiscrizione.verpsw.value)) {
			msg = msg + "I campi Password e Conferma Password devono essere uguali\n";
		}
		
		if (trim(document.frmiscrizione.nome.value) == '') {
				msg = msg + "Inserisci il Nome\n";
			}
		if (trim(document.frmiscrizione.cognome.value) == '') {
				msg = msg + "Inserisci il Cognome\n";
			}
		
		if (trim(document.frmiscrizione.cf.value) == '') {
				msg = msg + "Inserisci il Codice Fiscale\n";
			}
			else
			{
				var trimString	= trim(document.frmiscrizione.cf.value);
				if (trimString.length !=16) {
					msg = msg + "Controlla il Codice Fiscale\n";
				}
		}
		
	
		
		
		
		if (trim(document.frmiscrizione.indirizzo.value) == '') {
			msg = msg + "Inserisci l'Indirizzo\n";
		}
		if (trim(document.frmiscrizione.numero.value) == '') {
			msg = msg + "Inserisci il Numero civico\n";
		}
		
		var numcap = document.frmiscrizione.cap.value;
		if (trim(numcap) != '') {
			if (isNaN(numcap)) {
				msg = msg + "Inserisci un Cap corretto\n";
			}
		}
		else {
			msg = msg + "Inserisci il Cap\n";
		}
		
		if (trim(document.frmiscrizione.citta.value) == '') {
			msg = msg + "Inserisci la Citta'\n";
		}
		if (trim(document.frmiscrizione.provincia.value) == '') {
			msg = msg + "Inserisci la Provincia\n";
		}
		if (trim(document.frmiscrizione.tel.value) == '') {
			msg = msg + "Inserisci un recapito telefonico\n";
		}
		
		
		
		
		
		
		
	}
	else {
		msg = "E' necesaria l'autorizzazione al trattamento dei dati personali";
	}
	
	if (msg != '') {
		msg = 'Devi compilare i seguenti campi:\n\n' + msg;
		alert(msg);
		return false;
	}
}

