home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Javascript / JavaScriptEditor / jse_en28.exe / %MAINDIR% / Library / Calendar.js < prev    next >
Encoding:
Text File  |  2001-09-10  |  2.4 KB  |  95 lines

  1.  
  2. function greeting()
  3. {
  4.    var today = new Date();
  5.    var hrs = today.getHours();
  6.    document.writeln("<CENTER>");
  7.    document.write("<H1>Good ");
  8.    if (hrs < 6)
  9.       document.write("(Early) Morning");
  10.    else if (hrs < 12)
  11.       document.write("Morning");
  12.    else if (hrs <= 18)
  13.       document.write("Afternoon");
  14.    else
  15.       document.write("Evening");
  16.    document.writeln("!</H1>");
  17.    document.write("You entered this page at ");
  18.    dayStr = today.toLocaleString();
  19.    document.write(dayStr);
  20.    document.writeln("</CENTER>");
  21. }
  22. function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
  23. {
  24.    this[0] = m0;
  25.    this[1] = m1;
  26.    this[2] = m2;
  27.    this[3] = m3;
  28.    this[4] = m4;
  29.    this[5] = m5;
  30.    this[6] = m6;
  31.    this[7] = m7;
  32.    this[8] = m8;
  33.    this[9] = m9;
  34.    this[10] = m10;
  35.    this[11] = m11;
  36. }
  37. function calendar()
  38. {
  39.    var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
  40.    var today = new Date();
  41.    var thisDay;
  42.    var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30,
  43.       31, 30, 31);
  44.    
  45.    year = today.getYear() + 1900;
  46.    thisDay = today.getDate();
  47.    
  48.    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
  49.       monthDays[1] = 29;
  50.    nDays = monthDays[today.getMonth()];
  51.    firstDay = today;
  52.    firstDay.setDate(1); // works fine for most systems
  53.    testMe = firstDay.getDate();
  54.    if (testMe == 2)
  55.         firstDay.setDate(0);    
  56.    startDay = firstDay.getDay();
  57.      
  58.    document.writeln("<CENTER>");
  59.    document.write("<TABLE BORDER>");
  60.    document.write("<TR><TH COLSPAN=7>");
  61.    document.write(monthNames.substring(today.getMonth() * 3,
  62.       (today.getMonth() + 1) * 3));
  63.    document.write(". ");
  64.    document.write(year);
  65.    document.write("<TR><TH>Sun<TH>Mon<TH>Tue<TH>Wed<TH>Thu<TH>Fri<TH>Sat");
  66.    document.write("<TR>");
  67.    column = 0;
  68.    for (i=0; i<startDay; i++)
  69.    {
  70.       document.write("<TD>");
  71.       column++;
  72.    }
  73.    for (i=1; i<=nDays; i++)
  74.    {
  75.       document.write("<TD>");
  76.       if (i == thisDay)
  77.          document.write("<FONT COLOR=\"red\">")
  78.       document.write(i);
  79.       if (i == thisDay)
  80.         document.write("</FONT>")
  81.       column++;
  82.       if (column == 7)
  83.       {
  84.          document.write("<TR>"); 
  85.          column = 0;
  86.       }
  87.    }
  88.    document.write("</TABLE>");
  89.    document.writeln("</CENTER>");
  90. }
  91. greeting();
  92. document.write("<br>");
  93. calendar();
  94. document.write("");
  95.