home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / internet / svetpda / data / date-picker.js < prev    next >
Text File  |  2002-02-06  |  15KB  |  446 lines

  1. var DateMin = new Date('11/01/2001');
  2. var DateMax = new Date();
  3. var weekend = [5,6];
  4. var weekendColor = "#d9e5e7";
  5. var fontface = "Verdana";
  6. var fontsize = 2;
  7. var vDayMin, vDayMax
  8. var gNow = new Date();
  9. var ggWinCal;
  10. isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
  11. isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  12. Calendar.Months = ["Leden", "┌nor", "B°ezen", "Duben", "Kv∞ten", "╚erven",
  13. "╚ervenec", "Srpen", "Zß°φ", "╪φjen", "Listopad", "Prosinec"];
  14. Calendar.Days = ["Po","┌t","St","╚t","Pß","So","Ne"];
  15. // Non-Leap year Month days..
  16. Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  17. // Leap year Month days..
  18. Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  19. function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
  20.     if ((p_month == null) && (p_year == null))    return;
  21.     this.gWinCal = p_WinCal == null ? ggWinCal : p_WinCal;
  22.     
  23.     if (p_month == null) {
  24.         this.gMonthName = this.gMonth = null;
  25.         this.gYearly = true;
  26.     } else {
  27.         this.gMonthName = Calendar.get_month(p_month);
  28.         this.gMonth = new Number(p_month);
  29.         this.gYearly = false;
  30.     }
  31.     this.gYear = p_year;
  32.     this.gFormat = p_format;
  33.     this.gBGColor = "white";
  34.     this.gFGColor = "black";
  35.     this.gTextColor = "black";
  36.     this.gHeaderColor = "black";
  37.     this.gReturnItem = p_item;
  38. }
  39. Calendar.get_month = Calendar_get_month;
  40. Calendar.get_daysofmonth = Calendar_get_daysofmonth;
  41. Calendar.calc_month_year = Calendar_calc_month_year;
  42. Calendar.print = Calendar_print;
  43. function Calendar_get_month(monthNo) {
  44.     return Calendar.Months[monthNo];
  45. }
  46. function Calendar_get_daysofmonth(monthNo, p_year) {
  47.     if ((p_year % 4) == 0) {
  48.         if ((p_year % 100) == 0 && (p_year % 400) != 0)
  49.             return Calendar.DOMonth[monthNo];
  50.         return Calendar.lDOMonth[monthNo];
  51.     } else
  52.         return Calendar.DOMonth[monthNo];
  53. }
  54. function Calendar_calc_month_year(p_Month, p_Year, incr) {
  55.     var ret_arr = new Array();
  56.     
  57.     if (incr == -1) {
  58.         // B A C K W A R D
  59.         if (p_Month == 0) {
  60.             ret_arr[0] = 11;
  61.             ret_arr[1] = parseInt(p_Year) - 1;
  62.         }
  63.         else {
  64.             ret_arr[0] = parseInt(p_Month) - 1;
  65.             ret_arr[1] = parseInt(p_Year);
  66.         }
  67.     } else if (incr == 1) {
  68.         // F O R W A R D
  69.         if (p_Month == 11) {
  70.             ret_arr[0] = 0;
  71.             ret_arr[1] = parseInt(p_Year) + 1;
  72.         }
  73.         else {
  74.             ret_arr[0] = parseInt(p_Month) + 1;
  75.             ret_arr[1] = parseInt(p_Year);
  76.         }
  77.     }
  78.     
  79.     return ret_arr;
  80. }
  81. function Calendar_print() {
  82.     ggWinCal.print();
  83. }
  84. function Calendar_calc_month_year(p_Month, p_Year, incr) {
  85.     var ret_arr = new Array();
  86.     
  87.     if (incr == -1) {
  88.         // B A C K W A R D
  89.         if (p_Month == 0) {
  90.             ret_arr[0] = 11;
  91.             ret_arr[1] = parseInt(p_Year) - 1;
  92.         }
  93.         else {
  94.             ret_arr[0] = parseInt(p_Month) - 1;
  95.             ret_arr[1] = parseInt(p_Year);
  96.         }
  97.     } else if (incr == 1) {
  98.         // F O R W A R D
  99.         if (p_Month == 11) {
  100.             ret_arr[0] = 0;
  101.             ret_arr[1] = parseInt(p_Year) + 1;
  102.         }
  103.         else {
  104.             ret_arr[0] = parseInt(p_Month) + 1;
  105.             ret_arr[1] = parseInt(p_Year);
  106.         }
  107.     }
  108.     
  109.     return ret_arr;
  110. }
  111. // This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
  112. new Calendar();
  113. Calendar.prototype.getMonthlyCalendarCode = function() {
  114.     var vCode = "";
  115.     var vHeader_Code = "";
  116.     var vData_Code = "";
  117.     
  118.     // Begin Table Drawing code here..
  119.     vCode = "<TABLE WIDTH=190 BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
  120.     
  121.     vHeader_Code = this.cal_header();
  122.     vData_Code = this.cal_data();
  123.     vCode += vHeader_Code + vData_Code;
  124.     
  125.     vCode = vCode + "</TABLE>";
  126.     
  127.     return vCode;
  128. }
  129. Calendar.prototype.show = function() {
  130.     var vCode = "";
  131.     
  132.     this.gWinCal.document.open();
  133.     // Setup the page...
  134.     this.wwrite("<html>");
  135.     this.wwrite("<head><title>Kalendß°</title>");
  136.     this.wwrite("</head>");
  137.     this.wwrite("<body " + 
  138.         "link=\"" + this.gLinkColor + "\" " + 
  139.         "vlink=\"" + this.gLinkColor + "\" " +
  140.         "alink=\"" + this.gLinkColor + "\" " +
  141.         "text=\"" + this.gTextColor + "\">");
  142.     this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
  143.     this.wwriteA(this.gMonthName + " " + this.gYear);
  144.     this.wwriteA("</B><BR>");
  145.     // Show navigation buttons
  146.     var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
  147.     var prevMM = prevMMYYYY[0];
  148.     var prevYYYY = prevMMYYYY[1];
  149.     var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
  150.     var nextMM = nextMMYYYY[0];
  151.     var nextYYYY = nextMMYYYY[1];
  152.     
  153.     this.wwrite("<TABLE WIDTH='190' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#d9e5e7'><TR><TD ALIGN=center>");
  154.     this.wwrite("<A HREF=\"" +
  155.         "javascript:window.opener.Build(" + 
  156.         "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
  157.         ");" +
  158.         "\"><FONT SIZE='2' FACE='Verdana'><<</FONT><\/A></TD><TD ALIGN=center>");
  159.     this.wwrite("<A HREF=\"" +
  160.         "javascript:window.opener.Build(" + 
  161.         "'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
  162.         ");" +
  163.         "\"><FONT SIZE='2' FACE='Verdana'><</FONT><\/A></TD><TD ALIGN=center>");
  164.     this.wwrite("<FONT SIZE='2' FACE='Verdana'>Vyber</FONT></TD><TD ALIGN=center>");
  165.     this.wwrite("<A HREF=\"" +
  166.         "javascript:window.opener.Build(" + 
  167.         "'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
  168.         ");" +
  169.         "\"><FONT SIZE='2' FACE='Verdana'>></FONT><\/A></TD><TD ALIGN=center>");
  170.     this.wwrite("<A HREF=\"" +
  171.         "javascript:window.opener.Build(" + 
  172.         "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
  173.         ");" +
  174.         "\"><FONT SIZE='2' FACE='Verdana'>>></FONT><\/A></TD></TR></TABLE><BR>");
  175.     // Get the complete calendar code for the month..
  176.     vCode = this.getMonthlyCalendarCode();
  177.     this.wwrite(vCode);
  178.     this.wwrite("</font></body></html>");
  179.     this.gWinCal.document.close();
  180. }
  181. Calendar.prototype.showY = function() {
  182.     var vCode = "";
  183.     var i;
  184.     var vr, vc, vx, vy;        // Row, Column, X-coord, Y-coord
  185.     var vxf = 285;            // X-Factor
  186.     var vyf = 200;            // Y-Factor
  187.     var vxm = 10;            // X-margin
  188.     var vym;                // Y-margin
  189.     if (isIE)    vym = 75;
  190.     else if (isNav)    vym = 25;
  191.     
  192.     this.gWinCal.document.open();
  193.     this.wwrite("<html>");
  194.     this.wwrite("<head><title>Kalendß°</title>");
  195.     this.wwrite("<style type='text/css'>\n<!--");
  196.     for (i=0; i<12; i++) {
  197.         vc = i % 3;
  198.         if (i>=0 && i<= 2)    vr = 0;
  199.         if (i>=3 && i<= 5)    vr = 1;
  200.         if (i>=6 && i<= 8)    vr = 2;
  201.         if (i>=9 && i<= 11)    vr = 3;
  202.         
  203.         vx = parseInt(vxf * vc) + vxm;
  204.         vy = parseInt(vyf * vr) + vym;
  205.         this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
  206.     }
  207.     this.wwrite("-->\n</style>");
  208.     this.wwrite("</head>");
  209.     this.wwrite("<body " + 
  210.         "link=\"" + this.gLinkColor + "\" " + 
  211.         "vlink=\"" + this.gLinkColor + "\" " +
  212.         "alink=\"" + this.gLinkColor + "\" " +
  213.         "text=\"" + this.gTextColor + "\">");
  214.     this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
  215.     this.wwrite("Rok : " + this.gYear);
  216.     this.wwrite("</B><BR>");
  217.     // Show navigation buttons
  218.     var prevYYYY = parseInt(this.gYear) - 1;
  219.     var nextYYYY = parseInt(this.gYear) + 1;
  220.     
  221.     this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
  222.     this.wwrite("<A HREF=\"" +
  223.         "javascript:window.opener.Build(" + 
  224.         "'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
  225.         ");" +
  226.         "\" alt='Prev Year'><<<\/A></TD><TD ALIGN=center>");
  227.     this.wwrite("<A HREF=\"javascript:window.print();\">Tisknout</A></TD><TD ALIGN=center>");
  228.     this.wwrite("<A HREF=\"" +
  229.         "javascript:window.opener.Build(" + 
  230.         "'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
  231.         ");" +
  232.         "\">>><\/A></TD></TR></TABLE><BR>");
  233.     // Get the complete calendar code for each month..
  234.     var j;
  235.     for (i=11; i>=0; i--) {
  236.         if (isIE)
  237.             this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
  238.         else if (isNav)
  239.             this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
  240.         this.gMonth = i;
  241.         this.gMonthName = Calendar.get_month(this.gMonth);
  242.         vCode = this.getMonthlyCalendarCode();
  243.         this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
  244.         this.wwrite(vCode);
  245.         if (isIE)
  246.             this.wwrite("</DIV>");
  247.         else if (isNav)
  248.             this.wwrite("</LAYER>");
  249.     }
  250.     this.wwrite("</font><BR></body></html>");
  251.     this.gWinCal.document.close();
  252. }
  253. Calendar.prototype.wwrite = function(wtext) {
  254.     this.gWinCal.document.writeln(wtext);
  255. }
  256. Calendar.prototype.wwriteA = function(wtext) {
  257.     this.gWinCal.document.write(wtext);
  258. }
  259. Calendar.prototype.cal_header = function() {
  260.     var vCode = "";
  261.     for (var i=0;i<7;i++) {
  262.         vCode += "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>" + Calendar.Days[i] + "</B></FONT></TD>";
  263.     }
  264.     return "<TR>" + vCode + "</TR>";
  265. }
  266. Calendar.prototype.cal_data = function() {
  267.     var vDate = new Date();
  268.     vDate.setDate(1);
  269.     vDate.setMonth(this.gMonth);
  270.     vDate.setFullYear(this.gYear);
  271.     vDayMin=DateMin>vDate?DateMin.getDate():0;
  272.     vDayMax=vDate>DateMax?0:32;
  273.     var tmp=vDate.getDay();
  274.     var vFirstDay=tmp==0?6:--tmp;
  275.     var vDay=1;
  276.     var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
  277.     vDate.setDate(vLastDay);
  278.     var vOnLastDay=0;
  279.     var vCode = "";
  280.     if (vDayMax != 0) vDayMax=vDate>DateMax?DateMax.getDate():32;
  281.     if (vDayMin != 0) vDayMin=vDate<=DateMin?32:vDayMin;
  282.     /*
  283.     Get day for the 1st of the requested month/year..
  284.     Place as many blank cells before the 1st day of the month as necessary. 
  285.     */
  286.     vCode = vCode + "<TR>";
  287.     for (i=0; i<vFirstDay; i++) {
  288.         vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
  289.     }
  290.     // Write rest of the 1st week
  291.     for (j=vFirstDay; j<7; j++) {
  292.         vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>";
  293.         if ((vDay>=vDayMin)&&(vDay<=vDayMax)) {
  294.              vCode = vCode + "<A HREF='#' " + 
  295.                 "onClick=\"self.opener.location=\'/svetpda/svetpda.nsf/homepage?readform&count=30&startkey=" + this.format_data(vDay) + "\';window.close();\">" + 
  296.                 this.format_day(vDay) + 
  297.             "</A>"} else {
  298.              vCode = vCode + this.format_day(vDay)
  299.         };
  300.         vCode = vCode + "</FONT></TD>";
  301.         vDay=vDay + 1;
  302.     }
  303.     vCode = vCode + "</TR>";
  304.     // Write the rest of the weeks
  305.     for (k=2; k<7; k++) {
  306.         vCode = vCode + "<TR>";
  307.         for (j=0; j<7; j++) {
  308.             vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>";
  309.         if ((vDay>=vDayMin)&&(vDay<=vDayMax)) {
  310.             vCode = vCode + "<A HREF='#' " + 
  311.                 "onClick=\"self.opener.location=\'/svetpda/svetpda.nsf/homepage?readform&count=30&startkey=" + this.format_data(vDay) + "\';window.close();\">" + 
  312.                 this.format_day(vDay) + 
  313.                 "</A>"
  314.         } else {
  315.             vCode = vCode + this.format_day(vDay)
  316.         }
  317.             vCode = vCode + "</FONT></TD>";
  318.             vDay=vDay + 1;
  319.             if (vDay > vLastDay) {
  320.                 vOnLastDay = 1;
  321.                 break;
  322.             }
  323.         }
  324.         if (j == 6)
  325.             vCode = vCode + "</TR>";
  326.         if (vOnLastDay == 1)
  327.             break;
  328.     }
  329.     
  330.     // Fill up the rest of last week with proper blanks, so that we get proper square blocks
  331.     for (m=1; m<(7-j); m++) {
  332.         if (this.gYearly)
  333.             vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
  334.             "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
  335.         else
  336.             vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
  337.             "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
  338.     }
  339.     
  340.     return vCode;
  341. }
  342. Calendar.prototype.format_day = function(vday) {
  343.     var vNowDay = gNow.getDate();
  344.     var vNowMonth = gNow.getMonth();
  345.     var vNowYear = gNow.getFullYear();
  346.     if ((vday < vDayMin) || (vday > vDayMax))
  347.         return ("<FONT COLOR=\"gray\">" + vday + "</FONT>");
  348.     if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
  349.         return ("<FONT COLOR=\"#ff6600\"><B>" + vday + "</B></FONT>");
  350.     else
  351.         return (vday);
  352. }
  353. Calendar.prototype.write_weekend_string = function(vday) {
  354.     var i;
  355.     // Return special formatting for the weekend day.
  356.     for (i=0; i<weekend.length; i++) {
  357.         if (vday == weekend[i])
  358.             return (" BGCOLOR=\"" + weekendColor + "\"");
  359.     }
  360.     
  361.     return "";
  362. }
  363. Calendar.prototype.format_data = function(p_day) {
  364.     var vData;
  365.     var vMonth = 1 + this.gMonth;
  366.     vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
  367.     var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
  368.     var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
  369.     var vY4 = new String(this.gYear);
  370.     var vY2 = new String(this.gYear.substr(2,2));
  371.     var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
  372.     switch (this.gFormat) {
  373.         case "YYYYMMDD" :
  374.             vData = vY4 + vMonth + vDD;
  375.             break;
  376.         case "DD.MM.YY" :
  377.             vData = vDD + "." + vMonth + "." + vY2;
  378.             break;
  379.         case "DD.MM.YYYY" :
  380.             vData = vDD + "." + vMonth + "." + vY4;
  381.             break;
  382.         case "DD.MON.YYYY" :
  383.             vData = vDD + "." + vMon + "." + vY4;
  384.             break;
  385.         case "DD.MONTH.YYYY" :
  386.             vData = vDD + "." + vFMon + "." + vY4;
  387.             break;
  388.         default :
  389.             vData = vDD + "." + vMonth + "." + vY4;
  390.     }
  391.     return vData;
  392. }
  393. function Build(p_item, p_month, p_year, p_format) {
  394.     var p_WinCal = ggWinCal;
  395.     gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);
  396.     // Customize your Calendar here..
  397.     gCal.gBGColor="white";
  398.     gCal.gLinkColor="black";
  399.     gCal.gTextColor="black";
  400.     gCal.gHeaderColor="#004e5f";
  401.     // Choose appropriate show function
  402.     if (gCal.gYearly)    gCal.showY();
  403.     else    gCal.show();
  404. }
  405. function show_calendar() {
  406.     /* 
  407.         p_month : 0-11 for Jan-Dec; 12 for All Months.
  408.         p_year    : 4-digit year
  409.         p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
  410.         p_item    : Return Item.
  411.     */
  412.     p_item = arguments[0];
  413.     if (arguments[1] == null)
  414.         p_month = new String(gNow.getMonth());
  415.     else
  416.         p_month = arguments[1];
  417.     if (arguments[2] == "" || arguments[2] == null)
  418.         p_year = new String(gNow.getFullYear().toString());
  419.     else
  420.         p_year = arguments[2];
  421.     if (arguments[3] == null)
  422.         p_format = "DD.MM.YYYY";
  423.     else
  424.         p_format = arguments[3];
  425.     vWinCal = window.open("", "Calendar", 
  426.         "width=210,height=240,status=no,resizable=no,top=200,left=200");
  427.     vWinCal.opener = self;
  428.     ggWinCal = vWinCal;
  429.     Build(p_item, p_month, p_year, p_format);
  430.     window.location = "/svetpda/svetpda.nsf/"
  431. }
  432. /*
  433. Yearly Calendar Code Starts here
  434. */
  435. function show_yearly_calendar(p_item, p_year, p_format) {
  436.     // Load the defaults..
  437.     if (p_year == null || p_year == "")
  438.         p_year = new String(gNow.getFullYear().toString());
  439.     if (p_format == null || p_format == "")
  440.         p_format = "DD.MM.YYYY";
  441.     var vWinCal = window.open("", "Calendar", "scrollbars=yes");
  442.     vWinCal.opener = self;
  443.     ggWinCal = vWinCal;
  444.     Build(p_item, null, p_year, p_format);
  445. }
  446.