Subversion Repositories cms

Rev

Rev 14 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<SCRIPT>
// ---------------------------------------------------------------------- #
// Copyright: (C) 2002 Leader.IT S.r.l. <http://leader.it>
// Authors: Guido Brugnara <gdo@leader.it>
//
// $Revision: 18 $
// ---------------------------------------------------------------------- #
</SCRIPT>
<PUBLIC:COMPONENT URN="www.leader.it/jscript/library/form/DATE" >
  <PUBLIC:PROPERTY NAME="Descrizione" />
  <PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="IsDATESet()" />
  <PUBLIC:ATTACH EVENT="onblur" ONEVENT="IsDATEFinal()" />
  <PUBLIC:ATTACH EVENT="onfocus" ONEVENT="ViewDescription()" />
  <PUBLIC:ATTACH EVENT="onmouseenter" ONEVENT="ViewDescription()" />
  <PUBLIC:ATTACH EVENT="onmouseleave" ONEVENT="DeleteDescription()" />
  <SCRIPT LANGUAGE="JScript">

  // provvede ad un baco riscontrato in IE5.5 per cui parseInt('04') == 0
  //
  function my_parseInt(val){
    var re = /^0+(\d+)/;
    if(re.test(val)){
      return parseInt(RegExp.$1);
    }else{
      return parseInt(val);
    }
  }

  function ViewDescription(){
    try {
      if(Descrizione == ''){
        window.status = "Campo "+id;
      }else{
        window.status = Descrizione;
      }
    }catch(e){
      window.status = "Campo "+id;
    };
  }
  function DeleteDescription(){
    window.status = "";
  }
  function IsDATEFinal(){
    DeleteDescription();
    if(readOnly){
      return;
    }
    // elimino blank all'inizio ed alla fine
    if(value==" "){value=""};
    if(value==""){
      return;
    }
    var D = new Date();
    var Anno=D.getFullYear();
    var Mese=D.getMonth()+1;
    var Giorno=D.getDate();
    var re = /^\/*$/; /**/
    if(re.test(value)){
      //ok data odierna
    }else{
      var re = /^(\d+)\/*$/; /**/
      if(re.test(value)){
        Giorno=my_parseInt(RegExp.$1);
      }else{    
        var re = /^(\d+)\/(\d+)\/*$/; /**/
        if(re.test(value)){
          Giorno=RegExp.$1;
          Mese=my_parseInt(RegExp.$2);
          Giorno=my_parseInt(Giorno);
        }else{
          var re = /^(\d+)\/(\d+)\/(\d+)$/ ;
          if(re.test(value)){
            Giorno=RegExp.$1;
            Mese=RegExp.$2;
            Anno=my_parseInt(RegExp.$3);
            Mese=my_parseInt(Mese);
            Giorno=my_parseInt(Giorno);
          }else{
                    focus();
            window.alert("Il formato della data non è corretto");
            event.returnValue = false;
            return false;          
          }
        }    
      } 
    }  
    if(Anno<100){
      if(Anno<49){
        Anno = Anno+2000;
      }else{
        Anno = Anno+1900;
      }
    }
    if(Mese > 12 || Mese < 1){
      focus();
      window.alert("Il mese non è corretto");
      event.returnValue = false;
      return false;    
    }
    if(Mese==2){
      var Bisestile = false;
      if(Anno % 4 == 0){
        Bisestile = true;
        if(Anno % 100 == 0 ){
          Bisestile = false;
          if(Anno % 400 == 0){
            Bisestile=true;
          }
        }
      }
      if(Bisestile){
        if(Giorno >29){
              focus();
          window.alert("Il mese di febbraio ha al massimo 29 giorni");
          event.returnValue = false;            
          return false;    
        }
      }else{
        if(Giorno > 28 || Giorno < 1){
          focus();
          window.alert("Il mese di febbraio ha al massimo 28 giorni");
          event.returnValue = false;            
          return false;    
        }      
      }
    }
    if(Giorno > 30 && (Mese == 4 || Mese == 6 || Mese == 9 || Mese == 11)){
      focus();
      window.alert("Il mese ha al massimo 30 giorni");
      event.returnValue = false;
      return false;          
    }
    if(Giorno>31){
      focus();
      window.alert("Il mese ha al massimo 31 giorni");
      event.returnValue = false;    
      return false;    
    }
    if(Mese<=9){
      Mese = "0"+Mese.toString();
    }
    if(Giorno<=9){
      Giorno = "0"+Giorno.toString();
    }
    value=Giorno+'/'+Mese+'/'+Anno;
  }
  
  // filtra i tasti durante immissione in campo DATA
  function IsDATESet(){
    with(event){
      //window.alert("Key ="+keyCode);
      //window.alert("offsetX="+offsetX+" Y="+offsetY);
      // filtro i caratteri ammessi
      if(keyCode<47 || keyCode>57){ 
        // se diverso da numero o . annullo il carattere digitato
        keyCode=0;
        return false;
      }
    }
  }
  </SCRIPT>
</PUBLIC:COMPONENT>