// The number of milliseconds per day, to handle date increments.
msPerDay = 24*60*60*1000;
cw  = 1;
// Find today.
today = new Date()

// Find the first day of the requested month. We start at noon to work around the problem of daylight
// savings time.
firstDayThis = new Date(calYear,calMonth-1,1,12);

// Back up to the Sunday previous or equal to the first day of the month.
calStart = new Date(firstDayThis.getTime() - firstDayThis.getDay()*msPerDay)

// Loop forward from that date to the first Sunday of the next month.
for (calEnd=new Date(calStart.getTime() + 7*msPerDay);
	calEnd.getMonth() == (calMonth - 1);
	calEnd.setTime(calEnd.getTime() + 7*msPerDay)) /* empty */ ;

// Loop from the beginning date of the calendar to the ending date by days.
for (currentDate = calStart;
	currentDate.getTime() < calEnd.getTime();
	currentDate.setTime(currentDate.getTime() + msPerDay))
	{
	cda = currentDate.getDay();
	cdt = currentDate.getDate();
	cmo = currentDate.getMonth() + 1;
	cyr = currentDate.getYear();
	if (cyr < 1000) cyr += 1900;
	thisMonth = (cmo == calMonth);

	todayYear = today.getYear();
	if (todayYear < 1000) todayYear += 1900;
	
	isToday = ((cmo == today.getMonth() + 1) && (cdt == today.getDate()) && (cyr == todayYear));

	// If a Sunday, begin a new row.
	if (cda == 0){ 
      document.write("<tr>");
      document.write('<td align="center" valign="middle">');
      document.write('<a href="' + searchPage + '?go=w' + cmo + 'z' + cdt + 'z' + cyr + '" ');
      document.write('class="' + "thisweek" + '"> ');
//      document.write(cw + '</a></td>');
      document.write('W&nbsp;</a></td>');
    }

	document.write('<td align="center" valign="middle">');
	document.write('<a href="' + searchPage + '?go=' + cmo + 'z' + cdt + 'z' + cyr + '" ');
	document.write('class="' + (thisMonth ? (isToday ? "today" : "thisMonth") : "otherMonth") + '">');

	// If the day is during the requested month, highlight it.
	if (thisMonth) document.write("<b>" + cdt + "</b>");
	else document.write(cdt);

	// End the table cell.
	document.writeln("</a></td>");

	// If a Saturday, end the row.
	if (cda == 6) {
      document.write("</tr>");
      cw = cw + 1;
	}
        }