  /*---------------------------------------------------------------------------*/
  /* alltrim                                                                   */
  /*---------------------------------------------------------------------------*/
  function alltrim(str) 
  {
    return str.replace(/^\s+|\s+$/g, '');
  }
  /*---------------------------------------------------------------------------*/


  /*--------------------------------------------------------------------------*/
  /* Effettua il submit della pagina a seconda dei parametri passati          */
  /*--------------------------------------------------------------------------*/
  function MySubmit(NomePagina,MyParam)
  {
    if (MyParam === null)
    {
      document.form1.action = NomePagina;
    }
    else
    {
     document.form1.action = NomePagina + "?STF=" + MyParam;
    }
   
    document.form1.targhet = "_self";
    document.form1.submit();
  }
  /*---------------------------------------------------------------------------*/
 

  /*---------------------------------------------------------------------------*/
  /* funzione per prendere un elemento con id univoco con i diversi browser    */
  /*---------------------------------------------------------------------------*/
  function getElByID(IDMyElement)
  {
	  var MyElement;
		if(document.getElementById)
		  MyElement = document.getElementById(IDMyElement);
		else
				MyElement = document.all[IDMyElement];
		return MyElement;
	}
	/*---------------------------------------------------------------------------*/
 
 
  /*---------------------------------------------------------------------------*/
  /* Ritorna l'estensione di un file passto                                    */
	/*---------------------------------------------------------------------------*/
  function ReturnFileExstension(MyPathFile)
	{
	  MyExtension = MyPathFile.substring(MyPathFile.lastIndexOf(".")+1,MyPathFile.length);
		return MyExtension;
	}
  /*---------------------------------------------------------------------------*/
        
  
  /*---------------------------------------------------------------------------*/
  /* CheckDate Contolla la vaidità di una data                                 */
	/*---------------------------------------------------------------------------*/
  function CheckValidDate(stringa)
  {
  	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
  	if (!espressione.test(stringa))
  	{
  	    return false;
  	}else{
  		anno = parseInt(stringa.substr(6),10);
  		mese = parseInt(stringa.substr(3, 2),10);
  		giorno = parseInt(stringa.substr(0, 2),10);
  		
  		var data=new Date(anno, mese-1, giorno);
  		if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
  			return true;
  		}else{
  			return false;
  		}
  	}
  }
  
      
  /*---------------------------------------------------------------------------*/
  /* CheckSelGrid                                                              */
  /* Ritorna true se ci sono degli elementi selezinati nella griglia           */
  /*---------------------------------------------------------------------------*/
  function CheckSelGrid()
  {
    MyEsito  = false;
    
    for(var x=0; x < document.getElementsByName('CheckField[]').length;x++)
    {
      if(document.getElementsByName('CheckField[]')[x].checked === true)
      {
        MyEsito  = true;  
      }
    }
    return MyEsito;
  }
  
  /*---------------------------------------------------------------------------*/
  
  
  /*---------------------------------------------------------------------------*/
  /* CentraPopUp                                                               */
  /* Centra una finestra pop up                                                */
  /*---------------------------------------------------------------------------*/
  function CentraPopUp(URLPage,Larghezza,Altezza)
  {
    w = Larghezza;
    h = Altezza;
    l = Math.floor((screen.width-w)/2);
    t = Math.floor((screen.height-h)/2);
    /*--- window.open(URLPage,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l); ---*/
    window.open(URLPage,""," alwaysRaised=yes, width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
     
  }
  /*---------------------------------------------------------------------------*/
  
  
  /*---------------------------------------------------------------------------*/
  /* CentraPopUpS                                                               */
  /* Centra una finestra pop up                                                */
  /*---------------------------------------------------------------------------*/
  function CentraPopUpS(URLPage,Larghezza,Altezza)
  {
    w = Larghezza;
    h = Altezza;
    l = Math.floor((screen.width-w)/2);
    t = Math.floor((screen.height-h)/2);
    /*--- window.open(URLPage,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l); ---*/
    window.open(URLPage,"","scrollbars=1, alwaysRaised=yes, width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
     
  }
  /*---------------------------------------------------------------------------*/
  
  
  /*---------------------------------------------------------------------------*/
  /* JS_Confirm                                                                */
  /* Effettua il confirm di cuna rich                                          */
  /*---------------------------------------------------------------------------*/
  function JS_Confirm(Msg,MyPathPage)
  {
    if (confirm(Msg) === true) 
    {
      document.form1.action = MyPathPage;
      document.form1.targhet = "_self";
      document.form1.submit();
    } 
  }
  /*---------------------------------------------------------------------------*/




  /*---------------------------------------------------------------------------*/
  /* CheckChecked                                                              */ 
  /*---------------------------------------------------------------------------*/
  function CheckChecked(strIDCheck,IsChecked)
  {
    VetIDCheck =  strIDCheck.split(",");
    
    for(var x=0; x < VetIDCheck.length;x++)
    {
      for(var y=0; y < document.getElementsByName('CheckField[]').length;y++)
      {
        if(document.getElementsByName('CheckField[]')[y].value == VetIDCheck[x])
        {
          document.getElementsByName('CheckField[]')[y].checked = IsChecked;
        }
      }
    }
  }
  /*---------------------------------------------------------------------------*/


  /*---------------------------------------------------------------------------*/
  /* CheckUploadFile                                                           */
	/*---------------------------------------------------------------------------*/
  function CheckUploadFile(ElementName,NomePagina,MyParam)
  {
    if (document.getElementById(ElementName).value !== "")
    {
      MySubmit(NomePagina,MyParam);
    }
    else
    {
      alert("ATTENZIONE! Inserire il file da caricare.");
    }
  }
  /*---------------------------------------------------------------------------*/
  
  
  
  /*---------------------------------------------------------------------------*/
  /*---------------------------------------------------------------------------*/
  /*---------------------------------------------------------------------------*/
  
  /*---------------------------------------------------------------------------*/
  /* RedirectDaCombo                                                           */
  /*---------------------------------------------------------------------------*/
  function RedirectDaCombo(IDComboBox,LinkPage)    
  {
    IDCorr = document.getElementById(IDComboBox).value;
    window.location.href = LinkPage + IDCorr;
  }
  /*---------------------------------------------------------------------------*/  
  
  
  
  /*---------------------------------------------------------------------------*/
  /* CheckFormContatti                                                         */
  /*---------------------------------------------------------------------------*/
  function CheckFormContatti(MyForm) 
  {
    /*---   Regular Expression - Mail ---*/
    var RExpEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
   
   
    /*--- Caratteri Alfanumerici da minimo 1 max 30 ---*/
    var RExpCharMin1Max30  = /^([a-zA-Z0-9\_\*\-\+\!\?\,\:\;\.\xE0\xE8\xE9\xF9\xF2\xEC\x27]\s?){1,30}$/;

    /*--- Caratteri Alfanumerici da minimo 1 max 50 ---*/
    var RExpCharMin1Max50  = /^([a-zA-Z0-9\_\*\-\+\!\?\,\:\;\.\/\xE0\xE8\xE9\xF9\xF2\xEC\x27]\s?){1,50}$/;

    /*--- Caratteri Alfanumerici da minimo 1 max 150 ---*/
    var RExpCharMin1Max150  = /^([a-zA-Z0-9\_\*\-\+\!\?\,\:\;\.\/\xE0\xE8\xE9\xF9\xF2\xEC\x27]\s?){1,150}$/;

    /*--- Caratteri Alfanumerici  minimo 1 carattere ---*/
    var RExpCharMin1  =   /^([a-zA-Z0-9\_\*\-\+\!\?\,\:\;\.\xE0\xE8\xE9\xF9\xF2\xEC\x27]\s?){1,2000}$/;

    /*--- Caratteri Alfanumerici da minimo 1 max 30 ---*/
    var RExpTelefono  = /^([0-9\-\+\(\)\.]\s?){1,30}$/;

 
    /*--- controllo txt_cos_cognome ---*/
    if (!MyForm.txt_cos_cognome.value.match(RExpCharMin1Max30)) 
    {
      alert("Attenzione! Il campo 'Cognome' deve essere compreso tra 1 e 30 caratteri");
      MyForm.txt_cos_cognome.focus();
      return false;
    }
      
    /*--- controllo txtNome ---*/
    if (!MyForm.txt_cos_nome.value.match(RExpCharMin1Max30)) 
    {
      alert("Attenzione! Il campo 'Nome' deve essere compreso tra 1 e 30 caratteri");
      MyForm.txt_cos_nome.focus();
      return false;
    }
    
    

    /*--- telefono ---*/
    if (!MyForm.txt_cos_telefono.value.match(RExpTelefono)) 
    {
      alert("Attenzione! Il numero di telefono può contenere solo numeri.");
      MyForm.txt_cos_telefono.focus();
      return false;
    }  
    
    
    /*---------- CONTROLLO EMAIL ----------*/
    

    /*--- controllo txt_cos_email ---*/
    if (alltrim(MyForm.txt_cos_email.value) === "" || alltrim(MyForm.txt_cos_email.value) === "")
    {
      alert("Attenzione! Inserire Indirizzo Email.");
      MyForm.txt_cos_email.focus();
      return false;
    }  
      
    /*--- controllo txt_cos_email ---*/
    if (!MyForm.txt_cos_email.value.match(RExpEmail)) 
    {
      alert("Attenzione! Inserire un indirizzo Email valido.");
      MyForm.txt_cos_email.focus();
      return false;
    }
    
    /*--- controllo txt_cos_email_conf ---*/
    if (!MyForm.txt_cos_email_conf.value.match(RExpEmail)) 
    {
      alert("Attenzione! Inserire un indirizzo Email valido.");
      MyForm.txt_cos_email_conf.focus();
      return false;
    }
    
    
    /*--- Controllo che l'indirizzo eMail e la conferma siano uguali ---*/
    if (MyForm.txt_cos_email.value != MyForm.txt_cos_email_conf.value)
    {
      alert("Attenzione! La Conferma della Email deve essere uguale all'Email");
      MyForm.txt_cos_email_conf.focus();
      return false;
    }
       
       
    /*--- controllo txt_csm_Messaggio ---*/
    if (alltrim(MyForm.txt_csm_Messaggio.value) === "")
    {
      alert("Attenzione! Il campo 'Messaggio' non deve essere vuoto.");
      MyForm.txt_csm_Messaggio.focus();
      return false;
    }



    /*--- Controllo sualla privacy        ---*/
    if (!MyForm.check_cos_Privacy.checked)
    {
      alert("Attenzione, per poter proseguire è necessario autorizzare il trattamento dei propri dati personali.");
      MyForm.check_cos_Privacy.focus();
      return false;
    }

    
    return true;
  }
  /*---------------------------------------------------------------------------*/
  
  
  /*---------------------------------------------------------------------------*/
  /* CheckFormRicerca                                                        */
  /*---------------------------------------------------------------------------*/
  function CheckFormRicerca(MyForm) 
  {

    /*--- Caratteri Alfanumerici da minimo 1 max 30 ---*/
    var RExpCharMin1Max30  = /^([a-zA-Z0-9\xE0\xE8\xE9\xF9\xF2\xEC]\s?){1,30}$/;

    /*--- controllo txt_cos_email ---*/
    if (alltrim(MyForm.txt_Search.value) === "" || alltrim(MyForm.txt_Search.value) === "")
    {
      alert("Attenzione! Inserire un termine di ricerca.");
      MyForm.txt_Search.focus();
      return false;
    }  
    else
    {
      /*--- ccaratteri strani ---*/
      if (!MyForm.txt_Search.value.match(RExpCharMin1Max30)) 
      {
        alert("Attenzione! inserire solo caratteri alfanumerici");
        MyForm.txt_Search.focus();
        return false;
      }
    
    }    

 
    return true;
  }
  /*---------------------------------------------------------------------------*/

  
  
  /*---------------------------------------------------------------------------*/
  /* ShowHide                                                                  */
  /*---------------------------------------------------------------------------*/
  function ShowHide(i) 
  {
    if ((document.getElementById) && (document.getElementById(i))) {
      var obj = document.getElementById(i);
      obj.style.display = obj.style.display == 'none' ? 'block' : 'none';
    }
  }
  /*---------------------------------------------------------------------------*/
  
 
