

var months = new Array ("January", "February", "March",
			"April", "May", "June", "July", "August", "September",
			"October", "November", "December");
var daysInMonth = new Array (31, 28, 31, 30, 31, 30, 31, 31,
					30, 31, 30, 31);
var today = new Date();
var highlightedCellId = "";	// id of the cell that is currently highlighted
var calendarOutputFieldId = "";	// id of the text box where the selected
								// date from the calendar will be written to

// makes the calendar visible after populating it with either
// today's date (if the text box for which the calendar is being
// displayed does not contain a date) or with the date in the
// text box for which the calendar is being displayed.
function showElement1 (elementId)
{
	// initialize the calendar
	var textObj = eval ("document.all." + calendarOutputFieldId);
	var currTextObjValue = textObj.value;
	if ((currTextObjValue == "") ||
		(currTextObjValue.length != 8) ||
		(isNaN (currTextObjValue)))
	{
		populateCalendar (today);
	}
	else
	{
		var yr = currTextObjValue.substring (0, 4);
		var mon = new Number (currTextObjValue.substring (4, 6)) - 1;
		var dt = currTextObjValue.substring (6, 8);
		var currDate = new Date (yr, mon, dt);
		populateCalendar (currDate);
	}
	
	leftWidthAvail = event.clientX +100 ;
    rightWidthAvail = document.body.clientWidth - event.clientX;
  
    TopHeightAvail = event.clientY +100;
    BottomHeightAvail = document.body.clientHeight - event.clientY;
  
    if (eval ("(rightWidthAvail - document.all." + elementId + 
   									".offsetWidth) > 0"))
       	x = event.clientX + document.body.scrollLeft;
    else if (eval ("event.clientX - document.all." + elementId + 
   								".offsetWidth > 0"))
   		eval ("x = event.clientX - document.all." + elementId + 
   									".offsetWidth + document.body.scrollLeft");
   	else
   		x = document.body.scrollLeft;
    if (eval ("(BottomHeightAvail - document.all." + elementId +
   									".offsetHeight) > 0"))
       	y = event.clientY + document.body.scrollTop;
    else if (eval ("event.clientY - document.all." + elementId +
   									".offsetHeight > 0"))
   		eval ("y = event.clientY - document.all." + elementId +
   									".offsetHeight + document.body.scrollTop");
	else
   		y = document.all.scrollTop;
   	eval (elementId + ".style.left = " + x)
   	eval (elementId + ".style.top = " + y)
   	eval (elementId + ".style.visibility = \"visible\"")		
}

// makes the given element inivisible
function hideElement (elementId)
{
   	eval (elementId + ".style.visibility = \"hidden\"")
}

// takes a month (should be one of the entries in the months array
// above) and returns the previous month (exhibits cyclic
// behavior)
function getPrevMonth (currMonth)
{
	for (i=0; i < months.length; i++)
	{
		if (months[i] == currMonth)
			break;
	}	
	if (i == 0)
	{
		return (months[months.length-1]);
	}
	else
	{
		return (months[i-1]);
	}
}

// takes a month (should be one of the entries in the months array
// above) and returns the next month (exhibits cyclic
// behavior)
function getNextMonth (currMonth)
{
	for (i=0; i < months.length; i++)
	{
		if (months[i] == currMonth)
		{
			break;
		}
	}	
	if (i == months.length-1)
	{
		return (months[0]);
	}
	else
	{
		return (months[i+1]);
	}	
}

// takes a year and returns the previous year
function getPrevYear (currYear)
{
	yr = new Number (currYear);
	return (yr-1);
}

// takes a year and returns the next year
function getNextYear (currYear)
{
	yr = new Number (currYear);
	return (yr+1);
}

// Takes a month (integer, with 0 being January and so on..)
// and a year and returns the number of days in that month.
function getDays (month, year) 
{
   // Test for leap year when February is selected.
   if (month == 1)
      return ((0 == year % 4) && (0 != (year % 100))) ||
         (0 == year % 400) ? 29 : 28;
   else
      return daysInMonth[month];
}

// populates our calendar to display the specified date.
function populateCalendar (dateObject)
{
	if (highlightedCellId != "")
	{
		unhighlightThis (eval (highlightedCellId));
	}
	
	var mon = dateObject.getMonth();
	month.innerText = months[dateObject.getMonth()];
	
	var yr = dateObject.getYear();
	if (yr < 100)
	{
		yr += 1900;
	}
	year.innerText = yr;	
	
	var numOfDays = getDays (mon, yr);
	var dayOfWeek = new Date (yr, mon, 1).getDay();
	for (i=0, j=1; i < 42; i++, j++)
	{		
		if ((i >= dayOfWeek) && (j <= numOfDays))
		{
			eval ("date_" + i + ".innerText = j");						
		}
		else
		{
			eval ("date_" + i + ".innerText = ''");
			j--;
		}
	}
	
	// If the textbox for which this calendar is being
	// displayed contains a date and if the user is viewing
	// the calendar for the same month, then highlight
	// that date.
	// If the textbox does not contain a date, then highlight
	// today's date.
	var textObj = eval ("document.all." + calendarOutputFieldId);
	var currTextObjValue = textObj.value;
	if ((currTextObjValue == "") &&
		(yr == today.getYear()) &&
		(mon = today.getMonth()))
	{
		var dateId = eval ("date_" + (dayOfWeek+today.getDate()-1));
		highlightThis (dateId);
		highlightedCellId = dateId;
	}
	else
	{
		var curryr = currTextObjValue.substring (0, 4);
		var currmon = new Number (currTextObjValue.substring (4, 6)) - 1;
		if ((curryr == yr) && (currmon == mon))
		{
			var currdt = currTextObjValue.substring (6, 8);
			var currDate = new Date (yr, mon, currdt);
			var firstOfMonth = new Date (yr, mon, 1);
			var dayOfWeek = firstOfMonth.getDay();			
			var obj = eval ("date_" + (currDate.getDate()+dayOfWeek-1));			
			highlightThis (obj);
			highlightedCellId = "date_" + (currDate.getDate()+dayOfWeek-1);			
		}
	}
}

// highlights a given date cell
function highlightThis (ele)
{
	if (highlightedCellId != "")
	{
		unhighlightThis (eval (highlightedCellId));
	}
	if (ele.innerText != '')
	{
		if (ele.className.indexOf ('date') != -1)
		{
			ele.className = 'dateOn';
		} 
		else
		{
			ele.className = 'buttonStyleOn';
		}
	}
	else
	{	
		if (ele.className.indexOf ('date') != -1)
		{
			ele.className = 'dateOff';
		} 
		else
		{
			ele.className = 'buttonStyleOff';
		}
	}
}

// unhighlights a given date cell
function unhighlightThis (ele)
{
	if (ele.className.indexOf ('date') != -1)
	{
		ele.className = 'dateOff';
	} 
	else
	{
		ele.className = 'monthOff';
	}
}

// calls populateCalendar with the date object being the
// 1st day of the month and the year that the user has chosen
function displayCalendar()
{
	var str = month.innerText + " 1, " + year.innerText;	 
	var date = new Date (str);
	populateCalendar (date);
}

// this is the method that needs to be customized to take
// any appropriate action when the user clicks a particular date.
function returnDate()
{
var str = month.innerText + " " + event.srcElement.innerText + ", " + year.innerText;	 
	var date = new Date (str);
	var dateStr = year.innerText;
	//var dateStryr = ""
	if (date.getMonth()+1 < 10)
	{
		dateStr += "0";
	}
	dateStr += date.getMonth()+1;
        //alert(dateStr);  
	if (event.srcElement.innerText.length == 1)
	{
		dateStr += "0";
	}
	dateStr += event.srcElement.innerText;
        //alert(dateStr);
	var textObj = eval ("document.all." + calendarOutputFieldId);
        //alert(dateStr);
         dateStryr = dateStr.substring(0,4)
         dateStrdt = dateStr.substring(6,8)
         dateStrmn = dateStr.substring(4,6)
        
         //alert(dateStrmn);
         //alert (dateStrdt);
         //alert(dateStryr);
         
         
	textObj.value = dateStrmn+"/"+dateStrdt+"/"+dateStryr;
	hideElement ('Calendar');

}

// clears the contents of the text box for which the calendar was
// displayed and also hides the calendar.
function clearDate()
{
	var textObj = eval ("document.all." + calendarOutputFieldId);
	textObj.value = "";
	hideElement ('Calendar');
}
// end of calendar.js

/*
		<!-- Before using this calendar make sure that the following ids are not
		used elsewhere in the HTML file:
		1) month
		2) year
		3) Calendar
		4) date_XX (XX from 0 to 41)
		//-->
*/	
//document.write('<Style><!-- .mothRow {color:red;}  --> </Style>')	
document.write('<DIV ID="Calendar" CLASS="popupCalendar">')
document.write('			<TABLE WIDTH="150">')
document.write('				<TR CLASS="monthRow">')
document.write('					<TD WIDTH="25" ALIGN="LEFT">')
document.write('						<IMG SRC="./images/leftArrow.gif" STYLE="{cursor: hand}" ')
document.write('						ONCLICK="month.innerText=getPrevMonth(month.innerText); displayCalendar()">')
document.write('					</TD>')
document.write('					<TD WIDTH="100"  ID="month" ALIGN="CENTER" color=blue></TD>')
document.write('					<TD WIDTH="25" ALIGN="RIGHT">')
document.write('						<IMG SRC="./images/rightArrow.gif" STYLE="{cursor: hand}" ')
document.write('						ONCLICK="month.innerText=getNextMonth(month.innerText); displayCalendar()">')
document.write('					</TD>')
document.write('				</TR>')
document.write('				<TR CLASS="yearRow">')
document.write('					<TD ALIGN="LEFT">')
document.write('						<IMG SRC="./images/leftArrow.gif" STYLE="{cursor: hand}" ')
document.write('						ONCLICK="year.innerText=getPrevYear(year.innerText); displayCalendar()">')
document.write('					</TD>')
document.write('					<TD ID="year" ALIGN="CENTER"></TD>')
document.write('					<TD ALIGN="RIGHT">')
document.write('						<IMG SRC="./images/rightArrow.gif" STYLE="{cursor: hand}" ')
document.write('						ONCLICK="year.innerText=getNextYear(year.innerText); displayCalendar()">')
document.write('					</TD>')
document.write('				</TR>')
document.write('			</TABLE>')
document.write('			<TABLE WIDTH="150">')
document.write('				<TR CLASS="dayRow">')
document.write('					<TD>Su</TD>')
document.write('					<TD>Mo</TD>')
document.write('					<TD>Tu</TD>')
document.write('					<TD>We</TD>')
document.write('					<TD>Th</TD>')
document.write('					<TD>Fr</TD>')
document.write('					<TD>Sa</TD>')
document.write('				</TR>		')
document.write('				<TR>')
document.write('					<TD ID="date_0" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_1" CLASS="dateOff"ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_2" CLASS="dateOff"ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_3" CLASS="dateOff"ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_4" CLASS="dateOff"ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_5" CLASS="dateOff"ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_6" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>')
document.write('				<TR>')
document.write('					<TD ID="date_7" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_8" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_9" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_10" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_11" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_12" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_13" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>')
document.write('				<TR>')
document.write('					<TD ID="date_14" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_15" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_16" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_17" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_18" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_19" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_20" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>')
document.write('				<TR>')
document.write('					<TD ID="date_21" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_22" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_23" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_24" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_25" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_26" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_27" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>')
document.write('				<TR>')
document.write('					<TD ID="date_28" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_29" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_30" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_31" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('                <TD ID="date_32" CLASS="dateOff" ONCLICK="returnDate()" ')

document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_33" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_34" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>')
document.write('				<TR>')
document.write('					<TD ID="date_35" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_36" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_37" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_38" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_39" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_40" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('					<TD ID="date_41" CLASS="dateOff" ONCLICK="returnDate()"')
document.write('					ONMOUSEOVER="highlightThis(this)" ONMOUSEOUT="unhighlightThis(this)"></TD>')
document.write('				</TR>	')
document.write('			</TABLE>')
document.write('			<TABLE WIDTH="150">')
document.write('			  <TR CLASS="monthRow">   ')
document.write('			  <TD>')
document.write('			    <SPAN CLASS="calButtonStyleOff" STYLE="{width: 80}"')
document.write('			    ONMOUSEOVER="this.className=\'calButtonStyleOn\'" ')
document.write('			    ONMOUSEOUT="this.className=\'calButtonStyleOff\'" ')
document.write('			    ONCLICK="clearDate()">')
document.write('			      Clear Date')
document.write('			    </SPAN>')
document.write('			    <SPAN STYLE="{width: 10}"></SPAN>')
document.write('			    <SPAN CLASS="calButtonStyleOff" STYLE="{width: 50}"')
document.write('			    ONMOUSEOVER="this.className=\'calButtonStyleOn\'" ')
document.write('			    ONMOUSEOUT="this.className=\'calButtonStyleOff\'"')
document.write("			    ONCLICK=hideElement('Calendar')> ")
document.write('			      Cancel')
document.write('			    </SPAN> ')
document.write('			  </TD>')
document.write('			</TABLE>	')
document.write('		</DIV>')