/*
   Author: jgf
    Date:   09/18/06


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
	  
stringReverse
      Used to reverse the order of characters in a text string
	  
showem
	  shows email as clickable link	
*/
function calendar(calendarDay) {
//to make calendar for today's date 
	if (calendarDay == null) calDate= new Date()
	else calDate = new Date(calendarDay); 
		document.write("<table id= 'calendar_table'>");
		writeCalTitle(calDate);
		writeDayNames();
		writeCalDays(calDate);
	document.write ("</table>")
	}
/*function calendar() {
//to make calendar for ap particular day 
	var calDate = new Date("May 18,2007");
		document.write("<table id= 'calendar_table'>");
		writeCalTitle(calDate);
		writeDayNames();
		writeCalDays(calDate);
	document.write ("</table>")
	}
*/
function writeCalTitle(calendarDay) {
		var monthName = new Array("January","February","March", "April","May","June","July","August","September", "October", "November", "December");
		var thisMonth= calendarDay.getMonth();
		var thisYear= calendarDay.getFullYear();
		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");
	document.write("<tr>");
		for (var i=0; i<dayName.length; i++){
			document.write("<th class = 'calendar_weekdays'>"+dayName[i]+"</th>");
		}
			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; //calculate the leap year
		}
	}
		return dayCount[thisMonth]; //return the number of days in the month
}	
function writeCalDays(calendarDay){
	var currentDay=calendarDay.getDate(); //set today;s date 
		//determine the starting day of the week
		var dayCount=1;
		var totalDays = daysInMonth(calendarDay);
		calendarDay.setDate(1);  //set the date to the first of the month
		var weekDay= calendarDay.getDay(); //the day of the week of the first of the month
			//write blank cells preceeding the first of the month
			document.write("<tr>");
			for (var i=0; i<weekDay; i++){
			document.write("<td></td>");
			}
	// write cells for each day of the month
	while (dayCount<=totalDays) {
	//write the table rows and cells
	if (weekDay==0) document.write("<tr>");
			if (dayCount==currentDay) {
			//highlight today's date 
	document.write("<td class='calendar_dates' id ='calendar_today'>"+dayCount+"</td>");
			}
			else {document.write("<td class = 'calendar_dates'>"+dayCount+"</td>");}
		if(weekDay==6) document.write ("</tr>");
	//move to the next day
	dayCount++;
	calendarDay.setDate (dayCount);
	weekDay = calendarDay.getDay();
	}
}

function stringReverse(textString) {
   if (!textString) return '';
   var revString='';
   for (i = textString.length-1; i>=0; i--)
       revString+=textString.charAt(i)
   return revString;
}
function showEm (userName, emServer){
	userName = stringReverse(userName);
	emServer = stringReverse(emServer); 
	var emLink = userName+ "@"+emServer;
	document.write("<a href= 'mailto:"+emLink+" '>");
	document.write(emLink);
	document.write("</a>");
	}

