//------Set the first day of the first month
(Begin_Calendar_Day=="Sunday") ? (Begin_Calendar_Day=0) : null;
(Begin_Calendar_Day=="Monday") ? (Begin_Calendar_Day=1) : null;
(Begin_Calendar_Day=="Tuesday") ? (Begin_Calendar_Day=2) : null;
(Begin_Calendar_Day=="Wednesday") ? (Begin_Calendar_Day=3) : null;
(Begin_Calendar_Day=="Thursday") ? (Begin_Calendar_Day=4) : null;
(Begin_Calendar_Day=="Friday") ? (Begin_Calendar_Day=5) : null;
(Begin_Calendar_Day=="Saturday") ? (Begin_Calendar_Day=6) : null;


//------This section is used to marked when the co-op session begins each quarter
var BeginCoopSessionMonth = new Array();
var BeginCoopSessionDay = new Array();
	
for (var BPQM=0; BPQM<6; BPQM++)
{
	(Begin_Paractice_Quarter_Month[BPQM]=="January") ? (Begin_Paractice_Quarter_Month[BPQM]=1) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="February") ? (Begin_Paractice_Quarter_Month[BPQM]=2) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="March") ? (Begin_Paractice_Quarter_Month[BPQM]=3) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="April") ? (Begin_Paractice_Quarter_Month[BPQM]=4) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="May") ? (Begin_Paractice_Quarter_Month[BPQM]=5) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="June") ? (Begin_Paractice_Quarter_Month[BPQM]=6) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="July") ? (Begin_Paractice_Quarter_Month[BPQM]=7) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="August") ? (Begin_Paractice_Quarter_Month[BPQM]=8) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="September") ? (Begin_Paractice_Quarter_Month[BPQM]=9) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="October") ? (Begin_Paractice_Quarter_Month[BPQM]=10) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="November") ? (Begin_Paractice_Quarter_Month[BPQM]=11) : null;
	(Begin_Paractice_Quarter_Month[BPQM]=="December") ? (Begin_Paractice_Quarter_Month[BPQM]=12) : null;
	
	BeginCoopSessionMonth[BPQM] = Begin_Paractice_Quarter_Month[BPQM];		
	BeginCoopSessionDay[BPQM] = (Begin_Paractice_Quarter_Day[BPQM]);
}


//------This section is used to marked when classes begin and end during each quarter
var BeginClassMonth = new Array();

for (var CM=0; CM<13; CM++)
{
	if(CM==0 || CM==2 || CM==4 || CM==6 || CM==8 || CM==10)
	{
		(Begin_Class_Quarter_Month[CM]=="January") ? (Begin_Class_Quarter_Month[CM]=1) : null;
		(Begin_Class_Quarter_Month[CM]=="February") ? (Begin_Class_Quarter_Month[CM]=2) : null;
		(Begin_Class_Quarter_Month[CM]=="March") ? (Begin_Class_Quarter_Month[CM]=3) : null;
		(Begin_Class_Quarter_Month[CM]=="April") ? (Begin_Class_Quarter_Month[CM]=4) : null;
		(Begin_Class_Quarter_Month[CM]=="May") ? (Begin_Class_Quarter_Month[CM]=5) : null;
		(Begin_Class_Quarter_Month[CM]=="June") ? (Begin_Class_Quarter_Month[CM]=6) : null;
		(Begin_Class_Quarter_Month[CM]=="July") ? (Begin_Class_Quarter_Month[CM]=7) : null;
		(Begin_Class_Quarter_Month[CM]=="August") ? (Begin_Class_Quarter_Month[CM]=8) : null;
		(Begin_Class_Quarter_Month[CM]=="September") ? (Begin_Class_Quarter_Month[CM]=9) : null;
		(Begin_Class_Quarter_Month[CM]=="October") ? (Begin_Class_Quarter_Month[CM]=10) : null;
		(Begin_Class_Quarter_Month[CM]=="November") ? (Begin_Class_Quarter_Month[CM]=11) : null;
		(Begin_Class_Quarter_Month[CM]=="December") ? (Begin_Class_Quarter_Month[CM]=12) : null;
	
		BeginClassMonth[CM] = Begin_Class_Quarter_Month[CM];
	}
	if(CM==1 || CM==3 || CM==5 || CM==7 || CM==9 || CM==11)
	{
		(End_Class_Quarter_Month[CM]=="January") ? (End_Class_Quarter_Month[CM]=1) : null;
		(End_Class_Quarter_Month[CM]=="February") ? (End_Class_Quarter_Month[CM]=2) : null;
		(End_Class_Quarter_Month[CM]=="March") ? (End_Class_Quarter_Month[CM]=3) : null;
		(End_Class_Quarter_Month[CM]=="April") ? (End_Class_Quarter_Month[CM]=4) : null;
		(End_Class_Quarter_Month[CM]=="May") ? (End_Class_Quarter_Month[CM]=5) : null;
		(End_Class_Quarter_Month[CM]=="June") ? (End_Class_Quarter_Month[CM]=6) : null;
		(End_Class_Quarter_Month[CM]=="July") ? (End_Class_Quarter_Month[CM]=7) : null;
		(End_Class_Quarter_Month[CM]=="August") ? (End_Class_Quarter_Month[CM]=8) : null;
		(End_Class_Quarter_Month[CM]=="September") ? (End_Class_Quarter_Month[CM]=9) : null;
		(End_Class_Quarter_Month[CM]=="October") ? (End_Class_Quarter_Month[CM]=10) : null;
		(End_Class_Quarter_Month[CM]=="November") ? (End_Class_Quarter_Month[CM]=11) : null;
		(End_Class_Quarter_Month[CM]=="December") ? (End_Class_Quarter_Month[CM]=12) : null;
	
		BeginClassMonth[CM] = End_Class_Quarter_Month[CM];
	}
}

var BeginClassDay = new Array("1");
	
for (var BCQD=1; BCQD<13; BCQD++)
{
	if(BCQD==2 || BCQD==4 || BCQD==6 || BCQD==8 || BCQD==10 || BCQD==12)
	{
		BeginClassDay[BCQD] = Begin_Class_Quarter_Day[BCQD];
	}
	
	else if(BCQD==1 || BCQD==3 || BCQD==5 || BCQD==7 || BCQD==9 || BCQD==11)
	{
		BeginClassDay[BCQD] = (End_Class_Quarter_Day[BCQD]+1);
	}
}

//------This section is used to marked when the registration card must be mailed in each quarter
var mailMonth = new Array();
var mailDay = new Array();

for (var MPCM=0; MPCM<6; MPCM++)
{
	(Mail_Paractice_Card_Month[MPCM]=="January") ? (Mail_Paractice_Card_Month[MPCM]=1) : null;
	(Mail_Paractice_Card_Month[MPCM]=="February") ? (Mail_Paractice_Card_Month[MPCM]=2) : null;
	(Mail_Paractice_Card_Month[MPCM]=="March") ? (Mail_Paractice_Card_Month[MPCM]=3) : null;
	(Mail_Paractice_Card_Month[MPCM]=="April") ? (Mail_Paractice_Card_Month[MPCM]=4) : null;
	(Mail_Paractice_Card_Month[MPCM]=="May") ? (Mail_Paractice_Card_Month[MPCM]=5) : null;
	(Mail_Paractice_Card_Month[MPCM]=="June") ? (Mail_Paractice_Card_Month[MPCM]=6) : null;
	(Mail_Paractice_Card_Month[MPCM]=="July") ? (Mail_Paractice_Card_Month[MPCM]=7) : null;
	(Mail_Paractice_Card_Month[MPCM]=="August") ? (Mail_Paractice_Card_Month[MPCM]=8) : null;
	(Mail_Paractice_Card_Month[MPCM]=="September") ? (Mail_Paractice_Card_Month[MPCM]=9) : null;
	(Mail_Paractice_Card_Month[MPCM]=="October") ? (Mail_Paractice_Card_Month[MPCM]=10) : null;
	(Mail_Paractice_Card_Month[MPCM]=="November") ? (Mail_Paractice_Card_Month[MPCM]=11) : null;
	(Mail_Paractice_Card_Month[MPCM]=="December") ? (Mail_Paractice_Card_Month[MPCM]=12) : null;
	
	mailMonth[MPCM] = Mail_Paractice_Card_Month[MPCM];		
	mailDay[MPCM] = (Mail_Paractice_Card_Day[MPCM]);
}


//-------Fixed information used to create the calander and get the current date. No more variables need to be changed.
var numDays=new Array("", "31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
var monthName=new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var dayName=new Array("S", "M", "T", "W", "H", "F", "S");
var numSessions=BeginCoopSessionMonth.length-1;
var s=0;
var c=0;
var mc=0;
var rowCount=0;
var itsToday="";
var mailDate="";
var todaysDate=new Date();
var yearNum=todaysDate.getFullYear(); //getYear() returns 106 in Firefox and 2006 in IE, so use getFullYear()
var monthNum=todaysDate.getMonth() + 1; //HACK: don't know why we need the +1, but we do!...
var dayNum=todaysDate.getDate();

var End_Calendar_Year = Begin_Calendar_Year+1; //---The year the calendar is to end on

//-------Begin creating the table.
document.write('\n<table class="calendar"><tr valign="top">\n');
var RecessSwitch = 1;
for (Begin_Calendar_Year; Begin_Calendar_Year<=End_Calendar_Year; Begin_Calendar_Year++)
{
	//check which year it is and what the last month for that year is
	if (Begin_Calendar_Year!=End_Calendar_Year)
	{ 
		firstMonth=BeginCoopSessionMonth[0];
		finalMonth=12;
	}
	else {
		finalMonth=BeginCoopSessionMonth[numSessions];
		firstMonth=1;
	}
	
	//compensate for leapyear, and if this thing is still around in 17 years, WOW!
	//HOW ABOUT DOING: if Begin_Calendar_Year % 4 = 0		???//Jason Hafer
	if(Begin_Calendar_Year==2004 || Begin_Calendar_Year==2008 || Begin_Calendar_Year==2012 || Begin_Calendar_Year==2016 || Begin_Calendar_Year==2020)
	{
		numDays[2]="29";
	}
	else
	{
		numDays[2]="28";
	}
	//begin writing tables for each month
	for (var m=firstMonth; m<=finalMonth; m++)
	{
		var newLine=0;
		if (rowCount==3)
		{
			//create a new row every 3 months
			rowCount=0;
			document.write('</tr><tr valign="top">');
		}
		//write the header and month + year name
		document.write('\n<td valign="top" style="border: block;">\n<table class="month"><tr valign="top"><td colspan="7">'+monthName[m]+'&nbsp;'+Begin_Calendar_Year+'</td></tr>\n<tr>');
		//write the 7 days titles
		for (var seven=0; seven<7; seven++)
		{
			document.write('<th>'+dayName[seven]+'</th>');
		}
		document.write('</tr><tr>');
		//fill in blank days until the first day of the month
		for(var blanks=0; blanks<Begin_Calendar_Day; blanks++)
		{
			document.write('<td>&nbsp;</td>');
			newLine++;
		}
		
		//begin writing the days of the month
		for(var d=1; d<=numDays[m]; d++)
		{
			//check which section it is
			if(m==BeginCoopSessionMonth[s] && d==BeginCoopSessionDay[s])
			{ 
				//alert(BeginCoopSessionDay[s]);
				if (sectionNum==1)
				{
					sectionNum++;
				}
				else
				{
					sectionNum--;
				}
				s++;
			}
			//check if class is in session or not
			if(m==BeginClassMonth[c] && d==BeginClassDay[c])
			{
				//alert(m + "  " + d);
				RecessSwitch++;
				if (sectionNum==1 || sectionNum==2)
				{
					//sectionNum=sectionNum+2;					
				}
				else
				{
					//sectionNum=sectionNum-2;
				}
				c++;
			}
			//check if the date being written is the current date
			if (m==monthNum && d==dayNum && Begin_Calendar_Year==yearNum)
			{
				itsToday="today";
			}
			else
			{
				itsToday="";
			}
			//check if the registration card is due
			if (m==mailMonth[mc] && d==mailDay[mc])
			{
				mailDate="mail";
				mc++;
			}
			else
			{
				mailDate="";
			}
			//write the cell with the number and correct class
			var recess="";
			if(1 == (RecessSwitch % 2))
				recess="recess";
			else
				recess="";
			document.write('\n<td class="sec'+sectionNum+recess+itsToday+mailDate+'" align="center">'+d+'</td>\n');
			newLine++;
			if(newLine==7)
			{
				document.write('</tr>\n<tr>');
				newLine=0;
			}
		}
		//close the table for the month and repeat if necessary
		document.write('</tr></table></td>');
		Begin_Calendar_Day=newLine;
		rowCount++;
	}
}
document.write('</table>');
