/[health_html]/js/DateSelector.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /js/DateSelector.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Sep 19 12:23:57 2001 UTC (22 years, 7 months ago) by ravilov
Branch: MAIN
Changes since 1.1: +5 -4 lines
File MIME type: application/javascript
Added thefilez/med/ (PLIVAmed site). Other major changes...

1 ravilov 1.1 function DateSelector(form, date, before, after) {
2     this.sDay = form.day || form.elements[0] || null;
3     this.sMonth = form.month || form.elements[1] || null;
4     this.sYear = form.year || form.elements[2] || null;
5     this.yBefore = before || 0;
6     this.yAfter = after || 0;
7     this.BaseDate = date || new Date();
8     this.Rebuild = function(d, m, y) {
9     var i, sel;
10     // build day selector
11     if (this.sDay != null) {
12     sel = d || this.sDay.selectedIndex;
13     if (sel < 0) sel = this.BaseDate.getDate() - 1;
14     for (i = 0; i < this.sDay.options.length; i++)
15     this.sDay.options[i] = null;
16     for (i = 0; i < this.nDays; i++)
17     this.sDay.options[i] = new Option(String(i + 1), String(i + 1));
18     // this.sDay.options.length = this.nDays;
19     this.sDay.selectedIndex = Math.min(sel, this.sDay.options.length - 1);
20     }
21     // build month selector
22     if (this.sMonth != null) {
23     sel = m || this.sMonth.selectedIndex;
24 ravilov 1.2 alert(sel);
25 ravilov 1.1 if (sel < 0) sel = this.BaseDate.getMonth();
26     for (i = 0; i < this.sMonth.options.length; i++)
27     this.sMonth.options[i] = null;
28     for (i = 0; i < 12; i++) {
29     var mon = null;
30     if (this.Months) mon = this.Months[i];
31     mon = mon || String(i + 1);
32     this.sMonth.options[i] = new Option(mon, String(i + 1));
33     }
34     // this.sMonth.options.length = 12;
35     this.sMonth.selectedIndex = sel;
36     }
37     // build year selector
38     if (this.sYear != null) {
39     sel = y || this.sYear.selectedIndex;
40     if (sel < 0) sel = this.yBefore;
41     var y = this.BaseDate.getYear();
42     if (y < 1900) y += 1900;
43     for (i = 0; i < this.sYear.options.length; i++)
44     this.sYear.options[i] = null;
45     var j = 0;
46     for (i = y - this.yBefore; i <= y + this.yAfter; i++)
47     this.sYear.options[j++] = new Option(String(i), String(i));
48     // this.sYear.options.length = this.yBefore + 1 + this.yAfter;
49     this.sYear.selectedIndex = sel;
50     }
51     }
52     this.Check = function(d, m, y) {
53     var n = new Array(31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
54 ravilov 1.2 if (!m) m = (this.sMonth != null && this.sMonth.options.selectedIndex >= 0) ?
55     parseInt(this.sMonth.options[this.sMonth.selectedIndex].value) : this.BaseDate.getMonth();
56     alert(m);
57     if (!y) y = (this.sYear != null && this.sYear.options.selectedIndex >= 0) ?
58 ravilov 1.1 parseInt(this.sYear.options[this.sYear.selectedIndex].text) : this.BaseDate.getYear();
59     if (y < 1900) y += 1900;
60     n[1] = ((y % 4 == 0) && (y % 100 != 0)) ? 29 : 28;
61     this.nDays = n[m - 1];
62     }
63     this.Reset = function() {
64     var d = this.BaseDate.getDate() - 1;
65     var m = this.BaseDate.getMonth();
66     var y = this.yBefore;
67     this.Check(d, m, y);
68     this.Rebuild(d, m, y);
69     }
70     this.Today = function() {
71     var t = new Date();
72     var d = t.getDate() - 1;
73     var m = t.getMonth();
74     var y = this.yBefore;
75     this.Check(d, m, y);
76     this.Rebuild(d, m, y);
77     }
78     this.nDays = null;
79     this.Reset();
80     this.Rebuild();
81     return this;
82     }

  ViewVC Help
Powered by ViewVC 1.1.26