home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / internet / svetpda.cz / svetpda / svetpda.nsf / date-picker.js < prev    next >
Text File  |  2002-03-25  |  15KB  |  513 lines

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