home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / CalendarPopup.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  31.7 KB  |  689 lines

  1. // ===================================================================
  2. // Author: Matt Kruse <matt@mattkruse.com>
  3. // WWW: http://www.mattkruse.com/
  4. //
  5. // NOTICE: You may use this code for any purpose, commercial or
  6. // private, without any further permission from the author. You may
  7. // remove this notice from your final code if you wish, however it is
  8. // appreciated by the author if at least my web site address is kept.
  9. //
  10. // You may *NOT* re-distribute this code in any way except through its
  11. // use. That means, you can include it in your product, or your web
  12. // site, or any other form where the code is actually being used. You
  13. // may not put the plain javascript up on your site for download or
  14. // include it in your javascript libraries for download. 
  15. // If you wish to share this code with others, please just point them
  16. // to the URL instead.
  17. // Please DO NOT link directly to my .js files from your site. Copy
  18. // the files to your server and use them there. Thank you.
  19. // ===================================================================
  20.  
  21. // HISTORY
  22. // ------------------------------------------------------------------
  23. // March 24, 2004: Fixed bug - when month name and abbreviations were
  24. //      changed, date format still used original values.
  25. // January 26, 2004: Added support for drop-down month and year
  26. //      navigation (Thanks to Chris Reid for the idea)
  27. // September 22, 2003: Fixed a minor problem in YEAR calendar with
  28. //      CSS prefix.
  29. // August 19, 2003: Renamed the function to get styles, and made it
  30. //      work correctly without an object reference
  31. // August 18, 2003: Changed showYearNavigation and 
  32. //      showYearNavigationInput to optionally take an argument of
  33. //      true or false
  34. // July 31, 2003: Added text input option for year navigation.
  35. //      Added a per-calendar CSS prefix option to optionally use 
  36. //      different styles for different calendars.
  37. // July 29, 2003: Fixed bug causing the Today link to be clickable 
  38. //      even though today falls in a disabled date range.
  39. //      Changed formatting to use pure CSS, allowing greater control
  40. //      over look-and-feel options.
  41. // June 11, 2003: Fixed bug causing the Today link to be unselectable
  42. //      under certain cases when some days of week are disabled
  43. // March 14, 2003: Added ability to disable individual dates or date
  44. //      ranges, display as light gray and strike-through
  45. // March 14, 2003: Removed dependency on graypixel.gif and instead 
  46. ///     use table border coloring
  47. // March 12, 2003: Modified showCalendar() function to allow optional
  48. //      start-date parameter
  49. // March 11, 2003: Modified select() function to allow optional
  50. //      start-date parameter
  51. /* 
  52. DESCRIPTION: This object implements a popup calendar to allow the user to
  53. select a date, month, quarter, or year.
  54.  
  55. COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
  56. positioning errors - usually with Window positioning - occur on the 
  57. Macintosh platform.
  58. The calendar can be modified to work for any location in the world by 
  59. changing which weekday is displayed as the first column, changing the month
  60. names, and changing the column headers for each day.
  61.  
  62. USAGE:
  63. // Create a new CalendarPopup object of type WINDOW
  64. var cal = new CalendarPopup(); 
  65.  
  66. // Create a new CalendarPopup object of type DIV using the DIV named 'mydiv'
  67. var cal = new CalendarPopup('mydiv'); 
  68.  
  69. // Easy method to link the popup calendar with an input box. 
  70. cal.select(inputObject, anchorname, dateFormat);
  71. // Same method, but passing a default date other than the field's current value
  72. cal.select(inputObject, anchorname, dateFormat, '01/02/2000');
  73. // This is an example call to the popup calendar from a link to populate an 
  74. // input box. Note that to use this, date.js must also be included!!
  75. <A HREF="#" onClick="cal.select(document.forms[0].date,'anchorname','MM/dd/yyyy'); return false;">Select</A>
  76.  
  77. // Set the type of date select to be used. By default it is 'date'.
  78. cal.setDisplayType(type);
  79.  
  80. // When a date, month, quarter, or year is clicked, a function is called and
  81. // passed the details. You must write this function, and tell the calendar
  82. // popup what the function name is.
  83. // Function to be called for 'date' select receives y, m, d
  84. cal.setReturnFunction(functionname);
  85. // Function to be called for 'month' select receives y, m
  86. cal.setReturnMonthFunction(functionname);
  87. // Function to be called for 'quarter' select receives y, q
  88. cal.setReturnQuarterFunction(functionname);
  89. // Function to be called for 'year' select receives y
  90. cal.setReturnYearFunction(functionname);
  91.  
  92. // Show the calendar relative to a given anchor
  93. cal.showCalendar(anchorname);
  94.  
  95. // Hide the calendar. The calendar is set to autoHide automatically
  96. cal.hideCalendar();
  97.  
  98. // Set the month names to be used. Default are English month names
  99. cal.setMonthNames("January","February","March",...);
  100.  
  101. // Set the month abbreviations to be used. Default are English month abbreviations
  102. cal.setMonthAbbreviations("Jan","Feb","Mar",...);
  103.  
  104. // Show navigation for changing by the year, not just one month at a time
  105. cal.showYearNavigation();
  106.  
  107. // Show month and year dropdowns, for quicker selection of month of dates
  108. cal.showNavigationDropdowns();
  109.  
  110. // Set the text to be used above each day column. The days start with 
  111. // sunday regardless of the value of WeekStartDay
  112. cal.setDayHeaders("S","M","T",...);
  113.  
  114. // Set the day for the first column in the calendar grid. By default this
  115. // is Sunday (0) but it may be changed to fit the conventions of other
  116. // countries.
  117. cal.setWeekStartDay(1); // week is Monday - Saturday
  118.  
  119. // Set the weekdays which should be disabled in the 'date' select popup. You can
  120. // then allow someone to only select week end dates, or Tuedays, for example
  121. cal.setDisabledWeekDays(0,1); // To disable selecting the 1st or 2nd days of the week
  122.  
  123. // Selectively disable individual days or date ranges. Disabled days will not
  124. // be clickable, and show as strike-through text on current browsers.
  125. // Date format is any format recognized by parseDate() in date.js
  126. // Pass a single date to disable:
  127. cal.addDisabledDates("2003-01-01");
  128. // Pass null as the first parameter to mean "anything up to and including" the
  129. // passed date:
  130. cal.addDisabledDates(null, "01/02/03");
  131. // Pass null as the second parameter to mean "including the passed date and
  132. // anything after it:
  133. cal.addDisabledDates("Jan 01, 2003", null);
  134. // Pass two dates to disable all dates inbetween and including the two
  135. cal.addDisabledDates("January 01, 2003", "Dec 31, 2003");
  136.  
  137. // When the 'year' select is displayed, set the number of years back from the 
  138. // current year to start listing years. Default is 2.
  139. // This is also used for year drop-down, to decide how many years +/- to display
  140. cal.setYearSelectStartOffset(2);
  141.  
  142. // Text for the word "Today" appearing on the calendar
  143. cal.setTodayText("Today");
  144.  
  145. // The calendar uses CSS classes for formatting. If you want your calendar to
  146. // have unique styles, you can set the prefix that will be added to all the
  147. // classes in the output.
  148. // For example, normal output may have this:
  149. //     <SPAN CLASS="cpTodayTextDisabled">Today<SPAN>
  150. // But if you set the prefix like this:
  151. cal.setCssPrefix("Test");
  152. // The output will then look like:
  153. //     <SPAN CLASS="TestcpTodayTextDisabled">Today<SPAN>
  154. // And you can define that style somewhere in your page.
  155.  
  156. // When using Year navigation, you can make the year be an input box, so
  157. // the user can manually change it and jump to any year
  158. cal.showYearNavigationInput();
  159.  
  160. // Set the calendar offset to be different than the default. By default it
  161. // will appear just below and to the right of the anchorname. So if you have
  162. // a text box where the date will go and and anchor immediately after the
  163. // text box, the calendar will display immediately under the text box.
  164. cal.offsetX = 20;
  165. cal.offsetY = 20;
  166.  
  167. NOTES:
  168. 1) Requires the functions in AnchorPosition.js and PopupWindow.js
  169.  
  170. 2) Your anchor tag MUST contain both NAME and ID attributes which are the 
  171.    same. For example:
  172.    <A NAME="test" ID="test"> </A>
  173.  
  174. 3) There must be at least a space between <A> </A> for IE5.5 to see the 
  175.    anchor tag correctly. Do not do <A></A> with no space.
  176.  
  177. 4) When a CalendarPopup object is created, a handler for 'onmouseup' is
  178.    attached to any event handler you may have already defined. Do NOT define
  179.    an event handler for 'onmouseup' after you define a CalendarPopup object 
  180.    or the autoHide() will not work correctly.
  181.    
  182. 5) The calendar popup display uses style sheets to make it look nice.
  183.  
  184. */ 
  185.  
  186. // CONSTRUCTOR for the CalendarPopup Object
  187. function CalendarPopup() {
  188.     var c;
  189.     if (arguments.length>0) {
  190.         c = new PopupWindow(arguments[0]);
  191.         }
  192.     else {
  193.         c = new PopupWindow();
  194.         c.setSize(150,175);
  195.         }
  196.     c.offsetX = -152;
  197.     c.offsetY = 25;
  198.     c.autoHide();
  199.     // Calendar-specific properties
  200.     c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  201.     c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  202.     c.dayHeaders = new Array("S","M","T","W","T","F","S");
  203.     c.returnFunction = "CP_tmpReturnFunction";
  204.     c.returnMonthFunction = "CP_tmpReturnMonthFunction";
  205.     c.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
  206.     c.returnYearFunction = "CP_tmpReturnYearFunction";
  207.     c.weekStartDay = 0;
  208.     c.isShowYearNavigation = false;
  209.     c.displayType = "date";
  210.     c.disabledWeekDays = new Object();
  211.     c.disabledDatesExpression = "";
  212.     c.yearSelectStartOffset = 2;
  213.     c.currentDate = null;
  214.     c.todayText="Today";
  215.     c.cssPrefix="";
  216.     c.isShowNavigationDropdowns=false;
  217.     c.isShowYearNavigationInput=false;
  218.     window.CP_calendarObject = null;
  219.     window.CP_targetInput = null;
  220.     window.CP_dateFormat = "MM/dd/yyyy";
  221.     // Method mappings
  222.     c.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
  223.     c.setReturnFunction = CP_setReturnFunction;
  224.     c.setReturnMonthFunction = CP_setReturnMonthFunction;
  225.     c.setReturnQuarterFunction = CP_setReturnQuarterFunction;
  226.     c.setReturnYearFunction = CP_setReturnYearFunction;
  227.     c.setMonthNames = CP_setMonthNames;
  228.     c.setMonthAbbreviations = CP_setMonthAbbreviations;
  229.     c.setDayHeaders = CP_setDayHeaders;
  230.     c.setWeekStartDay = CP_setWeekStartDay;
  231.     c.setDisplayType = CP_setDisplayType;
  232.     c.setDisabledWeekDays = CP_setDisabledWeekDays;
  233.     c.addDisabledDates = CP_addDisabledDates;
  234.     c.setYearSelectStartOffset = CP_setYearSelectStartOffset;
  235.     c.setTodayText = CP_setTodayText;
  236.     c.showYearNavigation = CP_showYearNavigation;
  237.     c.showCalendar = CP_showCalendar;
  238.     c.hideCalendar = CP_hideCalendar;
  239.     c.getStyles = getCalendarStyles;
  240.     c.refreshCalendar = CP_refreshCalendar;
  241.     c.getCalendar = CP_getCalendar;
  242.     c.select = CP_select;
  243.     c.setCssPrefix = CP_setCssPrefix;
  244.     c.showNavigationDropdowns = CP_showNavigationDropdowns;
  245.     c.showYearNavigationInput = CP_showYearNavigationInput;
  246.     c.copyMonthNamesToWindow();
  247.     // Return the object
  248.     return c;
  249.     }
  250. function CP_copyMonthNamesToWindow() {
  251.     // Copy these values over to the date.js 
  252.     if (typeof(window.MONTH_NAMES)!="undefined" && window.MONTH_NAMES!=null) {
  253.         window.MONTH_NAMES = new Array();
  254.         for (var i=0; i<this.monthNames.length; i++) {
  255.             window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthNames[i];
  256.         }
  257.         for (var i=0; i<this.monthAbbreviations.length; i++) {
  258.             window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthAbbreviations[i];
  259.         }
  260.     }
  261. }
  262. // Temporary default functions to be called when items clicked, so no error is thrown
  263. function CP_tmpReturnFunction(y,m,d) { 
  264.     if (window.CP_targetInput!=null) {
  265.         var dt = new Date(y,m-1,d,0,0,0);
  266.         if (window.CP_calendarObject!=null) { window.CP_calendarObject.copyMonthNamesToWindow(); }
  267.         window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
  268.         }
  269.     else {
  270.         alert('Use setReturnFunction() to define which function will get the clicked results!'); 
  271.         }
  272.     }
  273. function CP_tmpReturnMonthFunction(y,m) { 
  274.     alert('Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , month='+m); 
  275.     }
  276. function CP_tmpReturnQuarterFunction(y,q) { 
  277.     alert('Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , quarter='+q); 
  278.     }
  279. function CP_tmpReturnYearFunction(y) { 
  280.     alert('Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year='+y); 
  281.     }
  282.  
  283. // Set the name of the functions to call to get the clicked item
  284. function CP_setReturnFunction(name) { this.returnFunction = name; }
  285. function CP_setReturnMonthFunction(name) { this.returnMonthFunction = name; }
  286. function CP_setReturnQuarterFunction(name) { this.returnQuarterFunction = name; }
  287. function CP_setReturnYearFunction(name) { this.returnYearFunction = name; }
  288.  
  289. // Over-ride the built-in month names
  290. function CP_setMonthNames() {
  291.     for (var i=0; i<arguments.length; i++) { this.monthNames[i] = arguments[i]; }
  292.     this.copyMonthNamesToWindow();
  293.     }
  294.  
  295. // Over-ride the built-in month abbreviations
  296. function CP_setMonthAbbreviations() {
  297.     for (var i=0; i<arguments.length; i++) { this.monthAbbreviations[i] = arguments[i]; }
  298.     this.copyMonthNamesToWindow();
  299.     }
  300.  
  301. // Over-ride the built-in column headers for each day
  302. function CP_setDayHeaders() {
  303.     for (var i=0; i<arguments.length; i++) { this.dayHeaders[i] = arguments[i]; }
  304.     }
  305.  
  306. // Set the day of the week (0-7) that the calendar display starts on
  307. // This is for countries other than the US whose calendar displays start on Monday(1), for example
  308. function CP_setWeekStartDay(day) { this.weekStartDay = day; }
  309.  
  310. // Show next/last year navigation links
  311. function CP_showYearNavigation() { this.isShowYearNavigation = (arguments.length>0)?arguments[0]:true; }
  312.  
  313. // Which type of calendar to display
  314. function CP_setDisplayType(type) {
  315.     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; }
  316.     this.displayType=type;
  317.     }
  318.  
  319. // How many years back to start by default for year display
  320. function CP_setYearSelectStartOffset(num) { this.yearSelectStartOffset=num; }
  321.  
  322. // Set which weekdays should not be clickable
  323. function CP_setDisabledWeekDays() {
  324.     this.disabledWeekDays = new Object();
  325.     for (var i=0; i<arguments.length; i++) { this.disabledWeekDays[arguments[i]] = true; }
  326.     }
  327.     
  328. // Disable individual dates or ranges
  329. // Builds an internal logical test which is run via eval() for efficiency
  330. function CP_addDisabledDates(start, end) {
  331.     if (arguments.length==1) { end=start; }
  332.     if (start==null && end==null) { return; }
  333.     if (this.disabledDatesExpression!="") { this.disabledDatesExpression+= "||"; }
  334.     if (start!=null) { start = parseDate(start); start=""+start.getFullYear()+LZ(start.getMonth()+1)+LZ(start.getDate());}
  335.     if (end!=null) { end=parseDate(end); end=""+end.getFullYear()+LZ(end.getMonth()+1)+LZ(end.getDate());}
  336.     if (start==null) { this.disabledDatesExpression+="(ds<="+end+")"; }
  337.     else if (end  ==null) { this.disabledDatesExpression+="(ds>="+start+")"; }
  338.     else { this.disabledDatesExpression+="(ds>="+start+"&&ds<="+end+")"; }
  339.     }
  340.     
  341. // Set the text to use for the "Today" link
  342. function CP_setTodayText(text) {
  343.     this.todayText = text;
  344.     }
  345.  
  346. // Set the prefix to be added to all CSS classes when writing output
  347. function CP_setCssPrefix(val) { 
  348.     this.cssPrefix = val; 
  349.     }
  350.  
  351. // Show the navigation as an dropdowns that can be manually changed
  352. function CP_showNavigationDropdowns() { this.isShowNavigationDropdowns = (arguments.length>0)?arguments[0]:true; }
  353.  
  354. // Show the year navigation as an input box that can be manually changed
  355. function CP_showYearNavigationInput() { this.isShowYearNavigationInput = (arguments.length>0)?arguments[0]:true; }
  356.  
  357. // Hide a calendar object
  358. function CP_hideCalendar() {
  359.     if (arguments.length > 0) { window.popupWindowObjects[arguments[0]].hidePopup(); }
  360.     else { this.hidePopup(); }
  361.     }
  362.  
  363. // Refresh the contents of the calendar display
  364. function CP_refreshCalendar(index) {
  365.     var calObject = window.popupWindowObjects[index];
  366.     if (arguments.length>1) { 
  367.         calObject.populate(calObject.getCalendar(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
  368.         }
  369.     else {
  370.         calObject.populate(calObject.getCalendar());
  371.         }
  372.     calObject.refresh();
  373.     }
  374.  
  375. // Populate the calendar and display it
  376. function CP_showCalendar(anchorname) {
  377.     if (arguments.length>1) {
  378.         if (arguments[1]==null||arguments[1]=="") {
  379.             this.currentDate=new Date();
  380.             }
  381.         else {
  382.             this.currentDate=new Date(parseDate(arguments[1]));
  383.             }
  384.         }
  385.     this.populate(this.getCalendar());
  386.     this.showPopup(anchorname);
  387.     }
  388.  
  389. // Simple method to interface popup calendar with a text-entry box
  390. function CP_select(inputobj, linkname, format) {
  391.     var selectedDate=(arguments.length>3)?arguments[3]:null;
  392.     if (!window.getDateFromFormat) {
  393.         alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
  394.         return;
  395.         }
  396.     if (this.displayType!="date"&&this.displayType!="week-end") {
  397.         alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
  398.         return;
  399.         }
  400.     if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") { 
  401.         alert("calendar.select: Input object passed is not a valid form input object"); 
  402.         window.CP_targetInput=null;
  403.         return;
  404.         }
  405.     window.CP_targetInput = inputobj;
  406.     window.CP_calendarObject = this;
  407.     this.currentDate=null;
  408.     var time=0;
  409.     if (selectedDate!=null) {
  410.         time = getDateFromFormat(selectedDate,format)
  411.         }
  412.     else if (inputobj.value!="") {
  413.         time = getDateFromFormat(inputobj.value,format);
  414.         }
  415.     if (selectedDate!=null || inputobj.value!="") {
  416.         if (time==0) { this.currentDate=null; }
  417.         else { this.currentDate=new Date(time); }
  418.         }
  419.     window.CP_dateFormat = format;
  420.     this.showCalendar(linkname);
  421.     }
  422.     
  423. // Get style block needed to display the calendar correctly
  424. function getCalendarStyles() {
  425.     var result = "";
  426.     var p = "";
  427.     if (this!=null && typeof(this.cssPrefix)!="undefined" && this.cssPrefix!=null && this.cssPrefix!="") { p=this.cssPrefix; }
  428.     result += "<STYLE>\n";
  429.     result += "."+p+"cpYearNavigation,."+p+"cpMonthNavigation { background-color:#C0C0C0; text-align:center; vertical-align:center; text-decoration:none; color:#000000; font-weight:bold; }\n";
  430.     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";
  431.     result += "TD."+p+"cpDayColumnHeader { text-align:right; border:solid thin #C0C0C0;border-width:0 0 1 0; }\n";
  432.     result += "."+p+"cpCurrentMonthDate, ."+p+"cpOtherMonthDate, ."+p+"cpCurrentDate  { text-align:right; text-decoration:none; }\n";
  433.     result += "."+p+"cpCurrentMonthDateDisabled, ."+p+"cpOtherMonthDateDisabled, ."+p+"cpCurrentDateDisabled { color:#D0D0D0; text-align:right; text-decoration:line-through; }\n";
  434.     result += "."+p+"cpCurrentMonthDate, .cpCurrentDate { color:#000000; }\n";
  435.     result += "."+p+"cpOtherMonthDate { color:#808080; }\n";
  436.     result += "TD."+p+"cpCurrentDate { color:white; background-color: #C0C0C0; border-width:1; border:solid thin #800000; }\n";
  437.     result += "TD."+p+"cpCurrentDateDisabled { border-width:1; border:solid thin #FFAAAA; }\n";
  438.     result += "TD."+p+"cpTodayText, TD."+p+"cpTodayTextDisabled { border:solid thin #C0C0C0; border-width:1 0 0 0;}\n";
  439.     result += "A."+p+"cpTodayText, SPAN."+p+"cpTodayTextDisabled { height:20px; }\n";
  440.     result += "A."+p+"cpTodayText { color:black; }\n";
  441.     result += "."+p+"cpTodayTextDisabled { color:#D0D0D0; }\n";
  442.     result += "."+p+"cpBorder { border:solid thin #808080; }\n";
  443.     result += "</STYLE>\n";
  444.     return result;
  445.     }
  446.  
  447. // Return a string containing all the calendar code to be displayed
  448. function CP_getCalendar() {
  449.     var now = new Date();
  450.     // Reference to window
  451.     if (this.type == "WINDOW") { var windowref = "window.opener."; }
  452.     else { var windowref = ""; }
  453.     var result = "";
  454.     // If POPUP, write entire HTML document
  455.     if (this.type == "WINDOW") {
  456.         result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
  457.         result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
  458.         }
  459.     else {
  460.         result += '<TABLE CLASS="'+this.cssPrefix+'cpBorder" WIDTH=144 BORDER=1 BORDERWIDTH=1 CELLSPACING=0 CELLPADDING=1>\n';
  461.         result += '<TR><TD ALIGN=CENTER>\n';
  462.         result += '<CENTER>\n';
  463.         }
  464.     // Code for DATE display (default)
  465.     // -------------------------------
  466.     if (this.displayType=="date" || this.displayType=="week-end") {
  467.         if (this.currentDate==null) { this.currentDate = now; }
  468.         if (arguments.length > 0) { var month = arguments[0]; }
  469.             else { var month = this.currentDate.getMonth()+1; }
  470.         if (arguments.length > 1 && arguments[1]>0 && arguments[1]-0==arguments[1]) { var year = arguments[1]; }
  471.             else { var year = this.currentDate.getFullYear(); }
  472.         var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  473.         if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
  474.             daysinmonth[2] = 29;
  475.             }
  476.         var current_month = new Date(year,month-1,1);
  477.         var display_year = year;
  478.         var display_month = month;
  479.         var display_date = 1;
  480.         var weekday= current_month.getDay();
  481.         var offset = 0;
  482.         
  483.         offset = (weekday >= this.weekStartDay) ? weekday-this.weekStartDay : 7-this.weekStartDay+weekday ;
  484.         if (offset > 0) {
  485.             display_month--;
  486.             if (display_month < 1) { display_month = 12; display_year--; }
  487.             display_date = daysinmonth[display_month]-offset+1;
  488.             }
  489.         var next_month = month+1;
  490.         var next_month_year = year;
  491.         if (next_month > 12) { next_month=1; next_month_year++; }
  492.         var last_month = month-1;
  493.         var last_month_year = year;
  494.         if (last_month < 1) { last_month=12; last_month_year--; }
  495.         var date_class;
  496.         if (this.type!="WINDOW") {
  497.             result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
  498.             }
  499.         result += '<TR>\n';
  500.         var refresh = windowref+'CP_refreshCalendar';
  501.         var refreshLink = 'javascript:' + refresh;
  502.         if (this.isShowNavigationDropdowns) {
  503.             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)+');">';
  504.             for( var monthCounter=1; monthCounter<=12; monthCounter++ ) {
  505.                 var selected = (monthCounter==month) ? 'SELECTED' : '';
  506.                 result += '<option value="'+monthCounter+'" '+selected+'>'+this.monthNames[monthCounter-1]+'</option>';
  507.                 }
  508.             result += '</select></TD>';
  509.             result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"> </TD>';
  510.  
  511.             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);">';
  512.             for( var yearCounter=year-this.yearSelectStartOffset; yearCounter<=year+this.yearSelectStartOffset; yearCounter++ ) {
  513.                 var selected = (yearCounter==year) ? 'SELECTED' : '';
  514.                 result += '<option value="'+yearCounter+'" '+selected+'>'+yearCounter+'</option>';
  515.                 }
  516.             result += '</select></TD>';
  517.             }
  518.         else {
  519.             if (this.isShowYearNavigation) {
  520.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');"><</A></TD>';
  521.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="58"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+'</SPAN></TD>';
  522.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">></A></TD>';
  523.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"> </TD>';
  524.  
  525.                 result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year-1)+');"><</A></TD>';
  526.                 if (this.isShowYearNavigationInput) {
  527.                     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>';
  528.                     }
  529.                 else {
  530.                     result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><SPAN CLASS="'+this.cssPrefix+'cpYearNavigation">'+year+'</SPAN></TD>';
  531.                     }
  532.                 result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year+1)+');">></A></TD>';
  533.                 }
  534.             else {
  535.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');"><<</A></TD>\n';
  536.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="100"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+' '+year+'</SPAN></TD>\n';
  537.                 result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">>></A></TD>\n';
  538.                 }
  539.             }
  540.         result += '</TR></TABLE>\n';
  541.         result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=0 CELLPADDING=1 ALIGN=CENTER>\n';
  542.         result += '<TR>\n';
  543.         for (var j=0; j<7; j++) {
  544.  
  545.             result += '<TD CLASS="'+this.cssPrefix+'cpDayColumnHeader" WIDTH="14%"><SPAN CLASS="'+this.cssPrefix+'cpDayColumnHeader">'+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
  546.             }
  547.         result += '</TR>\n';
  548.         for (var row=1; row<=6; row++) {
  549.             result += '<TR>\n';
  550.             for (var col=1; col<=7; col++) {
  551.                 var disabled=false;
  552.                 if (this.disabledDatesExpression!="") {
  553.                     var ds=""+display_year+LZ(display_month)+LZ(display_date);
  554.                     eval("disabled=("+this.disabledDatesExpression+")");
  555.                     }
  556.                 var dateClass = "";
  557.                 if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
  558.                     dateClass = "cpCurrentDate";
  559.                     }
  560.                 else if (display_month == month) {
  561.                     dateClass = "cpCurrentMonthDate";
  562.                     }
  563.                 else {
  564.                     dateClass = "cpOtherMonthDate";
  565.                     }
  566.                 if (disabled || this.disabledWeekDays[col-1]) {
  567.                     result += '    <TD CLASS="'+this.cssPrefix+dateClass+'"><SPAN CLASS="'+this.cssPrefix+dateClass+'Disabled">'+display_date+'</SPAN></TD>\n';
  568.                     }
  569.                 else {
  570.                     var selected_date = display_date;
  571.                     var selected_month = display_month;
  572.                     var selected_year = display_year;
  573.                     if (this.displayType=="week-end") {
  574.                         var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
  575.                         d.setDate(d.getDate() + (7-col));
  576.                         selected_year = d.getYear();
  577.                         if (selected_year < 1000) { selected_year += 1900; }
  578.                         selected_month = d.getMonth()+1;
  579.                         selected_date = d.getDate();
  580.                         }
  581.                     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';
  582.                     }
  583.                 display_date++;
  584.                 if (display_date > daysinmonth[display_month]) {
  585.                     display_date=1;
  586.                     display_month++;
  587.                     }
  588.                 if (display_month > 12) {
  589.                     display_month=1;
  590.                     display_year++;
  591.                     }
  592.                 }
  593.             result += '</TR>';
  594.             }
  595.         var current_weekday = now.getDay() - this.weekStartDay;
  596.         if (current_weekday < 0) {
  597.             current_weekday += 7;
  598.             }
  599.         result += '<TR>\n';
  600.         result += '    <TD COLSPAN=7 ALIGN=CENTER CLASS="'+this.cssPrefix+'cpTodayText">\n';
  601.         if (this.disabledDatesExpression!="") {
  602.             var ds=""+now.getFullYear()+LZ(now.getMonth()+1)+LZ(now.getDate());
  603.             eval("disabled=("+this.disabledDatesExpression+")");
  604.             }
  605.         if (disabled || this.disabledWeekDays[current_weekday+1]) {
  606.             result += '        <SPAN CLASS="'+this.cssPrefix+'cpTodayTextDisabled">'+this.todayText+'</SPAN>\n';
  607.             }
  608.         else {
  609.             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';
  610.             }
  611.         result += '        <BR>\n';
  612.         result += '    </TD></TR></TABLE></CENTER></TD></TR></TABLE>\n';
  613.     }
  614.  
  615.     // Code common for MONTH, QUARTER, YEAR
  616.     // ------------------------------------
  617.     if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
  618.         if (arguments.length > 0) { var year = arguments[0]; }
  619.         else { 
  620.             if (this.displayType=="year") {    var year = now.getFullYear()-this.yearSelectStartOffset; }
  621.             else { var year = now.getFullYear(); }
  622.             }
  623.         if (this.displayType!="year" && this.isShowYearNavigation) {
  624.             result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
  625.             result += '<TR>\n';
  626.             result += '    <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-1)+');"><<</A></TD>\n';
  627.             result += '    <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="100">'+year+'</TD>\n';
  628.             result += '    <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+1)+');">>></A></TD>\n';
  629.             result += '</TR></TABLE>\n';
  630.             }
  631.         }
  632.         
  633.     // Code for MONTH display 
  634.     // ----------------------
  635.     if (this.displayType=="month") {
  636.         // If POPUP, write entire HTML document
  637.         result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
  638.         for (var i=0; i<4; i++) {
  639.             result += '<TR>';
  640.             for (var j=0; j<3; j++) {
  641.                 var monthindex = ((i*3)+j);
  642.                 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>';
  643.                 }
  644.             result += '</TR>';
  645.             }
  646.         result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  647.         }
  648.     
  649.     // Code for QUARTER display
  650.     // ------------------------
  651.     if (this.displayType=="quarter") {
  652.         result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
  653.         for (var i=0; i<2; i++) {
  654.             result += '<TR>';
  655.             for (var j=0; j<2; j++) {
  656.                 var quarter = ((i*2)+j+1);
  657.                 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>';
  658.                 }
  659.             result += '</TR>';
  660.             }
  661.         result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  662.         }
  663.  
  664.     // Code for YEAR display
  665.     // ---------------------
  666.     if (this.displayType=="year") {
  667.         var yearColumnSize = 4;
  668.         result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
  669.         result += '<TR>\n';
  670.         result += '    <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');"><<</A></TD>\n';
  671.         result += '    <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">>></A></TD>\n';
  672.         result += '</TR></TABLE>\n';
  673.         result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
  674.         for (var i=0; i<yearColumnSize; i++) {
  675.             for (var j=0; j<2; j++) {
  676.                 var currentyear = year+(j*yearColumnSize)+i;
  677.                 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>';
  678.                 }
  679.             result += '</TR>';
  680.             }
  681.         result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  682.         }
  683.     // Common
  684.     if (this.type == "WINDOW") {
  685.         result += "</BODY></HTML>\n";
  686.         }
  687.     return result;
  688.     }
  689.