today= new Date();
todayDate= today.getDate();
todayMonth= today.getMonth();
todayYear= today.getFullYear();
numberofmonths = 1;
type=3;

thisMonth= today.getMonth();
thisYear= today.getFullYear();
start = new Date(thisYear,thisMonth,1);
startofyear = new Date(thisYear,0,1);
weekday = start.getDay();
todayDay = today.getDay();
lasttest= new Date();
ADay = 60*1000*60*24;

var WeekClassDay = new Array([[8,0,3,5,2,1,8],[8,1,6,7,4,0,8]],[[8,7,5,2,3,4,8],[8,2,4,1,0,6,8]],[[8,4,1,3,4,5,8],[8,6,2,0,1,7,8]],[[8,1,7,6,1,2,8],[8,5,0,4,5,3,8]],[[8,5,6,1,7,0,8],[8,3,7,2,6,4,8]],
[[8,3,1,6,4,2,8],[8,0,5,3,7,6,8]],[[8,1,4,0,7,6,8],[8,7,3,5,1,2,8]],[[8,6,2,4,5,3,8],[8,1,3,0,2,7,8]],[[8,2,0,5,6,7,8],[8,5,4,1,3,1,8]],[[8,3,0,7,0,1,8],[8,4,1,6,2,5,8]]);
//var WeekClassDay = new Array([[B,T,G,W,K],[L,K,D,S,B]],[[K,G,W,S,D],[S,L,B,K,T]],[[G,B,D,T,W],[D,S,W,L,K]],[[W,G,K,D,L],[T,L,S,G,B]],[[L,W,T,K,S],[S,D,L,B,G]],
//[[L,K,D,S,T],[W,B,G,T,L]],[[T,L,S,D,G],[K,W,B,L,D]],[[D,S,L,B,K],[G,W,T,W,L]],[[S,L,B,L,T],[T,G,K,D,W]],[[G,D,L,G,B],[B,T,W,K,S]])
var techs = new Array ("Basics", "Locks", "Kicks", "Strikes", "Weapons", "Wrestling", "Self-Defense", "Throws/Rolls","Open Practice");
var MonthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
var DayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var MonthDays = new Array (31, todayYear%4==0?29:28, 31,30,31,30,31,31,30,31,30,31);

var tests = new Array ("12/09/2006","03/03/2007", "05/12/2007","07/21/2007", "09/29/2007", "12/08/2007");
var holidays = new Array ("12/31/2006","01/01/2007", "01/15/2007", "05/28/2007", "07/04/2007","09/03/2007", "11/22/2007", "11/23/2007" ,
	"12/23/2007", "12/24/2007", "12/25/2007", "12/26/2007","12/31/2007","01/01/2008");
var seminarsdate = new Array ("01/20/2007","03/04/2007","05/13/2007","07/14/2007","07/22/2006","09/30/2007","12/09/2007");
var seminars = new Array ("10am-4pm: Stunt<br>Team <b>Auditions</b>","10am-2pm: Throws/Rolls Seminar","10am-2pm: Joint Controls and Locks","10am-4pm: Gun<br>Defense Seminar","10am-2pm: Weapons Seminar","9am-2pm: Black Belt Test","10am-2pm: Weapons Seminar");

function loadform()
{
	document.Calendar.thismonth.selectedIndex=thisMonth;
	document.Calendar.thisyear.value=todayYear;	
	document.Calendar.thisyear.focus();
}

function gotoMonth(x)
{
	if (x > 0)
		thisMonth = thisMonth + x;
	else
		thisMonth = thisMonth - (numberofmonths*2-1);
	if (thisMonth > 11)
		thisYear++;
	if (thisMonth < 0)
		thisYear--;
	if (thisMonth < -12)
		thisYear--;
	thisMonth = (thisMonth+36)%12;
	document.Calendar.thismonth.selectedIndex=thisMonth;
	document.Calendar.thisyear.selectedIndex=thisYear-2001;
}
	
function gotonext(x)
{
	gotoMonth(x);
	writeHTML();		
}

function gotoselect()
{
	thisMonth = document.Calendar.thismonth.selectedIndex;
	thisYear = document.Calendar.thisyear.value;
	numberofmonths = document.Calendar.numberofmonths.value;
	writeHTML();		
}

function lookupevent(k)
{
	thedate = new Date(thisYear,thisMonth,k);
	return(lookuptoday(1));	
}

function writeMonth()
{
	start = new Date(thisYear,thisMonth,1);
	startofyear = new Date(thisYear,0,1);
	weekday = start.getDay();
	today = new Date();
	todayDay = today.getDay();
	todayDate= today.getDate();
//	sumofmonth();

	s = "";
    s += "<tr class='CalendarHeader'>\n<td colspan=7 align='center'>\n";
	s += MonthName[thisMonth] +" &nbsp "+thisYear;
	s += "</td>\n</tr>\n<tr class='cal-Font'>\n<td align=center width='125'>Sunday</td>\n<td align=center width='125'>Monday</td>\n<td align=center width='125'>Tuesday</td>\n";
	s += "<td align=center width='125'>Wednesday</td>\n<td align=center width='125'>Thursday</td>\n<td align=center width='125'>Friday</td>\n<td align=center  width='125'>Saturday</td>	\n</tr>	";
	s += "<tr>";
	var k = 1;
	for (i=0; i<7; i++)
	{
		if (i < weekday)
			s +="<td align=center>&nbsp";
		else
			s +="<td align=center valign=top>"+lookupevent(k++)+"</a>";
		s +="</td>";
	}
	s +="</tr>";

	for (j=2; j<=6; j++)
	{
		if (k <= MonthDays[thisMonth])
		{
			s +="<tr>";
			for (i=0; i<=6; i++)
			{
				if (k <=MonthDays[thisMonth])
					s +="<td align=center valign=top>"+lookupevent(k++)+"</a>";
				else
					s +="<td align=center> &nbsp";
				s +="</td>";
			}
			s +="</tr>";
		}
	}
	 return(s);
}
function writeHTML()
{
	thestring = "<table width=100% border=1 bordercolor='#000000'  cellpadding='1' cellspacing='0' class='CalendarFont'>";
//	for (x2=0; x2<8; x2++)
//		b[x2]=0; 

	for (ii=0; ii<numberofmonths; ii++)
	{
		if (ii > 0 )
		{
  			 thestring += "<tr class='cal-Font'><td colspan=7 >&nbsp;</td></tr>";
			gotoMonth(1);
		}
		start = new Date(thisYear,thisMonth,1);
		startofyear = new Date(thisYear,0,1);
		weekday = start.getDay();
		todayDay = today.getDay();
		thestring += writeMonth();
	}
	thestring += "</table>";
	document.getElementById("Main").innerHTML = thestring;
}

function lookuptoday()
{
	thedate = new Date(thedate.getFullYear(),thedate.getMonth(),thedate.getDate());
	startofyear = new Date(thedate.getFullYear(),0,1);
	weekofyear =  	 Math.floor(((60*1000*60*2 + thedate.getTime()) - (startofyear.getTime() - startofyear.getDay()*ADay))/(ADay*7))+1;
	weeksfromtest =  (weekofyear)%10;

	special = "";
	sem = "";
	youthadvanced = "";
	dynamic = "";
	y_string = "";
	stu = "";
	theevent = "";
//	document.write("weekofyear:"+weekofyear+"<br>");
//	document.write("WeeksfromTest:"+weeksfromtest+"<br>");

	if (thedate.getDay() == 0 || thedate.getDay() == 6)
		a_string = "<br>4pm: "+techs[WeekClassDay[weeksfromtest][0][thedate.getDay()]];
	else 
	{
		if (type == 3 || type == 4)
		{
			if (thedate.getDay() == 2 || thedate.getDay() == 4)
				a_string = "<br><b>At Black Knight</b><br>6:30pm: "+techs[WeekClassDay[weeksfromtest][0][thedate.getDay()]]+" <br>7:30pm: "+techs[WeekClassDay[weeksfromtest][1][thedate.getDay()]];
			else
				a_string = "<br>6:30pm: "+techs[WeekClassDay[weeksfromtest][0][thedate.getDay()]]+" <br>7:30pm: "+techs[WeekClassDay[weeksfromtest][1][thedate.getDay()]];
		}
		else
			a_string = "<br>6pm: "+techs[WeekClassDay[weeksfromtest][0][thedate.getDay()]]+" <br>7:30pm: "+techs[WeekClassDay[weeksfromtest][1][thedate.getDay()]];
	}

	if ((thedate.getDay() == 2 || thedate.getDay() == 4 ) && type != 3 && type != 4) 
		y_string = "<br><span style='color: #009C00;'>4:45pm: Youth Class</span>";
		
	for (x=0; x < tests.length; x++)
	{
		a_date = new Date(tests[x])
		if (thedate.getYear() == a_date.getYear() && thedate.getMonth() == a_date.getMonth() && thedate.getDate() == a_date.getDate())
			special = "<br><b>Belt Test</b>";
	}
	for (x=0; x < holidays.length; x++)
	{
		a_date = new Date(holidays[x])
		if (thedate.getYear() == a_date.getYear() && thedate.getMonth() == a_date.getMonth() && thedate.getDate() == a_date.getDate())
			special = "<br><b>Holiday</b>";
	}
	for (x=0; x < seminars.length; x++)
	{
		a_date = new Date(seminarsdate[x])
		if (thedate.getYear() == a_date.getYear() && thedate.getMonth() == a_date.getMonth() && thedate.getDate() == a_date.getDate())
			sem = "<br><span style='color: #9C009C;'>"+seminars[x]+"</span>";
	}

//	theevent = "<b>"+DayName[thedate.getDay()]+"</b><br>"+ MonthName[thedate.getMonth()]+" "+thedate.getDate()+", "+thedate.getFullYear() + " ";
	if (type == 2 || type == 4)
		theevent = "<b>"+DayName[thedate.getDay()]+"</b> ("+ (thedate.getMonth()+1)+"/"+thedate.getDate()+"/"+thedate.getFullYear() + ")";
	else
		theevent = "<span class='CalendarDay'>"+thedate.getDate()+"</span>";

	if (thedate.getDay() == 6)
	{
		if ((weekofyear%2) == 0)
		{
			if (type != 3 && type != 4) 
				youthadvanced = "<br><span style='color: #009C00;'>10:30am: Advanced Youth</span>";
			if (weekofyear > 3 && weekofyear < 51)
				stu = "<br><b><span style='color: #9C0000;'>12pm: Stunt Team</span></b>";
		}
		else
			dynamic = "<br><span style='color: #9C0000;'>2:00pm: Applied Class</span>";
	}

	if (special == "")
	{
		theevent += sem;
		if (sem == "")
		{
			theevent += youthadvanced;
			theevent += dynamic;
		}
		theevent += stu;
		theevent += y_string;
		theevent += a_string;
	}
	else
		theevent += special;
	return(theevent);	
}

function writeDays(days, ttype)
{
	thedate = new Date();
	type = ttype;
	document.write("<b><font size='+1'>Schedule</font></b><br>");
	for (ii=0; ii<days; ii++)
	{
		document.write(lookuptoday()+"<br><br>");
		thedate.setTime(thedate.getTime()+ 24*60*60*1000);
	}
}


