1 // Title: Tigra Calendar
2 // Description: See the demo at url
3 // URL: http://www.softcomplex.com/products/tigra_calendar/
4 // Version: 3.1 (European date format)
5 // Date: 08-08-2002 (mm-dd-yyyy)
6 // Feedback: feedback@softcomplex.com (specify product title in the subject)
7 // Note: Permission given to use this script in ANY kind of applications if
8 // header lines are left unchanged.
9 // Note: Script consists of two files: calendar?.js and calendar.html
10 // About us: Our company provides offshore IT consulting services.
11 // Contact us at sales@softcomplex.com if you have any programming task you
12 // want to be handled by professionals. Our typical hourly rate is $20.
14 // modified by Martin Hoerning, mh@skyrix.com, 2002-12-05
15 // 2003-01-23 added date format support (Martin Hoerning)
17 // if two digit year input dates after this year considered 20 century.
18 var NUM_CENTYEAR = 30;
19 // are year scrolling buttons required by default
20 var BUL_YEARSCROLL = true;
21 var DEF_CALPAGE = 'skycalendar.html';
24 var RE_NUM = /^\-?\d+$/;
25 var dateFormat = "yyyy-mm-dd";
27 function skycalendar(obj_target) {
29 this.gen_date = cal_gen_date1;
30 this.gen_tsmp = cal_gen_tsmp1;
31 this.prs_date = cal_prs_date1;
32 this.prs_tsmp = cal_prs_tsmp1;
33 this.popup = cal_popup1;
34 this.setCalendarPage = cal_setcalpage1;
35 this.setDateFormat = cal_setdateformat1;
37 // validate input parameters
39 return cal_error("Error calling the calendar: no target control specified");
40 if (obj_target.value == null)
41 return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
42 this.target = obj_target;
43 this.year_scroll = BUL_YEARSCROLL;
44 this.calpage = DEF_CALPAGE;
46 // register in global collections
47 this.id = calendars.length;
48 calendars[this.id] = this;
51 function cal_setcalpage1(str_page) {
52 this.calpage = str_page;
55 function cal_setdateformat1(str_dateformat) {
56 this.dateFormat = str_dateformat;
59 function cal_popup1(str_datetime) {
60 this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
61 if (!this.dt_current) return;
63 var obj_calwindow = window.open(
64 this.calpage+'?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
65 'Calendar', 'width=200,height=190'+
66 ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
68 obj_calwindow.opener = window;
69 obj_calwindow.focus();
72 // timestamp generating function
73 function cal_gen_tsmp1(dt_datetime) {
74 return this.gen_date(dt_datetime);
77 // date generating function
78 function cal_gen_date1(dt_datetime) {
79 var out = this.dateFormat;
81 if (out.indexOf("yyyy") != 1) {
82 t = out.split("yyyy");
83 out = t.join(dt_datetime.getFullYear());
86 return cal_error("Missing year-part 'yyyy' in format: '"+this.dateFormat);
88 if (out.indexOf("mm") != 1) {
90 out = t.join((dt_datetime.getMonth() < 9 ? '0' : '')+
91 (dt_datetime.getMonth()+1));
94 return cal_error("Missing month-part 'mm' in format: '"+this.dateFormat);
96 if (out.indexOf("dd") != 1) {
98 out = t.join((dt_datetime.getDate() < 10 ? '0' : '')+
99 dt_datetime.getDate());
102 return cal_error("Missing day-part 'dd' in format: '"+this.dateFormat);
108 // timestamp parsing function
109 function cal_prs_tsmp1(str_datetime) {
110 // if no parameter specified return current timestamp
114 // if positive integer treat as milliseconds from epoch
115 if (RE_NUM.exec(str_datetime))
116 return new Date(str_datetime);
118 return this.prs_date(str_datetime);
121 // date parsing function
122 function cal_prs_date1(str_date) {
128 if (str_date.length != this.dateFormat.length) {
129 return cal_error ("Invalid date format: '"+str_date+
130 "'.\nFormat accepted is '"+this.dateFormat+"'.");
133 if ((idx = this.dateFormat.indexOf("yyyy")) != 1) {
134 year = str_date.substring(idx, idx+4);
137 return cal_error("Missing year-part 'yyyy' in format: '"+this.dateFormat);
139 if ((idx = this.dateFormat.indexOf("mm")) != 1) {
140 month = str_date.substring(idx, idx+2);
143 return cal_error("Missing month-part 'mm' in format: '"+this.dateFormat);
145 if ((idx = this.dateFormat.indexOf("dd")) != 1) {
146 day = str_date.substring(idx, idx+2);
149 return cal_error("Missing day-part 'dd' in format: '"+this.dateFormat);
152 if (!day) return cal_error("Invalid date format: '"+str_date+
153 "'.\nNo day of month value can be found.");
154 if (!RE_NUM.exec(day))
155 return cal_error("Invalid day of month value: '"+day+
156 "'.\nAllowed values are unsigned integers.");
158 if (!month) return cal_error("Invalid date format: '"+str_date+
159 "'.\nNo month of year value can be found.");
160 if (!RE_NUM.exec(month))
161 return cal_error("Invalid month of year value: '"+month+
162 "'.\nAllowed values are unsigned integers.");
164 if (!year) return cal_error("Invalid date format: '"+str_date+
165 "'.\nNo year value can be found.");
166 if (!RE_NUM.exec(year))
167 return cal_error("Invalid year value: '"+year+
168 "'.\nAllowed values are unsigned integers.");
171 var dt_date = new Date();
173 if (month < 1 || month > 12)
174 return cal_error("Invalid month value: '"+month+
175 "'.\nAllowed range is 01-12.");
176 dt_date.setMonth(month-1);
177 if (year < 100) year = Number(year)+(year < NUM_CENTYEAR ? 2000 : 1900);
178 dt_date.setFullYear(year);
179 var dt_numdays = new Date(year, month, 0);
180 dt_date.setDate(day);
181 if (dt_date.getMonth() != (month-1))
182 return cal_error("Invalid day of month value: '"+day+
183 "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");
187 function cal_error(str_message) {