function validaCampi(document){
	if(!controlloCampo("newlog",'Indicare il campo LOGIN'))return false;
	if (document.formDatiUtente.newlog.value.length < 5) {alert("Indicare una login di almeno 5 caratteri!");
													return false;}
	if(!controlloCampo("newpassword",'Indicare il campo PASSWORD'))return false;
	if(!controlloCampo("confpwd",'Indicare il campo RISCRIVI PASSWORD'))return false;   
	if (document.formDatiUtente.newpassword.value!=document.formDatiUtente.confpwd.value){
    	alert("Riscrivere la password! ");
    	return false;
    	} 
	if(!controlloCampo("nome",'Indicare il campo NOME'))return false;
	if(contrNumber("nome")){	
			alert('Indicare un valore corretto per il campo NOME')
			return false;
		}
	if(!controlloCampo("cognome",'Indicare il campo COGNOME'))return false;
	if(contrNumber("cognome")) {	
			alert('Indicare un valore corretto per il campo COGNOME')
			return false;
		}
	if(getComboText(document,"DATI_ANAG0Sesso")=="")  {
    	alert("Indicare il SESSO");
    	return false;
    } 
    if(!controlloCampiData("gg1","mm1","aa1",'Indicare valori corretti nei campi relativi alla data di nascita','Indicare la DATA DI NASCITA'))return false;	
	if(!controlloCampo("nazionalita",'Indicare il campo NAZIONALITA'))return false;
	if(contrNumber("nazionalita")) {	
			alert('Indicare un valore corretto per il campo NAZIONALITA')
			return false;
		}
	if(!controlloCampo("indirizzo",'Indicare il campo INDIRIZZO'))return false;
	if(!controlloCampo("civico",'Indicare il campo NUMERO CIVICO '))return false;
	if(!controlloCampo("cap",'Indicare il campo CAP'))return false;
	if(contrAlphabet(document.formDatiUtente.cap.value)) {	
			alert('Indicare un valore corretto per il campo CAP')
			return false;
		}
	if (document.formDatiUtente.cap.value.length != 5){	
			alert('Indicare un valore di lunghezza corretta per il campo CAP')
			return false;
		}
	if(!controlloCampo("citta",'Indicare il campo CITTA'))return false;
	if(contrNumber("citta")) {	
			alert('Indicare un valore corretto per il campo CITTA')
			return false;
		}	
    if(getComboText(document,"RESIDENZA0Provincia")=="")  {
    	alert("Indicare la PROVINCIA");
    	return false;
    } 
	if(getComboText(document,"INFO_PERSONALI0Cod_Stato_Civile")==""){
    	alert("Indicare lo STATO CIVILE");
    	return false;
    } 
    if(!controlloCampo("codFiscale",'Indicare il campo CODICE FISCALE'))return false;   
    if (!check_cf("codFiscale")) return;
	
    if(!controlloCampo("telefono",'Indicare il campo TELEFONO'))return false;
    if(contrAlphabet(document.formDatiUtente.telefono.value)) {	
			alert('Indicare un valore corretto per il campo TELEFONO')
			return false;
		}
	if 	(document.formDatiUtente.fax.value.length>0){
		if(contrAlphabet(document.formDatiUtente.fax.value)) {	
				alert('Indicare un valore corretto per il campo FAX')
				return false;
			}
	}
	if(!controlloCampo("email",'Indicare il campo EMAIL'))return false;
	if (!validamail(document.formDatiUtente.email.value)) return;
       //Controllo che sia spuntato il check relativo all'autorizzazione del trattamento dei dati personali 
     var trattamentoDati=document.getElementById("Autorizzo").checked;
     if(!trattamentoDati){
     	alert( "L'autorizzazione al trattamento dei dati personali è necessaria al fine della registrazione." )
        return false;
     }

 return true;    	
}
/** verifico che lì'indirizzo e-mail conteng ai caratteri '@' e i '.' */
function validamail(mail){
	var ckOK = "@.";
    if (mail.length > 0){
    	var contAt = false;
	    var contDot = false;
	    for (i=0;i < mail.length;i++){	      
	        	if (mail.charAt(i) == '@')
	        	    contAt = true;
		     	if (mail.charAt(i) == '.')
	        	    contDot = true;
	     if (contDot && contAt) {	return true;  	}
		}
    }
   alert('Inserire un indirizzo e-mail valido');
   return false; 	
 }   	
/** verifica se la stringa di input contiene numeri**/
function contrNumber(strInput){
	var ckOK = "0123456789";
    var ok = false;
    var str = document.getElementById(strInput).value;
	if (str.length > 0){
	    for (i=0;i < str.length;i++){
		      for (j=0;j < ckOK.length;j++){
		        	if (str.charAt(i) == ckOK.charAt(j)){  	
		        		ok = true; 
		        		break;}
		      }
		      if (ok) break;
	     }
	}
   return ok;
}
    
/** verifica se la stringa di input contiene caratteri**/
function contrAlphabet(strInput){
	var ckOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var ok = false;
    var str = strInput;
	if (str.length > 0){
	      for (i=0;i < str.length;i++){
	      for (j=0;j < ckOK.length;j++){
	        if (str.charAt(i) == ckOK.charAt(j)){
	        	ok = true; break;}
	      }
	      if (ok) break;
	    }
	}
  	return ok;
}

/** Controlla la validita del codice fiscale **/
function check_cf(obj){
	  var ckOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	  var cf = document.getElementById(obj).value;
	  if (cf.length > 0){
		   var ok = true;
		   if (cf.length > 0 && cf.length < 16) 	ok = false;
		   if ((!contrAlphabet(cf.substring(0,6)))||(!contrAlphabet(cf.substring(8,9)))||(!contrAlphabet(cf.substring(11,12)))||(!contrAlphabet(cf.substring(15))))
		    	ok=false;
		   if ((isNaN(cf.substring(6,8)))||(isNaN(cf.substring(9,11)))||(isNaN(cf.substring(12,15))))
		    	ok=false;		    	
		    if (!ok){
		    	alert("Verificare il formato del campo Codice Fiscale!");
		    	document.getElementById(obj).focus();
		    	return false;
		    }
		}
	  return true;
}

/******************controlloCampo(campo,msg)******************************/
function controlloCampo(campo,msg){
   if(document.getElementById(campo).value=='')	{
		alert(msg);
		document.getElementById(campo).focus();
	    return false;	
    }
 return true;
 }
 
 function getComboText(document,comboName){
	var indice= document.getElementById(comboName).options.selectedIndex; 
    var testo=document.getElementById(comboName).options[indice].text;
    return testo;
}
/******************controlloCampiData(gg,mm,aa,msg1,msg2)******************************/
function controlloCampiData(gg,mm,aa,msg1,msg2){
   var g=document.getElementById(gg).value;
   var m=document.getElementById(mm).value;
   var a=document.getElementById(aa).value;
   
   var dat=g+"/"+m+"/"+a;
   if(document.getElementById(gg).value!=''  && document.getElementById(mm).value!=''&&document.getElementById(aa).value!='' )	{
		var flag=Controllo_Data(dat);
    	if(flag==false){
	   		alert(msg1);
	   		return false;
		}
	}
	else{
        alert(msg2);
	    return false;
	}
 return true;
 }
 
/******************Controllo_Data(today)******************************/
 function Controllo_Data(today){
var daysInMonth = new Array(12);
daysInMonth[2] = 29;   // si deve testare in programma
if ((today.charAt(2) == '/') && (today.charAt(5) == '/')){
	D=today.split('/');
	gg=D[0];
	mm=D[1];
	aa=D[2];
	if(isNaN(gg)){
	//alert('Il giorno deve essere un valore compreso tra 01 e 31');
	return false;
	}else if((gg>31)|| (gg<1) ||(gg.length<2)){
	//alert('Il giorno deve essere compreso tra 01 e 31')
	return false;
	}else if(isNaN(mm)){
	//alert('Il mese deva essere un valore compreso tra 01 e 12');
	return false;
	}else if((mm>12)|| (mm<1) ||(mm.length<2)){
	//alert('Il mese deve essere compreso tra 01 e 12')
	return false;
	}else if(isNaN(aa)){
	//alert('Inserire un valore numerico per l\' anno');
	return false;
	}else if ((aa.length<4)||(aa.length>4) || (aa<1) ){
	 //alert('L\' anno deve essere nel formato yyyy');
	 return false;
	 }	 
}else{
return true;
}
if ((mm=='04')||(mm=='06')||(mm=='09')||(mm=='11')){
		if(gg>30){
			//alert('Il mese inserito è di 30 giorni');
			return false;
			}
}else if(mm=='02'){
//processo anno bisestile
	if(gg>29){
	alert('Febbraio ha meno di 30 giorni');
	return false
	}else if ((gg=='29')&&(!((aa % 4 == 0) && (!(aa % 100 == 0)) || (aa % 400 == 0)))){
	alert('L\'anno inserito non è bisestile');
	return false;
	}
}
	return true;
}
 
 /*****************void checkNum()*******************************/
function checkNum(evt){
	var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1); // se browser è ie 
	var e = (window.event) ? window.event : evt;
	if(ie) 	{
    		key = event.keyCode;
  	} 	else key = e.which;

	//if((event.ctrlKey && key==86) || key==190 || key == 110 || key == 37 || key== 39 || key==9) return true;
	if((e.ctrlKey && key==86) || key==190 || key == 110 || key == 37 || key== 39 || key==9) return true;
  		
  	if((key < 48 || key > 58) && (key != 8 && key != 13 && key != 46 )) {
        	if(key < 96 || key > 105)		
        	return false;                	
        }
	return true;
}
 /******************cambiaFocus(point1,point2,max)******************************/
function cambiaFocus(point1,point2,max) {
	Lunghezza = document.getElementById(point1).value.length;
	if (Lunghezza == max ) 
			document.getElementById(point2).focus();		
}
/******************trim(stringa)******************************/
function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}
/******************isDate(dateStr) nel formato gg/mm/aaaa******************************/
function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
		alert('Bisogna inserire delle date di nascita valide!');
		return false;
	}

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[5];

	if ((day < 1 || day > 31) || (month < 1 || month > 12) || ((month==4 || month==6 || month==9 || month==11) && day==31)) {
		alert('Bisogna inserire delle date di nascita valide!');
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Febbraio " + year + " non ha " + day + " giorni!");
			return false;
		}
	}
	return true; // date is valid
}