function getMonthNumber(input)
{
if (input == "Jan")
	{return "1"}
if (input == "Feb")
	{return "2"}
if (input  == "Mar")
	{return "3"}
if (input  == "Apr")
	{return "4"}
if (input  == "May")
	{return "5"}
if (input  == "Jun")
	{return "6"}
if (input == "Jul")
	{return "7"}
if (input  == "Aug")
	{return "8"}
if (input  == "Sep")
	{return "9"}
if (input  == "Oct")
	{return "10"}
if (input == "Nov")
	{return "11"}
if (input  == "Dec")
	{return "12"}
}


// Checks if browser is Netscape 2.0 since the options array properties don't work with Netscape 2.0x
function isBrowserSupp() {

    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
        return true;
    }                  
}


function isLeapYear(yr)
{
var leapYear=false;
// every fourth year is a leap year unless it's 100 th year unless it's 400 year
if ((yr%4) == 0 )
	{
	leapYear=true;
	}
return leapYear;
}


function getDaysInMonth(mth, Yr)
{
// all the rest have 31
var maxDays=31
// expect Feb. (of course)
if (mth==2) 
	{
	if (isLeapYear(Yr))
		{
		maxDays=29;
		}
	else 
		{
		maxDays=28;
		}
	}
// thirty days hath...
if (mth==4 || mth==6 || mth==9 || mth==11)
	{
	maxDays=30;
	}
return maxDays;
}
//the function which does some magic to the date fields
function adjustDate(mth, day, Yr) 
{
var value=0; 		
var numDays=getDaysInMonth(mth, Yr);

if (day < numDays)
	{
	return day;
	}
else 
	{
	return numDays;
	}
}


function parseMonth(mth, inM)
{
var i=1;
var retval =1;
for (i=1;i<=12;i++)
	{
	if (mth == inM.options[i].text)
		{
		retval=i;	
		break;
		}	
	}
	return retval;
}

function parseDay(day, inD)
{
var i=1;
var retval =1;
for (i=1;i<=31;i++)
	{
	if (day == inD.options[i].text)
		{
		retval=i;	
		break;
		}	
	}
return retval;
}

function parseYear(year, inY)
{
var retval=0;
var i=0;
     for (i=0; i<=5; i++)
     {
   
	if (year == inY.options[i].text)
		{
		retval=i;	
		break;
		}	
     }
return retval;
}

//Calendar Section

//calculation functions
function nextMonth(month) 
{
if (month==12)
	{
	return 1;
	}
else
	{
	return (month+1);
	}
}


function prevMonth(month) 
{
var prevMonth = (month-1)
if (month==1)
	{
	prevMonth = 12;
	}
return prevMonth
}

//increments or decrements month when it goes past Jan or Dec
function changeYear(direction,month,year)
{
var theYear = year
if (direction=="next")
	{
	if (month == 12)
		{
		theYear = (year+1)
		}
	}
if (direction=="prev")
	{
	if (month == 1)
		{
		theYear = (year-1)
		}
	}
return theYear
}


//opens a new window for the calendar
function createCalendar(month,io) 
{
var theDate = new Date(month);
var theMonth = theDate.getMonth() + 1;
var theDay = theDate.getDate() ;
var theYear = theDate.getFullYear();
if (!isBrowserSupp())
	{
	alert("Your browser is outdated and does not support this feature")
 	return;
	}
if (navigator.appVersion.indexOf("Mac",0) != -1) 
	{
    	calendarWindow = window.open("","Calendar","width=230,height=205,resizable=yes,scrollbars=no");
  	} 
else 
	{
	calendarWindow = window.open("","Calendar","width=230,height=285,resizable=yes,scrollbars=no");
  	}
if (isNaN(theDate))
{
var today = new Date();
var thisyear = today.getFullYear();
var thismonth = today.getMonth() + 1;
theMonth = thismonth;
theYear = thisyear;
theDay = today.getDate()
}
//call the function to populate the window
generateCalendar(calendarWindow,theMonth,theDay,theYear,io)
}


//generates the meat of the calendar
function generateCalendar(target,month,day,year,io) 
{
if (!isBrowserSupp())
	{
 	return;
	}	
var monthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")

//begin table for calendar
target.document.open()
calendar = "<html><head><title>calendar</title></head><body bgcolor=ffffff>"
calendar +="<table border=0 cellspacing=0 cellpadding=4 width=200>"
calendar +="<tr valign=top>"

var mthIdx = month;
var endday = getDaysInMonth(mthIdx, year)

//month header
calendar +="<td colspan=7 align=center bgcolor=#C0C0C0>"
var index = (mthIdx-1)
calendar +="<b><font face='Helvetica,Arial,Futura'>" + monthName[index] + " " + year + "</font></b></td></tr>"

//writes in the day of the week labels
calendar +="</tr><tr align=center>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#FF0000'>&nbsp;<b>S</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura'>&nbsp;<b>M</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura'>&nbsp;<b>T</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura'>&nbsp;<b>W</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura'>&nbsp;<b>T</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura'>&nbsp;<b>F</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#FF0000'>&nbsp;<b>S</b></font></td>"
calendar +="</tr>"
if (day != 0)
	{
	origyear = year
	origday = day
	origmonth = month
}
wholeDate = month + "/01/" + year
thedate = new Date(wholeDate)
firstDay = thedate.getDay()

selectedmonth = mthIdx;
var today = new Date();
var thisyear = today.getYear();
var thismonth = today.getMonth() + 1;
selectedyear = year
var lastDay = (endday + firstDay+1)
calendar +="<tr>"
for (var i = 1; i < lastDay; i++)
	{
	if (i <= firstDay)
		{
		// 'empty' boxes prior to first day
		calendar +="<td>&nbsp;</td>"
		}
	else 
		{
		// enter date number
		if (selectedyear == origyear && selectedmonth == origmonth && i-firstDay == origday)  
			{
				calendar +="<td align=center><a href='JavaScript:self.close();opener.closeCalendar"+io+"("+selectedmonth + ","+(i-firstDay)+","+ selectedyear + ")' style='color: rgb(255,0,0)' > "+(i-firstDay)+"</a></td>"
			}
		else
			{
				calendar +="<td align=center><a href='JavaScript:self.close();opener.closeCalendar"+io+"("+selectedmonth + ","+(i-firstDay)+","+ selectedyear + ")'> "+(i-firstDay)+"</a></td>"
			}
		}
	//must start new row after each week
	if (i % 7 == 0 &&  i != lastDay)
		{
		calendar +="</tr><tr>"
		}
	}
calendar +="</tr>"

//separator line
calendar +="<tr><td colspan=7 align=center width=200><hr noshade></td></tr>"

//next month and previous month buttons
var goPrevMonth = prevMonth(mthIdx)
var goNextMonth = nextMonth(mthIdx)
var nextYear = changeYear("next",month,year)
var prevYear = changeYear("prev",month,year)

if(navigator.userAgent.indexOf('MSIE',0) != -1)
	{
	calendar +="<tr><td align=left colspan=3 bgcolor=#A7CCDC><a href='javascript:opener.generateCalendar(self,"+goPrevMonth+",0,"+prevYear+",\""+io+"\")'>prev</a></td>"
	calendar +="<td align=center colspan=1 bgcolor=#A7CCDC>&nbsp;</td>"
	calendar +="<td align=right colspan=3 bgcolor=#A7CCDC><a href='javascript:opener.generateCalendar(self,"+goNextMonth+",0,"+nextYear+",\""+io+"\")'>next</a></td></tr>"
	calendar +="</table></body></html>"
	target.document.close()
	}
else
	{
	calendar +="<form><tr><td align=left colspan=3 bgcolor=#A7CCDC><input type=button value=' < '"+
"onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goPrevMonth+",0,"+prevYear+",\""+io+"\")'></td>"
	calendar +="<td align=center colspan=1 bgcolor=#A7CCDC>&nbsp;</td>"
	calendar +="<td align=right colspan=3 bgcolor=#A7CCDC><input type=button value=' > '"+
"onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goNextMonth+",0,"+nextYear+",\""+io+"\")'></td></tr></form>"
	calendar +="</table></body></html>"
	}
target.document.write(calendar);
target.document.close()	
}
