
 
 //funzione che restituisce true se la 
 //stringa contiene solo spazi bianchi
 
  function isblank(s)
 {
 
 for(var i=0;i< s.length; i++) {
	 var c = s.charAt(i);
	 if ((c!=' ')&&(c!='\n')&&(c!='\t')) return false;
    }
    
 }

 
 function isEqual(Pwd,CPwd)
 {
 
   if (Pwd!=CPwd) {
   
     alert("Passwod e Confirm Password non sono uguali");
     return false;
     
     }else{
     
       return true;
     
     }
 }

 function Raggruppamento(strSoggetto,strTipologia)
{
  
 var ultima=(strTipologia.length-1)
 var c=strTipologia.charAt(ultima);  
 
 if((c=="*") && (isblank(strSoggetto) || (strSoggetto==null) || (strSoggetto==""))){
    
    return false; 
   
   }else{
   return true;
   }
 } 
 	   

 
 function verifyOpere(f)
 {
	var msg;
	var empty_fields = "";
	var errors = "";
	
	
	for(var i=0;i < f.length;i++) {
	 var e = f.elements[i];
	 
	 if (((e.type == "text") || (e.type == "textarea") || (e.type=="password") ) && !e.optional) {
	      //prima controllo se il campo è vuoto
	      if ((e.value == null) || (e.value == "") || isblank(e.value)) {
	          empty_fields += "\n         " +e.name;
	          continue;
	      }
	      
	      
	      //ora controllo i campi che dovrebbero essere valori numerici
	      if ((e.numeric) && ((e.min!=null) || (e.max != null))) {
	          var v = parseFloat(e.value);
	          if (isNaN(v) ||
	              ((e.min != null) && (v < e.min)) ||
	              ((e.max != null) && (v > e.max))) {
	              errors += "- il  campo "+ e.name + " deve essere un numero";
	              if (e.min != null)
	                  errors += " maggiore/uguale di "+ e.min;
	              if (e.max != null && e.min != null)
	                  errors += " e minore/uguale di " + e.max;
	              else if (e.max!=null)
	                    errors += "minore/uguale di " + e.max;
	              errors += "-\n";
	          }
	          
	     }
	     
	     if ((!e.numeric) && ((e.min!=null) || (e.max != null))) {
	          var v = e.value;
	              if (
	                 (e.min != null) && (v.length< e.min)||
	                 (e.max != null) && (v.length> e.max)
	                 ) {
	                 errors += "- il  campo " + e.name +" deve essere una stringa ";	                 
	                  if((e.min != null) && (v.length < e.min))
	                      errors += "con un numero di caratteri maggiore/uguale di "+ e.min;
	                 if((e.max != null) && (v.length> e.max))
	                      errors += "con un numero di caratteri mimore/uguale di "+ e.max;
	                      
	                 errors += "-\n";
	          }
	          
	     }
	     
	     
	}
	
   } //chiudo for
   
   
   
   
   
   if (!empty_fields && !errors &&  Raggruppamento(f.Soggetto.value,f.IdTipologia.options[f.IdTipologia.selectedIndex].text)) return true;
   
   msg  = "                                                              \n"; 
   msg += "______________________________________________________________\n\n";
   msg += " Il modulo non è stato inviato a causa degli errori seguenti. \n";
   msg += " Si prega di correggere gli errori e di inviarlo nuovamente. \n";  
   msg += "______________________________________________________________\n\n";
   
   
   if(!Raggruppamento(f.Soggetto.value,f.IdTipologia.options[f.IdTipologia.selectedIndex].text)){
    msg += "- La Tipologia "+f.IdTipologia.options[f.IdTipologia.selectedIndex].text+" richiede un Soggetto"+ "\n\n";
   }
 
   if (empty_fields) {
       msg += "- I seguenti campi richiesti risultano vuoti:" + empty_fields + "\n";
       
       if (errors) msg += "\n";
       
   }
   
 
   
   
   msg += errors;
   alert(msg);
   return false;
 }

  function verify(f)
 {
	var msg;
	var empty_fields = "";
	var errors = "";
	
	
	for(var i=0;i < f.length;i++) {
	 var e = f.elements[i];
	 
	 if (((e.type == "text") || (e.type == "textarea") || (e.type=="password") ) && !e.optional) {
	       
	      //prima controllo se il campo è vuoto
	      if ((e.value == null) || (e.value == "") || isblank(e.value)) {
	          empty_fields += "\n         " +e.name;
	          continue;
	      }
	      
	 
	            
	      //ora controllo i campi che dovrebbero essere valori numerici
	      if ((e.numeric) && ((e.min!=null) || (e.max != null))) {
	          var v = parseFloat(e.value);
	          if (isNaN(v) ||
	              ((e.min != null) && (v < e.min)) ||
	              ((e.max != null) && (v > e.max))) {
	              errors += "- il  campo "+ e.name + " deve essere un numero";
	              if (e.min != null)
	                  errors += " maggiore/uguale di "+ e.min;
	              if (e.max != null && e.min != null)
	                  errors += " e minore/uguale di " + e.max;
	              else if (e.max!=null)
	                    errors += "minore/uguale di " + e.max;
	              errors += "-\n";
	          }
	          
	     }
	     
	     if ((!e.numeric) && ((e.min!=null) || (e.max != null))) {
	          var v = e.value;
	              if (
	                 (e.min != null) && (v.length< e.min)||
	                 (e.max != null) && (v.length> e.max)
	                 ) {
	                 errors += "- il  campo " + e.name +" deve essere una stringa ";	                 
	                  if((e.min != null) && (v.length < e.min))
	                      errors += "con un numero di caratteri maggiore/uguale di "+ e.min;
	                 if((e.max != null) && (v.length> e.max))
	                      errors += "con un numero di caratteri mimore/uguale di "+ e.max;
	                      
	                 errors += "-\n";
	          }
	          
	     }
	     
	     
	}
	
   } //chiudo for
   
   
   
   
   
   if (!empty_fields && !errors ) return true;
   
   msg  = "                                                              \n"; 
   msg += "______________________________________________________________\n\n";
   msg += " Il modulo non è stato inviato a causa degli errori seguenti. \n";
   msg += " Si prega di correggere gli errori e di inviarlo nuovamente. \n";  
   msg += "______________________________________________________________\n\n";
   
  
 
   if (empty_fields) {
       msg += "- I seguenti campi richiesti risultano vuoti:" + empty_fields + "\n";
       
       if (errors) msg += "\n";
       
   }
   
 
   
   
   msg += errors;
   alert(msg);
   return false;
 }

       
             

	                                              
	              
	          
	   	 