

	currDate = new Date();
	currMonth = currDate.getMonth();
    currYear = currDate.getFullYear();
	todayDate = new Date(); // only curtrent month/year should flagged with todays day
	todayDay = todayDate.getDate()
	todayMonth = todayDate.getMonth();
	todayYear = todayDate.getFullYear();
	eventList = new Array("",
					//	  "08302009-0820091",
					//	  "09132009-0920091",
					//	  "09242010-0920104",
					//	  "12182010-1220105",
					//	  "12052010-1220103",
					//	  "03192011-0320111",
					//	  "03202011-0320111",
					//	  "03252011-0320112",
					//	  "03262011-0320112",
					//	  "03272011-0320112",
					//	  "04082011-0420111",
					//	  "04092011-0420111",
					//	  "04102011-0420111",
					//	  "04152011-0420112",
					//	  "04162011-0420112",
					//	  "04172011-0420112",
					//	  "04292011-0420113",
					//	  "04302011-0420113",
					//	  "04162011-0420114",
					//	  "04302011-0420115",
					//	  "05012011-0420115",
					//	  "05102011-0520111",
					//	  "05142011-0520112",
					//	  "05222011-0520113",
					//	  "05282011-0520114",
					//	  "05292011-0520114",
					//	  "05292011-0520115",
					//	  "05302011-0520115",
					//	  "05062011-0520117",
					//	  "05072011-0520117",
					//	  "06052011-0620111",
					//	  "06112011-0620112",
					//	  "06122011-0620112",
					//	  "07302011-0720111",
					//	  "07312011-0720111",
					//	  "08062011-0820111",
					//	  "08072011-0820111",
					//	  "08132011-0820112",
					//	  "08282011-0820113",
					//	  "08192011-0820114",
					//"09032011-0920117",
					//"09042011-0920117",
					//"09052011-0920117",
						//  "09102011-0920111",
						//  "09112011-0920111",
						//  "09242011-0920115",
						//  "09252011-0920115",
						//  "09172011-0920116",
						//  "09182011-0920116",
						//  "09232011-0920118",
						//  "10012011-1020111",
						//  "10022011-1020111",
						//  "10142011-1020112",
						//  "10152011-1020112",
						//  "10162011-1020112",
						  //"11052011-1120111",
						  //"11112011-1120112",
						  //"11122011-1120112",
						  //"11132011-1120112",
						  //"11202011-1120115",
						  "12032011-1220111",
						  "12042011-1220112",
						  "12102011-1220113",
						  "12112011-1220113",
						  "12182011-1220117",
						//  "11252011-1120113",
						//  "11262011-1120113",
						//  "11272011-1120113",
					'')
	;
	//alert(eventList[0].substring(9,16));
	
	function calendaradd(){
		cdate = new Date();
		if (currMonth<11) currMonth++
		else {
			currMonth = 0;
			currYear++;
		}
		calendar(monthName[currMonth]+ " " +todayDay+", "+currYear);
		
	}
	
	function calendarsub(){
		if (currMonth>0) currMonth--
		else {
			currMonth = 11;
			currYear--;
		}
		calendar(monthName[currMonth]+ " " +todayDay+", "+currYear);
		
	}

	function trimNumber(s) {
	  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  	  return s;
	}
	
	function checkEvents(currDate){
		for (i=0; i<eventList.length; i++){
			if (currDate.getDate() == trimNumber(eventList[i].substring(2,4))&&
	            currDate.getMonth() + 1 == trimNumber(eventList[i].substring(0,2))&&
				currDate.getFullYear() == eventList[i].substring(4,8)) return i;
		}
		return 0;
	}

	function calendar(calendarDay){

	if (calendarDay == null) calDate = new Date()
	else calDate = new Date(calendarDay);
	calstr = '<form class="calendar_button"><input type="button" onClick="calendarsub()"  value="Prev"/>'+
			 '<input type="button" onClick="calendaradd()"  value="Next"/></form>' +
			 "<table id='calendar_table'>";
	writeCalTitle(calDate);
	writeDayNames();
	writeCalDays(calDate);
	document.getElementById("calendar").innerHTML = calstr;
}

function writeCalTitle(calendarDay){
	monthName = new Array("January","February","March","April","May","June","July","August","September",
	                          "October","November","December");
    thisMonth = calendarDay.getMonth();
    thisYear = calendarDay.getFullYear();
    
	calstr += "<tr>" +  "<th id='calendar_head' colspan='7'>" + monthName[thisMonth]+" "+thisYear + "</th>" + "</tr>";
    //document.write("<tr>");
    //document.write("<th id='calendar_head' colspan='7'>");
    //document.write(monthName[thisMonth]+" "+thisYear);
    //document.write("</th>");
    //document.write("</tr>");
}

function writeDayNames(){
	var dayName = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	calstr += "<tr>"; 
	//document.write("<tr>");
	for (var i=0; i<dayName.length; i++){
		calstr += "<th class = 'calendar_weekdays'>"+dayName[i]+"</th>";
		//document.write("<th class = 'calendar_weekdays'>"+dayName[i]+"</th>");
	}
	calstr += "</tr>"; 
	//document.write("</tr>");
}

function daysInMonth(calendarDay){
	var thisYear = calendarDay.getFullYear();
	var thisMonth = calendarDay.getMonth();
	var dayCount = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if (thisYear % 4 == 0){
		if ((thisYear % 100 != 0) || (thisYear % 400 == 0)){
			dayCount[1] = 29; // adjust for leap year
		}
	}		
	return dayCount[thisMonth]; // returns the number of days in the month.
}

function writeCalDays(calendarDay){

	// determine the starting day of the week	
	var dayCount = 1;
	var currentDay = calendarDay.getDate();
	var totalDays = daysInMonth(calendarDay);
	calendarDay.setDate(1); // set the day to be the first day of the month to retrieve the day in week.
	var weekDay = calendarDay.getDay();
	
	// write blank cells preceding the starting day
	
	calstr += "<tr>"; 
	//document.write("<tr>");
	for (var i=0; i < weekDay; i++){
		calstr += "<td></td>";
		//document.write("<td></td>");
	}
	// write cells for each day of the month
	
	while (dayCount <= totalDays){
		// write the table rows and cells
		
		if (weekDay == 0) calstr += "<tr>";
	    //if (dayCount == 3 && currMonth == 8 && currYear == 2009) {
		if (checkEvents(calendarDay)) {
			calstr += "<td class='calendar_dates' id='calendar_event'>"+"<a href='#"+
			eventList[checkEvents(calendarDay)].substring(9,16)+
			"'>"+dayCount+"</a>"+"</td>";
		}
		else if (dayCount != currentDay || todayMonth != currMonth || todayYear != currYear){
			calstr += "<td class='calendar_dates'>"+dayCount+"</td>";
			//document.write("<td class='calendar_dates'>"+dayCount+"</td>");
		} 
		else {
		// highlight the current date
			calstr += "<td class='calendar_dates' id='calendar_today'>"+dayCount+"</td>";
			//document.write("<td class='calendar_dates' id='calendar_today'>"+dayCount+"</td>");
		}
		
		if (weekDay == 6) calstr += "</tr>"; 
		
		// move to the next day
		
		dayCount++;
		calendarDay.setDate(dayCount);
		weekDay = calendarDay.getDay();
	}
	calstr += "</tr>";
	//document.write("</tr>");
}
