var ns6=document.getElementById&&!document.all
var ie4=document.all
var icur_month;
var icur_year;

function LeapYear(cur_year)
{
	return (cur_year % 4 == 0);
}


function DaysPerMonth(cur_month, cur_year)
{
	var dm = new Array(12);
	dm[0] = 31; 
	dm[1] = (LeapYear(cur_year)) ? 29 : 28;
	dm[2] = 31;
	dm[3] = 30;
	dm[4] = 31;
	dm[5] = 30;
	dm[6] = 31;
	dm[7] = 31;
	dm[8] = 30;
	dm[9] = 31;
	dm[10] = 30;
	dm[11] = 31;

return dm[cur_month];
}


function getMonthName(cur_month)
{
	if(cur_month > 11)
	{ cur_month=0; }
	if(cur_month < 0)
	{ cur_month=11; }
        var dm = new Array(12)
        dm[0] = "January";
        dm[1] = "February";
        dm[2] = "March";
        dm[3] = "April";
        dm[4] = "May";
        dm[5] = "June";
        dm[6] = "July";
        dm[7] = "August";
        dm[8] = "September";
        dm[9] = "October";
        dm[10] = "November";
        dm[11] = "December";

return dm[cur_month];
}

function DayofWeek(cur_day)
{
	var wkd = new Array(7)
	wkd[0] = "S";
	wkd[1] = "M";
	wkd[2] = "T";
	wkd[3] = "W";
	wkd[4] = "T";
	wkd[5] = "F";
	wkd[6] = "S";

return wkd[cur_day];
}

function getCurMonth()
{
	var date = new Date();
	var cur_month = date.getMonth();

return cur_month;
}

function getCurDay()
{
	var date = new Date();
	var cur_day = date.getDay();

return cur_day;
}

function getCurYear()
{
	var date = new Date();
	var cur_year = date.getFullYear();

return cur_year;
}

function getCurDate()
{
	var date = new Date();
	var cur_date = date.getDate();
	
return cur_date;
}
 
function FirstDay(cur_year, cur_month)
{
	var firstDayInstance = new Date(cur_year, cur_month, 1);
	var firstDay = firstDayInstance.getDay();
	
return firstDay;
}

function setDateVals()  
{
  cur_year = getCurYear();
  cur_month = getCurMonth();
  icur_year = getCurYear();
  icur_month = getCurMonth()+1;
  //if (icur_month < 10)
  //{
	//icur_month='0' + icur_month;
  //}

  DrawCalendar(cur_month, cur_year, icur_month, icur_year);	
}

function DrawCalendar(cur_month, cur_year, icur_month, icur_year)
{
	//Get function values
	var cur_day = getCurDay();
	var cur_month_name = getMonthName(cur_month);
	var cur_date = getCurDate();
	var firstDay = FirstDay(cur_year, cur_month);
	var counter = 0;
	var counter2 = 1;
	var text = "";
	
	text += '<TABLE BORDER=1  CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#000000"><TR><TD>';
	text += '<TABLE BORDER=0 CELLSPACING="0" BGCOLOR="#EEEEEE">';
	text += '<TR><TD BGCOLOR="#6700A3" ALIGN="LEFT"><a href="javascript:drawPrevMonth()"><img border="0" src="images/Other/arrowL-white.gif" width="8" height="11" alt="View ' + getMonthName(cur_month-1)+ '"></a></TD>';
	text += '<TD COLSPAN="5" ALIGN="CENTER" BGCOLOR="#6700A3"><FONT COLOR="#FFFFFF"><B>' + cur_month_name + ' ' + cur_year + '</B></FONT></TD>';
	text += '<TD BGCOLOR="#6700A3" ALIGN="RIGHT"><a href="javascript:drawNextMonth()"><img border="0" src="images/Other/arrowR-white.gif" width="8" height="11" alt="View ' + getMonthName(cur_month+1) + '"></a></TD></TR>'
	text += '<TR>';

	// loop through day headers
	for (var num = 0; num <7; num++)
	{
		text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0 BGCOLOR="#FFFFEE">' + DayofWeek(num) + '</TD>';
	}
	text +='</TR>'; 

	// loop through number of rows
	for(var row = 1;  row <= Math.ceil((DaysPerMonth(cur_month, cur_year) + firstDay + 1) / 7); ++row)
	{
		text += '<TR>';
		
		// loop through each individual row
		for(var col = 0; col <7; col++)
		{
			// stops the counter at last day of the month
			if(counter2 > DaysPerMonth(cur_month, cur_year)) {break;}
			
			// sets blank cells in table before the 1st of the month
			if(counter < firstDay)
			{
				text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0>&nbsp;</TD>';
				counter++;
			}
			else if(counter==firstDay)
			{
				// highlights today's date
				if(counter2 == cur_date)
				{
					text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0 BGCOLOR="#FFFF00"><B>';
					// display calendar without each day being a link
					// text +=  + counter2 + '</B></TD>';
					// display calendar with each day being a link
					text += '<a href="WeeklySchedule.aspx?sToday=' + icur_month + '/' + counter2 + '/' + icur_year + '">' + counter2 + '</a></B></TD>';
					counter2++;
					continue;
				}

				text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0>';
				// display calendar without each day being a link
				// text += counter2 + '</TD>';
				// display calendar with each day being a link
				text += '<a href="WeeklySchedule.aspx?sToday=' + icur_month + '/' + counter2 + '/' + icur_year + '">' + counter2 + '</a></TD>';
				counter2++;
			}
			else if(counter2 == cur_date)
			{
				text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0><B>';
				text += counter2 + '</B></TD>';
				counter2++;
			}
			else
			{
					text += '<TD WIDTH=20 HEIGHT=20 ALIGN="CENTER" VALIGN="TOP" BORDER=0>';
					text += counter2 + '</TD>';
					counter2++;
			}
		}
		text += '</TR>';	
	}
   // prints out calendar (text variable) to the screen
	cross_el=ns6? document.getElementById("Calendar") : document.all.Calendar
   cross_el.innerHTML = text;
}

function drawPrevMonth()  // display the next calendar month
{
	if (cur_month == 0)
	{
		cur_year--;
		icur_year=cur_year;
		cur_month = 11;
		icur_month=12;
    }
	else
	{
		cur_month--;
		icur_month=cur_month+1;
	}
	//if (icur_month < 10)
	//{
	//	icur_month='0' + icur_month;
	//}
	DrawCalendar(cur_month, cur_year, icur_month, icur_year);
  }

function drawNextMonth()  // display the next calendar month
  {
  if (cur_month == 11)
    {
		cur_year++;
		icur_year=cur_year;
		cur_month = 0;
		icur_month=cur_month+1;
    }
  else
    {
		cur_month++;
		icur_month=cur_month+1;
    }
	//if (icur_month < 10)
	//{
	//	icur_month='0' + icur_month;
	//}
  DrawCalendar(cur_month, cur_year, icur_month, icur_year);
  }


