// JavaScript Document
// function becomes a method for each month object
function getFirstDay(theYear, theMonth){
    var firstDate = new Date(theYear,theMonth,1)
    return firstDate.getDay() + 1
}
// number of days in the month
function getMonthLen(theYear, theMonth) {
    var oneDay = 1000 * 60 * 60 * 24
    var thisMonth = new Date(theYear, theMonth, 1)
    var nextMonth = new Date(theYear, theMonth + 1, 1)
    var len = Math.ceil((nextMonth.getTime() -
        thisMonth.getTime())/oneDay)
    return len
}
// correct for Y2K anomalies
function getY2KYear(today) {
    var yr = today.getYear()
    return ((yr < 1900) ? yr+1900 : yr)
}
// create basic array
theMonths = new MakeArray(12)
// load array with English month names
function MakeArray(n) {
    this[0] = "January"
    this[1] = "February"
    this[2] = "March"
    this[3] = "April"
    this[4] = "May"
    this[5] = "June"
    this[6] = "July"
    this[7] = "August"
    this[8] = "September"
    this[9] = "October"
    this[10] = "November"
    this[11] = "December"
    this.length = n
    return this
}

function multiplemonths(yr,month) {
	// which is the first day of this month?
var firstDay = getFirstDay(yr, month)
	// total number of <TD>...</TD> tags needed in for loop below
var howMany = getMonthLen(yr, month) + firstDay
	// start assembling HTML for table
var content = "<style>table.calendar td, table.calendar th {font-family: Verdana, Arial, Tahoma, sans-serif; font-size: 10px;} table.calendar th {font-weight: bold;} table.calendar th.calendarMonth {color: red; font-size: 12px;}</style><center><table  border='0' cellpadding='2' cellspacing='2' class='calendar'>"
	// month and year display at top of calendar
content += "<tr><th colspan='7' class='calendarMonth'>" + theMonths[month] + " " + yr + "</th></tr>"
	// days of the week at head of each column
content += "<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th>"
content += "<th>Thu</th><th>Fri</th><th>Sat</th></tr>"
content += "<tr>"
	// populate calendar
for (var i = 1; i < howMany; i++) {
    if (i < firstDay) {
        // 'empty' boxes prior to first day
        content += "<td></td>"
    } else {
        // enter date number
        content += "<td align='center'>" + (i - firstDay + 1) + "</td>"
    }
    // start new row after each week
    if (i % 7 == 0 &&  i != howMany) {
        content += "</tr><tr>"
    }
}
content += "</table></center>"
// blast entire table's HTML to the document
document.write(content)
}

function init() {
	// initialize some variables for later
var today = new Date()
var theYear = getY2KYear(today)
var theMonth = today.getMonth() // for index into our array
var nextMonth, thirdMonth, nextYear, thirdYear;
switch (theMonth) {
	case 10:
		nextMonth = 11;
		thirdMonth = 0;
		nextYear = theYear;
		thirdYear = theYear + 1;
		break;
	case 11:
		nextMonth = 0;
		thirdMonth = 1;
		nextYear = theYear + 1;
		thirdYear = theYear + 1;
		break;
	default:
		nextMonth = theMonth + 1;
		thirdMonth = theMonth + 2;
		nextYear = theYear;
		thirdYear = theYear;
		break;
	}
multiplemonths (theYear, theMonth)
multiplemonths (nextYear, nextMonth)
multiplemonths (thirdYear, thirdMonth)
}
