
// Object constructor
function eventInfo(day, month, year, time, event)
{
   this.day = day;
   this.month = month;
   this.year = year;
   this.time = time;
   this.event = event;
}

// this function builds the table component of the page
function display_diary()
{
	var eventDiary = new Array();
	var today = new Date();
	var aday;
	var amonth;
	var ayear;
	var printit;
	var bgcol;
	
	// set other local variables
	aday = today.getDate();
	amonth = today.getMonth() + 1;
	ayear = today.getFullYear();
	bgcol="#ffff00";	
	
	// this is the diary, one row per event, remember that the first row must be eventDiary[0]
	

eventDiary[0] = new eventInfo("01","05","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[1] = new eventInfo("08","05","2010","","No Rehearsal");
eventDiary[2] = new eventInfo("15","05","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[3] = new eventInfo("22","05","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[4] = new eventInfo("29","05","2010","19:45","Normal Rehearsal at Dewsbury Road");

eventDiary[5] = new eventInfo("06","06","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[6] = new eventInfo("13","06","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[7] = new eventInfo("20","06","2010","19:45","Normal Rehearsal at Dewsbury Road");
eventDiary[8] = new eventInfo("27","06","2010","19:45","Normal Rehearsal at Dewsbury Road");

	// set a local variable equal to the length of the array
	var maxEntries=eventDiary.length;
	
	// print out the header
	document.write("<table width='400' border='1' bordercolor='#ff0000' class='diary' bgcolor='#ccff00' align='center'>");
	document.write("<tr align='center'><th>Date</th><th>Time</th><th>Event</th></tr>")
	
	// check to see if the row shold be printed.
	for (i=0;i<maxEntries;i++)
	{
		printit=0;
	
		// is the year in the Plan greater than or equal to the current year ?
		if (eventDiary[i].year>=ayear)
		{
			// if the year in the Plan is equal to the current year
			if (eventDiary[i].year==ayear)
			{
				// is the month in the Plan greater than or equal to the current month 
				if (eventDiary[i].month==amonth)
				{
					if (aday>eventDiary[i].day)
					{
						printit=1;
					}
					else
					{
						printit=1;
					}
				}
				else
				{
					if (eventDiary[i].month>amonth)
					{
						printit=1;
					}
					else
					{
						printit=1;
					}
				}
			}
			else
			{
				printit=1;
			}
		}
		else
		{
			printit=1;
		}
		
		// if the row should be printed
		if (printit==1)
		{
			// build a date 
			var myDate = new Date (eventDiary[i].year,eventDiary[i].month,eventDiary[i].day);
			whichDay = myDate.getDay();
		
			// convert the day value to a proper day value
			switch (whichDay)
			{
				case 0:
					whichDayName="Sunday";
					break;
				case 1:
					whichDayName="Monday";
					break;
				case 2:
					whichDayName="Tuesday";
					break;
				case 3:
					whichDayName="Wednesday";
					break;
				case 4:
					whichDayName="Thursday";
					break;
				case 5:
					whichDayName="Friday";
					break;
				case 6:
					whichDayName="Saturday";
					break;
			}
			
			// convert the month value to a proper month value
			whichMonth = myDate.getMonth();
			
			switch(whichMonth)
			{
				case 0:
					whichMonthName="January";
					break;
				case 1:
					whichMonthName="February";
					break;
				case 2:
					whichMonthName="March";
					break;
				case 3:
					whichMonthName="April";
					break;
				case 4:
					whichMonthName="May";
					break;
				case 5:
					whichMonthName="June";
					break;
				case 6:
					whichMonthName="July";
					break;
				case 7:
					whichMonthName="August";
					break;
				case 8:
					whichMonthName="September";
					break;
				case 9:
					whichMonthName="October";
					break;
				case 10:
					whichMonthName="November";
					break;
				case 11:
					whichMonthName="December";
					break;
			}

			document.write("<tr bgcolor="+ bgcol + " align='center'><td>" + whichDayName + " " + eventDiary[i].day + " " + whichMonthName + " " + eventDiary[i].year + "</td><td>" + eventDiary[i].time + "</td><td>" + eventDiary[i].event + "</td></tr>")
			
			// change bgcol
			if (bgcol=="#ffff00")
			{
				bgcol="#ffff00";
			}
			else
			{
				bgcol="#ffff00";
			}
		}
	}
	
	// close the table
	document.write("</table>");
}
