//<script language=Javascript>

var isIE = navigator.appName == "Microsoft Internet Explorer";
var theYear;
var mainPage;

function makeArray(len) {
	for(var i=0; i<len; i++) this[i]=null;
this.length=len;
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
	this[0] = m0;
	this[1] = m1;
	this[2] = m2;
	this[3] = m3;
	this[4] = m4;
	this[5] = m5;
	this[6] = m6;
	this[7] = m7;
	this[8] = m8;
	this[9] = m9;
	this[10] = m10;
	this[11] = m11;
}

function calendar(aDate, currYear, currMonth, currDay) {
	var monthNames ="JanFebMarAprMayJunJulAugSepOctNovDec";
	var today = new Date(aDate);
	var thisday;
	var monthDays = new montharr(31,28,31,30,31,30,31,31,30,31,30,31);
	
	var monthName = new makeArray(12);
	monthName[0] = "January";
	monthName[1] = "February";
	monthName[2] = "March";
	monthName[3] = "April";
	monthName[4] = "May";
	monthName[5] = "June";
	monthName[6] = "July";
	monthName[7] = "August";
	monthName[8] = "September";
	monthName[9] = "October";
	monthName[10] = "November";
	monthName[11] = "December";
	
	mainPage = "";
	nYear = today.getYear();
	thisDay = today.getDate();
	nMonth = today.getMonth();
	if (nYear < 100)
		nYear = nYear + 1900

	
	// Leap Year Calculation
	if ((nYear % 4 == 0) && (nYear % 100 !=0) || (nYear % 400 == 0))
		monthDays[1] = 29;
	
	//  How many days does each month have
	nDays = monthDays[today.getMonth()];

	//  Back to first day of the month
	firstDay = today;
	firstDay.setDate(1);

	//  Which day of the week does it hit
	startDay = firstDay.getDay();

	var prevMonth, nextMonth;
	var prevYear, nextYear;
	if (nMonth == 0)
	{
		prevMonth = "12";
		prevYear = nYear-1;
		
		nextMonth = nMonth+2;
		nextYear = nYear;
	}
	else if (nMonth == 11)
	{
		prevMonth = nMonth;
		prevYear = nYear;
		
		nextMonth = "1";
		nextYear = nYear+1;
	}
	else
	{
		prevMonth = nMonth;
		nextMonth = nMonth+2;
		
		prevYear = nYear;
		nextYear = nYear;
	}

	document.write("<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr><td>");
	
	document.write("<table width='100%' border='0' class='Calendar' cellpadding='3' cellspacing='0'>");
	document.write("<tr><td align=center class=CalDayTitle bgcolor='#ECE8DD'>Su</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>Mo</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>Tu</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>We</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>Th</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>Fr</td>" +
						"<td align=center class='CalDayTitle bgcolor='#ECE8DD'>Sa</td>");
	document.write("</tr></table>");

	document.write("<table width='100%' border='0' class='Calendar2' cellpadding='3' cellspacing='1'>");
	//  Blanks at the beginning of calendar
	document.write("<tr>");
	column = 0;
	for (i= 0; i < startDay; i++) {
		document.write("<td align='center'>&nbsp;</td>");
		column++;
	}

	var links = "theLinks";
	for (i = 1; i <= nDays; i++) {
		document.write("<td align='center' class='CalDate'>");
		document.write("<span class='CalDate'>");
		var evtlink = links.substring((i-1)*9, i*9);
		//if (nMonth+1 == currMonth && nYear == currYear && i < currDay)
			//document.write(i);
		//else {
		    document.write("<span class=CalDateLink><a class='CalDateLink' href=\"index.cfm?year="+currYear+"&month="+currMonth+"&day="+i+"");
			document.write("\">" + i + "</a></span>");
		//}
		document.write("</span>");
		column++;
		document.write("</td>");
		if (column == 7) {
			document.write("</tr><tr>");
			column = 0;
		}
	}
	document.write("</tr>");
	document.write("</table></td></tr></table>");

	if (isIE)
		buildMonthSelector(nYear);
}

function buildMonthSelector(aYear) {

	theYear = aYear;
	
	document.write("<div ID='MonthSelector' STYLE='display:none;'>");
	
	document.write("<table id='M1' border='0' class='Calendar' cellpadding='2' cellspacing='0'");
	document.write("width='150' height='145'>");
	document.write("<tr>");
		document.write("<td width='33%' align='center'>");
		document.write("<p ID='I1' class=CalArrows onMouseOver='style.cursor=\"hand\"; event.returnValue=0;event.cancelBubble = true;'" +
					" onClick='decrementYear(Y2);'>");
		document.write("\<");
		document.write("</p></td>");
		
		document.write("<td width='33%' align='center'>");
		document.write("<p ID='Y2' class=CalYearTitle onMouseOver='style.cursor=\"hand\"; event.returnValue=0;event.cancelBubble = true;'" +
					" onClick='showSelector(DateSelector, MonthSelector);'>");
		document.write(aYear);
		document.write("</p></td>");

		document.write("<td width='34%' align='center'>");
		document.write("<p ID='I2' class=CalArrows onMouseOver='style.cursor=\"hand\"; event.returnValue=0;event.cancelBubble = true;'" +
					" onClick='incrementYear(Y2);'>");
		document.write("\>");
		document.write("</p></td>");
		
	document.write("</tr>");
	
	document.write("<tr>");
	    writeMonth("Jan", 1, theYear);
	    writeMonth("Feb", 2, theYear);
	    writeMonth("Mar", 3, theYear);
	document.write("</tr>");
	document.write("<tr>");
		writeMonth("Apr", 4, theYear);
		writeMonth("May", 5, theYear);
		writeMonth("Jun", 6, theYear);
	document.write("</tr>");
	document.write("<tr>");
		writeMonth("Jul", 7, theYear);
		writeMonth("Aug", 8, theYear);
		writeMonth("Sep", 9, theYear);
	document.write("</tr>");
	document.write("<tr>");
		writeMonth("Oct", 10, theYear);
		writeMonth("Nov", 11, theYear);
		writeMonth("Dec", 12, theYear);
	document.write("</tr>");
	document.write("</table>");
	
	document.write("</div>");
}

function writeMonth(aMonthName, aMonthIndex, aYear) {

	 monthYear = (aMonthIndex) + "/" + (aYear);
	 
	 document.write("<td width='33%' align='center'>");
	 document.write("<p class=CalMonth onMouseOver='style.cursor=\"hand\"; event.returnValue=0;event.cancelBubble = true;'" +
					" onClick='jumpToPage(" + aMonthIndex + ");'>");
	 
	 document.write(aMonthName);
	 document.write("</p>");
	 document.write("</td>");

}

function showSelector(aHiddenSelector, aVisibleSelector) {
	aVisibleSelector.style.display = 'none';
	aHiddenSelector.style.display='';
}

function incrementYear(aYearLabel) {
	theYear = theYear + 1;
	aYearLabel.innerText = theYear;
}

function decrementYear(aYearLabel) {
	theYear--;
	aYearLabel.innerText = theYear;
}

function jumpToPage(aMonthIndex) {
	window.location = mainPage + "Month=" + aMonthIndex + "&Year=" + theYear;
}//</script>