Subversion Repositories cms

Rev

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

Rev Author Line No. Line
14 pisoni 1
<SCRIPT>
2
// ---------------------------------------------------------------------- #
3
// Copyright: (C) 2002 Leader.IT S.r.l. <http://leader.it>
4
// Authors: Guido Brugnara <gdo@leader.it>
5
//
6
// $Revision: 18 $
7
// ---------------------------------------------------------------------- #
8
</SCRIPT>
9
<PUBLIC:COMPONENT URN="www.leader.it/jscript/library/form/DATE" >
10
  <PUBLIC:PROPERTY NAME="Descrizione" />
11
  <PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="IsDATESet()" />
12
  <PUBLIC:ATTACH EVENT="onblur" ONEVENT="IsDATEFinal()" />
13
  <PUBLIC:ATTACH EVENT="onfocus" ONEVENT="ViewDescription()" />
14
  <PUBLIC:ATTACH EVENT="onmouseenter" ONEVENT="ViewDescription()" />
15
  <PUBLIC:ATTACH EVENT="onmouseleave" ONEVENT="DeleteDescription()" />
16
  <SCRIPT LANGUAGE="JScript">
17
 
18
  // provvede ad un baco riscontrato in IE5.5 per cui parseInt('04') == 0
19
  //
20
  function my_parseInt(val){
21
    var re = /^0+(\d+)/;
22
    if(re.test(val)){
23
      return parseInt(RegExp.$1);
24
    }else{
25
      return parseInt(val);
26
    }
27
  }
28
 
29
  function ViewDescription(){
30
    try {
31
      if(Descrizione == ''){
32
        window.status = "Campo "+id;
33
      }else{
34
        window.status = Descrizione;
35
      }
36
    }catch(e){
37
      window.status = "Campo "+id;
38
    };
39
  }
40
  function DeleteDescription(){
41
    window.status = "";
42
  }
43
  function IsDATEFinal(){
44
    DeleteDescription();
45
    if(readOnly){
46
      return;
47
    }
48
    // elimino blank all'inizio ed alla fine
49
    if(value==" "){value=""};
50
    if(value==""){
51
      return;
52
    }
53
    var D = new Date();
54
    var Anno=D.getFullYear();
55
    var Mese=D.getMonth()+1;
56
    var Giorno=D.getDate();
57
    var re = /^\/*$/; /**/
58
    if(re.test(value)){
59
      //ok data odierna
60
    }else{
61
      var re = /^(\d+)\/*$/; /**/
62
      if(re.test(value)){
63
        Giorno=my_parseInt(RegExp.$1);
64
      }else{    
65
        var re = /^(\d+)\/(\d+)\/*$/; /**/
66
        if(re.test(value)){
67
          Giorno=RegExp.$1;
68
          Mese=my_parseInt(RegExp.$2);
69
          Giorno=my_parseInt(Giorno);
70
        }else{
71
          var re = /^(\d+)\/(\d+)\/(\d+)$/ ;
72
          if(re.test(value)){
73
            Giorno=RegExp.$1;
74
            Mese=RegExp.$2;
75
            Anno=my_parseInt(RegExp.$3);
76
            Mese=my_parseInt(Mese);
77
            Giorno=my_parseInt(Giorno);
78
          }else{
79
		    focus();
80
            window.alert("Il formato della data non è corretto");
81
            event.returnValue = false;
82
            return false;          
83
          }
84
        }    
85
      } 
86
    }  
87
    if(Anno<100){
88
      if(Anno<49){
89
        Anno = Anno+2000;
90
      }else{
91
        Anno = Anno+1900;
92
      }
93
    }
94
    if(Mese > 12 || Mese < 1){
95
      focus();
96
      window.alert("Il mese non è corretto");
97
      event.returnValue = false;
98
      return false;    
99
    }
100
    if(Mese==2){
101
      var Bisestile = false;
102
      if(Anno % 4 == 0){
103
        Bisestile = true;
104
        if(Anno % 100 == 0 ){
105
          Bisestile = false;
106
          if(Anno % 400 == 0){
107
            Bisestile=true;
108
          }
109
        }
110
      }
111
      if(Bisestile){
112
        if(Giorno >29){
113
  	      focus();
114
          window.alert("Il mese di febbraio ha al massimo 29 giorni");
115
          event.returnValue = false;            
116
          return false;    
117
        }
118
      }else{
119
        if(Giorno > 28 || Giorno < 1){
120
          focus();
121
          window.alert("Il mese di febbraio ha al massimo 28 giorni");
122
          event.returnValue = false;            
123
          return false;    
124
        }      
125
      }
126
    }
127
    if(Giorno > 30 && (Mese == 4 || Mese == 6 || Mese == 9 || Mese == 11)){
128
      focus();
129
      window.alert("Il mese ha al massimo 30 giorni");
130
      event.returnValue = false;
131
      return false;          
132
    }
133
    if(Giorno>31){
134
      focus();
135
      window.alert("Il mese ha al massimo 31 giorni");
136
      event.returnValue = false;    
137
      return false;    
138
    }
139
    if(Mese<=9){
140
      Mese = "0"+Mese.toString();
141
    }
142
    if(Giorno<=9){
143
      Giorno = "0"+Giorno.toString();
144
    }
145
    value=Giorno+'/'+Mese+'/'+Anno;
146
  }
147
 
148
  // filtra i tasti durante immissione in campo DATA
149
  function IsDATESet(){
150
    with(event){
151
      //window.alert("Key ="+keyCode);
152
      //window.alert("offsetX="+offsetX+" Y="+offsetY);
153
      // filtro i caratteri ammessi
154
      if(keyCode<47 || keyCode>57){ 
155
        // se diverso da numero o . annullo il carattere digitato
156
        keyCode=0;
157
        return false;
158
      }
159
    }
160
  }
161
  </SCRIPT>
162
</PUBLIC:COMPONENT>