// Array of dates off, Add any dates that lessons are cancelled
// Format must equal     "D/M/YYYY"
var datesOff = new Array(
"18/12/2008",
"22/12/2008",
"25/12/2008",
"29/12/2008",
"1/1/2009",
"5/1/2009",
"8/1/2009",
"12/1/2009",
"6/4/2009",
"9/4/2009",
"13/4/2009",
"16/4/2009",
"4/5/2009",
"25/5/2009",
"4/6/2009",
"27/7/2009",
"30/7/2009",
"3/8/2009",
"6/8/2009",
"10/8/2009",
"13/8/2009",
"17/8/2009",
"20/8/2009",
"24/8/2009",
"27/8/2009",
"31/8/2009",
"3/9/2009",
"14/12/2009",
"17/12/2009",
"21/12/2009",
"24/12/2009",
"28/12/2009",
"31/12/2009",
"4/1/2010",
"7/1/2010",
"14/1/2010",
"29/3/2010",
"1/4/2010",
"5/4/2010",
"8/4/2010",
"3/5/2010",
"6/5/2010",
"31/5/2010",
"26/7/2010",
"29/7/2010",
"2/8/2010",
"9/8/2010",
"16/8/2010",
"23/8/2010",
"30/8/2010"
);


// Message which is displayed before the date
var lessonON = "The next class is on";
var lessonOFF = "There will be <em>no</em> class on";

// Days which lessons fall (make sure its capitalized)
var dayONE = "Monday";
var dayTWO = "Thursday";
// Extra days (leave blank if not needed)
var dayTHREE = "";
var dayFOUR = "";
var dayFIVE = "";









//##########################################################################
// DO NOT EDIT ANYTHING BELOW
//##########################################################################

// Declare variables
var tdate = new Date();   // hold the date
var wholedate;    // hold formatted date
var todaysDay;    // hold what day today is
var shortDate;    // hold short version of date
var nextLesson;
var displayMessage  = "";  //what the function returns to the user

// Array for Days
var dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

// Array for Months 
var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");


// Set variables to todays date
shortDate = tdate.getDate() + "/" + (tdate.getMonth()+1) + "/" + tdate.getFullYear();
todaysDay = dayNames[tdate.getDay()];
wholedate = dayNames[tdate.getDay()] + " the " + tdate.getDate() + " of " + monthNames[tdate.getMonth()] + ", " + tdate.getFullYear();

// call function
checkday();

// Check if lesson falls on todays date
function checkday() {
		
if ((todaysDay == dayONE) || (todaysDay == dayTWO) || (todaysDay == dayTHREE) || (todaysDay == dayFOUR) || (todaysDay == dayFIVE)) {

// If a lesson falls on the date then check against the list of cancelled lessons
for(var i=0; i<datesOff.length; i++) {
	
	if(shortDate == datesOff[i]) {
		displayMessage = (lessonOFF + " " + wholedate);
		findnextLesson();

	}
}
// If date can not be found pn the list then assume lessons are on

	nextLesson = (lessonON + " " + wholedate);


} else {
	// If a lesson does not normally fall on this date then call next day function
	findnextday();
}
}

// function for finding out tommorows date
function findnextday() {
	
	tdate.setDate(tdate.getDate()+1);
	shortDate = tdate.getDate() + "/" + (tdate.getMonth()+1) + "/" + tdate.getFullYear();
	todaysDay = dayNames[tdate.getDay()];
	wholedate = dayNames[tdate.getDay()] + " the " + tdate.getDate() + " of " + monthNames[tdate.getMonth()] + ", " + tdate.getFullYear();
	
	// Once the date variables have been updated we need to run the checkday again to see if it lies on a lesson day
	// this will be repeated untill a day falls on one of the selected days
	checkday();
	
}
function findnextLesson() {
	tdate.setDate(tdate.getDate()+1);
	shortDate = tdate.getDate() + "/" + (tdate.getMonth()+1) + "/" + tdate.getFullYear();
	todaysDay = dayNames[tdate.getDay()];
	wholedate = dayNames[tdate.getDay()] + " the " + tdate.getDate() + " of " + monthNames[tdate.getMonth()] + ", " + tdate.getFullYear();
		checkday2();
}

function checkday2() {
		
if ((todaysDay == dayONE) || (todaysDay == dayTWO) || (todaysDay == dayTHREE) || (todaysDay == dayFOUR) || (todaysDay == dayFIVE)) {


for(var i=0; i<datesOff.length; i++) {
	
	if(shortDate == datesOff[i]) {
		findnextLesson();

	}
}


	nextLesson = (lessonON + " " + wholedate);


} else {

	findnextLesson();
}
}
