/*
   New Perspectives on JavaScript
   Tutorial 3
   Tutorial Case

   Author: 
   Date:   

   Function List:
   calendar(calendarDay)
      Creates the calendar table for the month specified in the
      calendarDay parameter. The current date is highlighted in 
      the table.

   writeCalTitle(calendarDay)
      Writes the title row in the calendar table

   writeDayTitle()
      Writes the weekday title rows in the calendar table

   daysInMonth(calendarDay)
      Returns the number of days in the month from calendarDay

   writeCalDays(calendarDay)
      Writes the daily rows in the calendar table, highlighting
      calendarDay

*/

function calendar() {
    var calDate = new Date();

    document.write("<table id='calendar_table'>");
    writeCalTitle(calDate);
    writeDayNames();
    document.write("</table>");
}

function writeCalTitle(calendarDay) {
    var monthName = new Array("January", "February",
        "March", "April", "May", "June", "July",
        "August", "September", "October", "November",
        "December");

    var month = calendarDay.getMonth();
    var year = calendarDay.getFullYear();

    document.write("<tr>"
        + "<th id='calendar_head' colspan='7'>"
        + monthName[month]
        + "</th></tr>");
}

function writeDayNames() {
    var dayName = new Array("Sun", "Mon", "Tue",
        "Wed", "Thu", "Fri", "Sat");
    document.write("<tr>");
    for (var i = 0; i < dayName.length; i++) {
      document.write("<th class='calendar_weekdays'>"
          + dayName[i] + "</th>");
    }
    document.write("</tr>");
}

