
var registrazione =true;
 
 // colore
 var alertcolor="#F9A98E";
 var alertcolor1="#FDF1F1";
 
 

var espressione = /^[a-z0-9]/;
 

// questa funzione di occupa di far apparire il div di errore cancellare il testo errato, evidenziare l'input text, e inserire un msg di errore
function alertDiv(id, text, idInput, idText, idSubmit, notNull){
	
	
		
	
	if(!text)
		text="Campo "+id+" non valido/a";

	 //elimino il carattere non consentito
	 	
         //   document.getElementById(id).value = "";
            //evidenzio di rosso l'imputext 
			
			 // div di errore
            //document.getElementById('trasparentDiv').style.cssText=" visibility: visible; width:445px; height:30px; border:1px dotted "+alertcolor+"; float:right";
			//document.getElementById('tdAllertMsg').innerHTML='Errore!';
			// inserisco il testo di errore
			 //document.getElementById('testo_alert').innerHTML= text;
			 	changeClass(idInput, 'divAlert');
				
				
			 	document.getElementById(idText).innerHTML=text;
				
				if(notNull!=1)
				{
					document.getElementById(idSubmit).disabled=true;
					
					document.getElementById(id).style.cssText="background-color:"+alertcolor;
				
				}
				else
				{
					
					document.getElementById(id).style.cssText="background-color:"+alertcolor1;
					
					//alert(alertcolor1);
				}
				
			 }
			 


// procede alla decolorizzazione del input text
    function decoloration(id, idInput, idText, idSubmit){
        
        document.getElementById(id).style.cssText="background-color:#fff";
		 document.getElementById(idText).innerHTML='';
	
		changeClass(idInput, 'invisibile')
		
		if(idSubmit)
   			document.getElementById(idSubmit).disabled=false;
    }
    
	
	
	
	
    function invisibleDiv(idInput){
        
        document.getElementById('trasparentDiv').style.cssText="overflow:hidden;visibility:hidden;position: relative; width:0px; height:0px;top: -370px;left:120px;alpha(opacity=10)-moz-opacity:.10;opacity:.10;	cursor:pointer;z-index:-24!important;";
		// document.getElementById(idInput).innerHTML= '';
		
		
    
    }
	
	//-----------------------------------------------------------------
	//	 validateForm: controlla se i campi sono diversi da null (vuoti)
	//-----------------------------------------------------------------
  
		/*function validateForm(){

		var control=true;
		// recupero tutti i field 
			<xsl:for-each select="//fieldset/field">
			
			
					
					
					<xsl:if test="@notnull = 'yes'">
							var <xsl:value-of select="form_name" />value = document.upd_record.<xsl:value-of select="form_name" />.value;
							
					
						if ((<xsl:value-of select="form_name" />value == "") || (<xsl:value-of select="form_name" />value == "undefined") ) 
							control=false;
				
				</xsl:if>
				
				
			</xsl:for-each> 
			if(control==false){
				 document.getElementById('trasparentDiv').style.cssText=" visibility: visible; width:445px; height:30px; border:1px dotted "+alertcolor+"; float:right";
			// inserisco il testo di errore
			 document.getElementById('testo_alert').innerHTML= "I campi con * sono obbligatori";
				upd_record.save.disabled=true;
			//alertDiv("save", 'I campi sono obbligatori');
			}else{
			
				//alert('abilitato')
				upd_record.save.disabled=false;
			}
		
	}*/
function emailCheck(id, alert_text,idInput, idText, idSubmit, notNull){
	
	// Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	 var inputmail = document.getElementById(id);
	 var email = inputmail.value;
	
  if (!email_reg_exp.test(email)) {
	  		
           	alertDiv(id, alert_text,idInput, idText, idSubmit , notNull);
           // inputmail.select();
            
           return false;
        }
    return true;
}		
 
 function simpleTextControl(id, maxlength, alert_text, idInput, idText, idSubmit, notNull )
{
    var stringa = document.getElementById(id).value;
	 var lengthstring=stringa.length;
        //ARRECORDARI- da -1 se non la trova
        //TO DO: trovare un modo pi semplice per farlo
		
        if ((stringa.indexOf("/") != (-1)) ||
            (stringa.indexOf(",") != (-1)) ||
            (stringa.indexOf(" \ ") != (-1)) ||
             (stringa.indexOf(">") != (-1)) ||
              (stringa.indexOf("<") != (-1)) ||
               (stringa.indexOf("?") != (-1)) ||
               (stringa.indexOf("$") != (-1)) ||
               (stringa.indexOf("'") != (-1)) ||
               (stringa.indexOf("(") != (-1)) ||
               (stringa.indexOf(")") != (-1)) ||
               (stringa.indexOf("&") != (-1)) ||
               (stringa.indexOf("%") != (-1)) ||
               (stringa.indexOf("") != (-1)) ||
               (stringa.indexOf("!") != (-1)) ||
               (stringa.indexOf("|") != (-1)) ||
               (stringa.indexOf("^") != (-1)) ||
               (stringa.indexOf("=") != (-1)) ||
			   (stringa.indexOf(",") != (-1)) ||
               (stringa.indexOf(";") != (-1)) ||
               (stringa.indexOf("_") != (-1)) ||
			   (stringa.indexOf("-") != (-1)) ||
				(stringa.indexOf("+") != (-1)) ||
				(stringa.indexOf("*") != (-1)) ||
				(stringa.indexOf("[") != (-1)) ||  
				(stringa.indexOf("}") != (-1)) ||
				(stringa.indexOf("{") != (-1)) ||
						 
			    (stringa.indexOf("\\") != (-1)) ||
				(lengthstring>=maxlength) ||
			   //SE LA STRINGA E' ALFANUMERICA (test() e UN METODO dell'oggetto RegExp)
			   //(espressione.test(stringa)) ||
			    //TO DO: NUMERICO NON FUNZIONA
			  (!isNaN(stringa))
			   //END TO DO:  
            	)
				{
             		alertDiv(id, alert_text, idInput, idText, idSubmit, notNull);
             		//qualcosa di queste duecento cose ha reso true: quale? scrvi in quanti secondi (puynteggio:9)
					return false;
        		}
       			 else{
   					return true; 
   				}
}


function advansedTextControl(id, maxlength, alert_text, idInput, idText, idSubmit, notNull )
{
    var stringa = document.getElementById(id).value;
	 var lengthstring=stringa.length;
        //ARRECORDARI- da -1 se non la trova
        //TO DO: trovare un modo pi semplice per farlo
		
        if ((stringa.indexOf("/") != (-1)) ||
           
            (stringa.indexOf(" \ ") != (-1)) ||
             (stringa.indexOf(">") != (-1)) ||
              (stringa.indexOf("<") != (-1)) ||
              
               (stringa.indexOf("$") != (-1)) ||
			   (stringa.indexOf("=") != (-1)) ||
              
               
               (stringa.indexOf("&") != (-1)) ||
               (stringa.indexOf("%") != (-1)) ||
              
               
               (stringa.indexOf("^") != (-1)) ||
               (stringa.indexOf("=") != (-1)) ||
			 
               (stringa.indexOf("_") != (-1)) ||
			
				
				(stringa.indexOf("*") != (-1)) ||
				(stringa.indexOf("[") != (-1)) ||  
				(stringa.indexOf("}") != (-1)) ||
				(stringa.indexOf("{") != (-1)) ||
						 
			    (stringa.indexOf("\\") != (-1)) ||
				(lengthstring>=maxlength) ||
			   //SE LA STRINGA E' ALFANUMERICA (test() e UN METODO dell'oggetto RegExp)
			   //(espressione.test(stringa)) ||
			    //TO DO: NUMERICO NON FUNZIONA
			  (!isNaN(stringa))
			   //END TO DO:  
            	)
				{
             		alertDiv(id, alert_text, idInput, idText, idSubmit, notNull);
             		//qualcosa di queste duecento cose ha reso true: quale? scrvi in quanti secondi (puynteggio:9)
					return false;
        		}
       			 else{
   					return true; 
   				}
}



 function nCivico(id, maxlength, alert_text, idInput, idText, idSubmit, notNull)
{
    var stringa = document.getElementById(id).value;
	 var lengthstring=stringa.length;
	 
	 
        //ARRECORDARI- da -1 se non la trova
        //TO DO: trovare un modo pi semplice per farlo
		
        if ((stringa.indexOf(",") != (-1)) ||
             (stringa.indexOf(">") != (-1)) ||
              (stringa.indexOf("<") != (-1)) ||
               (stringa.indexOf("?") != (-1)) ||
               (stringa.indexOf("$") != (-1)) ||
               (stringa.indexOf("'") != (-1)) ||
               (stringa.indexOf("(") != (-1)) ||
               (stringa.indexOf(")") != (-1)) ||
               (stringa.indexOf("&") != (-1)) ||
               (stringa.indexOf("%") != (-1)) ||
               (stringa.indexOf("") != (-1)) ||
               (stringa.indexOf("!") != (-1)) ||
               (stringa.indexOf("|") != (-1)) ||
               (stringa.indexOf("^") != (-1)) ||
               (stringa.indexOf("=") != (-1)) ||
			   (stringa.indexOf(",") != (-1)) ||
               (stringa.indexOf(";") != (-1)) ||
               (stringa.indexOf('"') != (-1)) ||
			   (stringa.indexOf("_") != (-1)) ||
			   (stringa.indexOf("-") != (-1)) ||
				(stringa.indexOf("+") != (-1)) ||
				(stringa.indexOf("*") != (-1)) ||
				(stringa.indexOf("[") != (-1)) ||  
				(stringa.indexOf("}") != (-1)) ||
				(stringa.indexOf("{") != (-1)) ||
				(stringa=='') ||
				(lengthstring>=maxlength)
            	)
				{
             		alertDiv(id, alert_text, idInput, idText, idSubmit, notNull);
             		//qualcosa di queste duecento cose ha reso true: quale? scrvi in quanti secondi (puynteggio:9)
					return false;
        		}
       			 else{
   					return true; 
   				}
}
 
function numeric(id, maxlength, alert_text,idInput, idText, idSubmit, notNull){
	
	var inputnumeric = document.getElementById(id);
	 var numeric = inputnumeric.value;
	 var lengthstring=numeric.length;
	
	if (isNaN(numeric) || (lengthstring <= maxlength)) {
          alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
           //document.modulo.telefono.focus();
           return false;
        }
    return true;
}


function confermaPsw(id, idPsw,  alert_text,idInput, idText, idSubmit){
	
	var pswConferma = document.getElementById(id).value;
	var psw= document.getElementById(idPsw).value;
	
	//alert()
	
	
	if (pswConferma != psw) {
          alertDiv(id, alert_text,idInput, idText, idSubmit);
           //document.modulo.telefono.focus();
           return false;
        }
    return true;
}
 
 
 


function sitelink(id, alert_text,idInput, idText, idSubmit, notNull){
	
	// Espressione regolare dell'email
     var link_reg_exp = /^([w])+\.(([a-zA-Z0-9_\.\-])+\.)+([a-zA-Z0-9]{2,})+$/;
	 var inputlink = document.getElementById(id);
	 var sitelink = inputlink.value;
	
  if (!link_reg_exp.test(sitelink)) {
	  		
           	alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
           // inputlink.select();
            
           return false;
        }
	return true;
}


function date(id, alert_text, idInput, idText, idSubmit, notNull)
   { 
    var inputdate = document.getElementById(id);
  //Effettua il controllo sul campo DATA DI NASCITA
        if (inputdate.value.substring(2,3) != "/" ||
           inputdate.value.substring(5,6) != "/" ||
           isNaN(inputdate.value.substring(0,2)) ||
           isNaN(inputdate.value.substring(3,5)) ||
           isNaN(inputdate.value.substring(6,10))) {
             	alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
              inputdate.value = "";
             // inputdate.focus();
              inputdate.style.cssText="background-color:#F9A98E";
              return false;
        }
        else if (inputdate.value.substring(0,2) > 31) {
           alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
           inputdate.select();
           inputdate.style.cssText="background-color:#F9A98E";
           return false;
        }
        else if (inputdate.value.substring(3,5) > 12) {
           alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
           inputdate.value = "";
          // inputdate.focus();
           inputdate.style.cssText="background-color:#F9A98E";
           return false;
        }
        else if (inputdate.value.substring(6,10) < 1900) {
           alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
           inputdate.value = "";
        //   inputdate.focus();
           inputdate.style.cssText="background-color:#F9A98E";
           return false;
        }
    return true;
   }
 
 function codiceFiscale(cfins, alert_text)
   {
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
   }
   
   function CheckCF(id, alert_text,idInput, idText, idSubmit, notNull)
   {
	   
   var CFok=codiceFiscale(document.getElementById(id).value)
   if (CFok==false)
      {
       alertDiv(id, alert_text,idInput, idText, idSubmit, notNull);
      return false;
      }
   else
      return true;
   }
   
 
 
 
 
 
  function catturaRegistrazione()
 {
	if(simpleTextControl('nomeRichiesta', '20', 'Nome nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false 
		|| simpleTextControl('cognomeRichiesta', '20', 'Cognome nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false 
		|| simpleTextControl('luogo_nascita', '20', 'Luogo di nascita nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		|| simpleTextControl('res_indirizzo', '20', 'Indirizzo nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		||  simpleTextControl('res_citta', '20', 'Citta nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		|| nCivico('res_civico', '5', 'N civico nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		||  simpleTextControl('res_provoincia', '20', 'Provincia nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		|| emailCheck('email', 'Telefono cellulare nullo o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		||  simpleTextControl('password', '20', 'password nulla o non valido', 'divAlert', 'resultAlertDiv', 'registrazione')==false
		)
		{
	
		 alertDiv('nomeRichiesta', 'Tutti i campi sono obbligatori','divAlert', 'resultAlertDiv', 'registrazione');
		 
		}
		
	}
	
	



function catturaLogin()
 {
	if(simpleTextControl('userLogin', '20', 'Username nullo o non valido', 'divAlert', 'resultAlertDiv', 'login', '#F9A98E')==false 
		|| simpleTextControl('passwordLogin', '20', 'Password nulla o non valida', 'divAlert', 'resultAlertDiv', 'login', '#F9A98E')==false 
		)
	{
	
		 alertDiv('userLogin', 'Tutti i campi sono obbligatori','divAlert', 'resultAlertDiv', 'registrazione');
		 
		 
		
	}
		
	return true
 
 }
 
 
 function catturaRicerca(id)
 {
	var string=document.getElementById(id).value;
	
	
	if(string!='' && string.length>2)
	{
		if(nCivico(id, '20000', 'Testo ricercato nulla o non valido.', 'divAlert', 'resultAlertDiv', 'ricercaAvanzata', 1))
		{
			ajaxInviaDati('stringa='+string, 'ajax.php', 'viewResultSearch(req.responseText)');
		}else{
			alertDiv(id, 'Carattere non corretto', 'divAlert', 'resultAlertDiv', 'ricercaAvanzata', 1)
			return false
		}
	}else{
			alertDiv(id, 'Sono necessarie almeno 3 lettere per effettuare la ricerca rapida.', 'divAlert', 'resultAlertDiv', 'ricercaAvanzata', 1)
		return false
	}
	
		
	return true
 
 }
	 