user-friendlier date chosing in events
[plewww.git] / planetlab / events / calendar / CalendarPopup.js
1 // CONSTRUCTOR for the CalendarPopup Object
2 function CalendarPopup() {
3         var c;
4         if (arguments.length>0) {
5                 c = new PopupWindow(arguments[0]);
6                 }
7         else {
8                 c = new PopupWindow();
9                 c.setSize(150,175);
10                 }
11         c.offsetX = -152;
12         c.offsetY = 25;
13         c.autoHide();
14         // Calendar-specific properties
15         c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
16         c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
17         c.dayHeaders = new Array("S","M","T","W","T","F","S");
18         c.returnFunction = "CP_tmpReturnFunction";
19         c.returnMonthFunction = "CP_tmpReturnMonthFunction";
20         c.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
21         c.returnYearFunction = "CP_tmpReturnYearFunction";
22         c.weekStartDay = 0;
23         c.isShowYearNavigation = false;
24         c.displayType = "date";
25         c.disabledWeekDays = new Object();
26         c.disabledDatesExpression = "";
27         c.yearSelectStartOffset = 2;
28         c.currentDate = null;
29         c.todayText="Today";
30         c.cssPrefix="";
31         c.isShowNavigationDropdowns=false;
32         c.isShowYearNavigationInput=false;
33         window.CP_calendarObject = null;
34         window.CP_targetInput = null;
35         window.CP_dateFormat = "MM/dd/yyyy";
36         // Method mappings
37         c.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
38         c.setReturnFunction = CP_setReturnFunction;
39         c.setReturnMonthFunction = CP_setReturnMonthFunction;
40         c.setReturnQuarterFunction = CP_setReturnQuarterFunction;
41         c.setReturnYearFunction = CP_setReturnYearFunction;
42         c.setMonthNames = CP_setMonthNames;
43         c.setMonthAbbreviations = CP_setMonthAbbreviations;
44         c.setDayHeaders = CP_setDayHeaders;
45         c.setWeekStartDay = CP_setWeekStartDay;
46         c.setDisplayType = CP_setDisplayType;
47         c.setDisabledWeekDays = CP_setDisabledWeekDays;
48         c.addDisabledDates = CP_addDisabledDates;
49         c.setYearSelectStartOffset = CP_setYearSelectStartOffset;
50         c.setTodayText = CP_setTodayText;
51         c.showYearNavigation = CP_showYearNavigation;
52         c.showCalendar = CP_showCalendar;
53         c.hideCalendar = CP_hideCalendar;
54         c.getStyles = getCalendarStyles;
55         c.refreshCalendar = CP_refreshCalendar;
56         c.getCalendar = CP_getCalendar;
57         c.select = CP_select;
58         c.setCssPrefix = CP_setCssPrefix;
59         c.showNavigationDropdowns = CP_showNavigationDropdowns;
60         c.showYearNavigationInput = CP_showYearNavigationInput;
61         c.copyMonthNamesToWindow();
62         // Return the object
63         return c;
64         }
65 function CP_copyMonthNamesToWindow() {
66         // Copy these values over to the date.js 
67         if (typeof(window.MONTH_NAMES)!="undefined" && window.MONTH_NAMES!=null) {
68                 window.MONTH_NAMES = new Array();
69                 for (var i=0; i<this.monthNames.length; i++) {
70                         window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthNames[i];
71                 }
72                 for (var i=0; i<this.monthAbbreviations.length; i++) {
73                         window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthAbbreviations[i];
74                 }
75         }
76 }
77 // Temporary default functions to be called when items clicked, so no error is thrown
78 function CP_tmpReturnFunction(y,m,d) { 
79         if (window.CP_targetInput!=null) {
80                 var dt = new Date(y,m-1,d,0,0,0);
81                 if (window.CP_calendarObject!=null) { window.CP_calendarObject.copyMonthNamesToWindow(); }
82                 window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
83                 }
84         else {
85                 alert('Use setReturnFunction() to define which function will get the clicked results!'); 
86                 }
87         }
88 function CP_tmpReturnMonthFunction(y,m) { 
89         alert('Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , month='+m); 
90         }
91 function CP_tmpReturnQuarterFunction(y,q) { 
92         alert('Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , quarter='+q); 
93         }
94 function CP_tmpReturnYearFunction(y) { 
95         alert('Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year='+y); 
96         }
97
98 // Set the name of the functions to call to get the clicked item
99 function CP_setReturnFunction(name) { this.returnFunction = name; }
100 function CP_setReturnMonthFunction(name) { this.returnMonthFunction = name; }
101 function CP_setReturnQuarterFunction(name) { this.returnQuarterFunction = name; }
102 function CP_setReturnYearFunction(name) { this.returnYearFunction = name; }
103
104 // Over-ride the built-in month names
105 function CP_setMonthNames() {
106         for (var i=0; i<arguments.length; i++) { this.monthNames[i] = arguments[i]; }
107         this.copyMonthNamesToWindow();
108         }
109
110 // Over-ride the built-in month abbreviations
111 function CP_setMonthAbbreviations() {
112         for (var i=0; i<arguments.length; i++) { this.monthAbbreviations[i] = arguments[i]; }
113         this.copyMonthNamesToWindow();
114         }
115
116 // Over-ride the built-in column headers for each day
117 function CP_setDayHeaders() {
118         for (var i=0; i<arguments.length; i++) { this.dayHeaders[i] = arguments[i]; }
119         }
120
121 // Set the day of the week (0-7) that the calendar display starts on
122 // This is for countries other than the US whose calendar displays start on Monday(1), for example
123 function CP_setWeekStartDay(day) { this.weekStartDay = day; }
124
125 // Show next/last year navigation links
126 function CP_showYearNavigation() { this.isShowYearNavigation = (arguments.length>0)?arguments[0]:true; }
127
128 // Which type of calendar to display
129 function CP_setDisplayType(type) {
130         if (type!="date"&&type!="week-end"&&type!="month"&&type!="quarter"&&type!="year") { alert("Invalid display type! Must be one of: date,week-end,month,quarter,year"); return false; }
131         this.displayType=type;
132         }
133
134 // How many years back to start by default for year display
135 function CP_setYearSelectStartOffset(num) { this.yearSelectStartOffset=num; }
136
137 // Set which weekdays should not be clickable
138 function CP_setDisabledWeekDays() {
139         this.disabledWeekDays = new Object();
140         for (var i=0; i<arguments.length; i++) { this.disabledWeekDays[arguments[i]] = true; }
141         }
142         
143 // Disable individual dates or ranges
144 // Builds an internal logical test which is run via eval() for efficiency
145 function CP_addDisabledDates(start, end) {
146         if (arguments.length==1) { end=start; }
147         if (start==null && end==null) { return; }
148         if (this.disabledDatesExpression!="") { this.disabledDatesExpression+= "||"; }
149         if (start!=null) { start = parseDate(start); start=""+start.getFullYear()+LZ(start.getMonth()+1)+LZ(start.getDate());}
150         if (end!=null) { end=parseDate(end); end=""+end.getFullYear()+LZ(end.getMonth()+1)+LZ(end.getDate());}
151         if (start==null) { this.disabledDatesExpression+="(ds<="+end+")"; }
152         else if (end  ==null) { this.disabledDatesExpression+="(ds>="+start+")"; }
153         else { this.disabledDatesExpression+="(ds>="+start+"&&ds<="+end+")"; }
154         }
155         
156 // Set the text to use for the "Today" link
157 function CP_setTodayText(text) {
158         this.todayText = text;
159         }
160
161 // Set the prefix to be added to all CSS classes when writing output
162 function CP_setCssPrefix(val) { 
163         this.cssPrefix = val; 
164         }
165
166 // Show the navigation as an dropdowns that can be manually changed
167 function CP_showNavigationDropdowns() { this.isShowNavigationDropdowns = (arguments.length>0)?arguments[0]:true; }
168
169 // Show the year navigation as an input box that can be manually changed
170 function CP_showYearNavigationInput() { this.isShowYearNavigationInput = (arguments.length>0)?arguments[0]:true; }
171
172 // Hide a calendar object
173 function CP_hideCalendar() {
174         if (arguments.length > 0) { window.popupWindowObjects[arguments[0]].hidePopup(); }
175         else { this.hidePopup(); }
176         }
177
178 // Refresh the contents of the calendar display
179 function CP_refreshCalendar(index) {
180         var calObject = window.popupWindowObjects[index];
181         if (arguments.length>1) { 
182                 calObject.populate(calObject.getCalendar(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
183                 }
184         else {
185                 calObject.populate(calObject.getCalendar());
186                 }
187         calObject.refresh();
188         }
189
190 // Populate the calendar and display it
191 function CP_showCalendar(anchorname) {
192         if (arguments.length>1) {
193                 if (arguments[1]==null||arguments[1]=="") {
194                         this.currentDate=new Date();
195                         }
196                 else {
197                         this.currentDate=new Date(parseDate(arguments[1]));
198                         }
199                 }
200         this.populate(this.getCalendar());
201         this.showPopup(anchorname);
202         }
203
204 // Simple method to interface popup calendar with a text-entry box
205 function CP_select(inputobj, linkname, format) {
206         var selectedDate=(arguments.length>3)?arguments[3]:null;
207         if (!window.getDateFromFormat) {
208                 alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
209                 return;
210                 }
211         if (this.displayType!="date"&&this.displayType!="week-end") {
212                 alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
213                 return;
214                 }
215         if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") { 
216                 alert("calendar.select: Input object passed is not a valid form input object"); 
217                 window.CP_targetInput=null;
218                 return;
219                 }
220         if (inputobj.disabled) { return; } // Can't use calendar input on disabled form input!
221         window.CP_targetInput = inputobj;
222         window.CP_calendarObject = this;
223         this.currentDate=null;
224         var time=0;
225         if (selectedDate!=null) {
226                 time = getDateFromFormat(selectedDate,format)
227                 }
228         else if (inputobj.value!="") {
229                 time = getDateFromFormat(inputobj.value,format);
230                 }
231         if (selectedDate!=null || inputobj.value!="") {
232                 if (time==0) { this.currentDate=null; }
233                 else { this.currentDate=new Date(time); }
234                 }
235         window.CP_dateFormat = format;
236         this.showCalendar(linkname);
237         }
238         
239 // Get style block needed to display the calendar correctly
240 function getCalendarStyles() {
241         var result = "";
242         var p = "";
243         if (this!=null && typeof(this.cssPrefix)!="undefined" && this.cssPrefix!=null && this.cssPrefix!="") { p=this.cssPrefix; }
244         result += "<STYLE>\n";
245         result += "."+p+"cpYearNavigation,."+p+"cpMonthNavigation { background-color:#C0C0C0; text-align:center; vertical-align:center; text-decoration:none; color:#000000; font-weight:bold; }\n";
246         result += "."+p+"cpDayColumnHeader, ."+p+"cpYearNavigation,."+p+"cpMonthNavigation,."+p+"cpCurrentMonthDate,."+p+"cpCurrentMonthDateDisabled,."+p+"cpOtherMonthDate,."+p+"cpOtherMonthDateDisabled,."+p+"cpCurrentDate,."+p+"cpCurrentDateDisabled,."+p+"cpTodayText,."+p+"cpTodayTextDisabled,."+p+"cpText { font-family:arial; font-size:8pt; }\n";
247         result += "TD."+p+"cpDayColumnHeader { text-align:right; border:solid thin #C0C0C0;border-width:0px 0px 1px 0px; }\n";
248         result += "."+p+"cpCurrentMonthDate, ."+p+"cpOtherMonthDate, ."+p+"cpCurrentDate  { text-align:right; text-decoration:none; }\n";
249         result += "."+p+"cpCurrentMonthDateDisabled, ."+p+"cpOtherMonthDateDisabled, ."+p+"cpCurrentDateDisabled { color:#D0D0D0; text-align:right; text-decoration:line-through; }\n";
250         result += "."+p+"cpCurrentMonthDate, .cpCurrentDate { color:#000000; }\n";
251         result += "."+p+"cpOtherMonthDate { color:#808080; }\n";
252         result += "TD."+p+"cpCurrentDate { color:white; background-color: #C0C0C0; border-width:1px; border:solid thin #800000; }\n";
253         result += "TD."+p+"cpCurrentDateDisabled { border-width:1px; border:solid thin #FFAAAA; }\n";
254         result += "TD."+p+"cpTodayText, TD."+p+"cpTodayTextDisabled { border:solid thin #C0C0C0; border-width:1px 0px 0px 0px;}\n";
255         result += "A."+p+"cpTodayText, SPAN."+p+"cpTodayTextDisabled { height:20px; }\n";
256         result += "A."+p+"cpTodayText { color:black; }\n";
257         result += "."+p+"cpTodayTextDisabled { color:#D0D0D0; }\n";
258         result += "."+p+"cpBorder { border:solid thin #808080; }\n";
259         result += "</STYLE>\n";
260         return result;
261         }
262
263 // Return a string containing all the calendar code to be displayed
264 function CP_getCalendar() {
265         var now = new Date();
266         // Reference to window
267         if (this.type == "WINDOW") { var windowref = "window.opener."; }
268         else { var windowref = ""; }
269         var result = "";
270         // If POPUP, write entire HTML document
271         if (this.type == "WINDOW") {
272                 result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
273                 result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
274                 }
275         else {
276                 result += '<TABLE CLASS="'+this.cssPrefix+'cpBorder" WIDTH=144 BORDER=1 BORDERWIDTH=1 CELLSPACING=0 CELLPADDING=1>\n';
277                 result += '<TR><TD ALIGN=CENTER>\n';
278                 result += '<CENTER>\n';
279                 }
280         // Code for DATE display (default)
281         // -------------------------------
282         if (this.displayType=="date" || this.displayType=="week-end") {
283                 if (this.currentDate==null) { this.currentDate = now; }
284                 if (arguments.length > 0) { var month = arguments[0]; }
285                         else { var month = this.currentDate.getMonth()+1; }
286                 if (arguments.length > 1 && arguments[1]>0 && arguments[1]-0==arguments[1]) { var year = arguments[1]; }
287                         else { var year = this.currentDate.getFullYear(); }
288                 var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
289                 if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
290                         daysinmonth[2] = 29;
291                         }
292                 var current_month = new Date(year,month-1,1);
293                 var display_year = year;
294                 var display_month = month;
295                 var display_date = 1;
296                 var weekday= current_month.getDay();
297                 var offset = 0;
298                 
299                 offset = (weekday >= this.weekStartDay) ? weekday-this.weekStartDay : 7-this.weekStartDay+weekday ;
300                 if (offset > 0) {
301                         display_month--;
302                         if (display_month < 1) { display_month = 12; display_year--; }
303                         display_date = daysinmonth[display_month]-offset+1;
304                         }
305                 var next_month = month+1;
306                 var next_month_year = year;
307                 if (next_month > 12) { next_month=1; next_month_year++; }
308                 var last_month = month-1;
309                 var last_month_year = year;
310                 if (last_month < 1) { last_month=12; last_month_year--; }
311                 var date_class;
312                 if (this.type!="WINDOW") {
313                         result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
314                         }
315                 result += '<TR>\n';
316                 var refresh = windowref+'CP_refreshCalendar';
317                 var refreshLink = 'javascript:' + refresh;
318                 if (this.isShowNavigationDropdowns) {
319                         result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="78" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpMonthNavigation" name="cpMonth" onChange="'+refresh+'('+this.index+',this.options[this.selectedIndex].value-0,'+(year-0)+');">';
320                         for( var monthCounter=1; monthCounter<=12; monthCounter++ ) {
321                                 var selected = (monthCounter==month) ? 'SELECTED' : '';
322                                 result += '<option value="'+monthCounter+'" '+selected+'>'+this.monthNames[monthCounter-1]+'</option>';
323                                 }
324                         result += '</select></TD>';
325                         result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
326
327                         result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="56" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpYearNavigation" name="cpYear" onChange="'+refresh+'('+this.index+','+month+',this.options[this.selectedIndex].value-0);">';
328                         for( var yearCounter=year-this.yearSelectStartOffset; yearCounter<=year+this.yearSelectStartOffset; yearCounter++ ) {
329                                 var selected = (yearCounter==year) ? 'SELECTED' : '';
330                                 result += '<option value="'+yearCounter+'" '+selected+'>'+yearCounter+'</option>';
331                                 }
332                         result += '</select></TD>';
333                         }
334                 else {
335                         if (this.isShowYearNavigation) {
336                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');">&lt;</A></TD>';
337                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="58"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+'</SPAN></TD>';
338                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">&gt;</A></TD>';
339                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
340
341                                 result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year-1)+');">&lt;</A></TD>';
342                                 if (this.isShowYearNavigationInput) {
343                                         result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><INPUT NAME="cpYear" CLASS="'+this.cssPrefix+'cpYearNavigation" SIZE="4" MAXLENGTH="4" VALUE="'+year+'" onBlur="'+refresh+'('+this.index+','+month+',this.value-0);"></TD>';
344                                         }
345                                 else {
346                                         result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><SPAN CLASS="'+this.cssPrefix+'cpYearNavigation">'+year+'</SPAN></TD>';
347                                         }
348                                 result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year+1)+');">&gt;</A></TD>';
349                                 }
350                         else {
351                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');">&lt;&lt;</A></TD>\n';
352                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="100"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+' '+year+'</SPAN></TD>\n';
353                                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">&gt;&gt;</A></TD>\n';
354                                 }
355                         }
356                 result += '</TR></TABLE>\n';
357                 result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=0 CELLPADDING=1 ALIGN=CENTER>\n';
358                 result += '<TR>\n';
359                 for (var j=0; j<7; j++) {
360
361                         result += '<TD CLASS="'+this.cssPrefix+'cpDayColumnHeader" WIDTH="14%"><SPAN CLASS="'+this.cssPrefix+'cpDayColumnHeader">'+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
362                         }
363                 result += '</TR>\n';
364                 for (var row=1; row<=6; row++) {
365                         result += '<TR>\n';
366                         for (var col=1; col<=7; col++) {
367                                 var disabled=false;
368                                 if (this.disabledDatesExpression!="") {
369                                         var ds=""+display_year+LZ(display_month)+LZ(display_date);
370                                         eval("disabled=("+this.disabledDatesExpression+")");
371                                         }
372                                 var dateClass = "";
373                                 if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
374                                         dateClass = "cpCurrentDate";
375                                         }
376                                 else if (display_month == month) {
377                                         dateClass = "cpCurrentMonthDate";
378                                         }
379                                 else {
380                                         dateClass = "cpOtherMonthDate";
381                                         }
382                                 if (disabled || this.disabledWeekDays[col-1]) {
383                                         result += '     <TD CLASS="'+this.cssPrefix+dateClass+'"><SPAN CLASS="'+this.cssPrefix+dateClass+'Disabled">'+display_date+'</SPAN></TD>\n';
384                                         }
385                                 else {
386                                         var selected_date = display_date;
387                                         var selected_month = display_month;
388                                         var selected_year = display_year;
389                                         if (this.displayType=="week-end") {
390                                                 var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
391                                                 d.setDate(d.getDate() + (7-col));
392                                                 selected_year = d.getYear();
393                                                 if (selected_year < 1000) { selected_year += 1900; }
394                                                 selected_month = d.getMonth()+1;
395                                                 selected_date = d.getDate();
396                                                 }
397                                         result += '     <TD CLASS="'+this.cssPrefix+dateClass+'"><A HREF="javascript:'+windowref+this.returnFunction+'('+selected_year+','+selected_month+','+selected_date+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+this.cssPrefix+dateClass+'">'+display_date+'</A></TD>\n';
398                                         }
399                                 display_date++;
400                                 if (display_date > daysinmonth[display_month]) {
401                                         display_date=1;
402                                         display_month++;
403                                         }
404                                 if (display_month > 12) {
405                                         display_month=1;
406                                         display_year++;
407                                         }
408                                 }
409                         result += '</TR>';
410                         }
411                 var current_weekday = now.getDay() - this.weekStartDay;
412                 if (current_weekday < 0) {
413                         current_weekday += 7;
414                         }
415                 result += '<TR>\n';
416                 result += '     <TD COLSPAN=7 ALIGN=CENTER CLASS="'+this.cssPrefix+'cpTodayText">\n';
417                 if (this.disabledDatesExpression!="") {
418                         var ds=""+now.getFullYear()+LZ(now.getMonth()+1)+LZ(now.getDate());
419                         eval("disabled=("+this.disabledDatesExpression+")");
420                         }
421                 if (disabled || this.disabledWeekDays[current_weekday+1]) {
422                         result += '             <SPAN CLASS="'+this.cssPrefix+'cpTodayTextDisabled">'+this.todayText+'</SPAN>\n';
423                         }
424                 else {
425                         result += '             <A CLASS="'+this.cssPrefix+'cpTodayText" HREF="javascript:'+windowref+this.returnFunction+'(\''+now.getFullYear()+'\',\''+(now.getMonth()+1)+'\',\''+now.getDate()+'\');'+windowref+'CP_hideCalendar(\''+this.index+'\');">'+this.todayText+'</A>\n';
426                         }
427                 result += '             <BR>\n';
428                 result += '     </TD></TR></TABLE></CENTER></TD></TR></TABLE>\n';
429         }
430
431         // Code common for MONTH, QUARTER, YEAR
432         // ------------------------------------
433         if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
434                 if (arguments.length > 0) { var year = arguments[0]; }
435                 else { 
436                         if (this.displayType=="year") { var year = now.getFullYear()-this.yearSelectStartOffset; }
437                         else { var year = now.getFullYear(); }
438                         }
439                 if (this.displayType!="year" && this.isShowYearNavigation) {
440                         result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
441                         result += '<TR>\n';
442                         result += '     <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-1)+');">&lt;&lt;</A></TD>\n';
443                         result += '     <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="100">'+year+'</TD>\n';
444                         result += '     <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+1)+');">&gt;&gt;</A></TD>\n';
445                         result += '</TR></TABLE>\n';
446                         }
447                 }
448                 
449         // Code for MONTH display 
450         // ----------------------
451         if (this.displayType=="month") {
452                 // If POPUP, write entire HTML document
453                 result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
454                 for (var i=0; i<4; i++) {
455                         result += '<TR>';
456                         for (var j=0; j<3; j++) {
457                                 var monthindex = ((i*3)+j);
458                                 result += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnMonthFunction+'('+year+','+(monthindex+1)+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+this.monthAbbreviations[monthindex]+'</A></TD>';
459                                 }
460                         result += '</TR>';
461                         }
462                 result += '</TABLE></CENTER></TD></TR></TABLE>\n';
463                 }
464         
465         // Code for QUARTER display
466         // ------------------------
467         if (this.displayType=="quarter") {
468                 result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
469                 for (var i=0; i<2; i++) {
470                         result += '<TR>';
471                         for (var j=0; j<2; j++) {
472                                 var quarter = ((i*2)+j+1);
473                                 result += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnQuarterFunction+'('+year+','+quarter+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">Q'+quarter+'</A><BR><BR></TD>';
474                                 }
475                         result += '</TR>';
476                         }
477                 result += '</TABLE></CENTER></TD></TR></TABLE>\n';
478                 }
479
480         // Code for YEAR display
481         // ---------------------
482         if (this.displayType=="year") {
483                 var yearColumnSize = 4;
484                 result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
485                 result += '<TR>\n';
486                 result += '     <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');">&lt;&lt;</A></TD>\n';
487                 result += '     <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">&gt;&gt;</A></TD>\n';
488                 result += '</TR></TABLE>\n';
489                 result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
490                 for (var i=0; i<yearColumnSize; i++) {
491                         for (var j=0; j<2; j++) {
492                                 var currentyear = year+(j*yearColumnSize)+i;
493                                 result += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnYearFunction+'('+currentyear+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+currentyear+'</A></TD>';
494                                 }
495                         result += '</TR>';
496                         }
497                 result += '</TABLE></CENTER></TD></TR></TABLE>\n';
498                 }
499         // Common
500         if (this.type == "WINDOW") {
501                 result += "</BODY></HTML>\n";
502                 }
503         return result;
504         }