// Object constructor
function planEntry(day, month, year,  when, preacherm, preachere)
{
   this.day = day;
   this.month = month;
   this.year = year;
   this.when = when; 
   this.preacherm = preacherm;
   this.preachere = preachere;
}

// this function builds the table component of the page
function display_plan()
{
	var circuitPlan = 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="#CCCCCC";	
	
	
	
	
	
	
	circuitPlan[0] = new planEntry("10","08","2008","Sun 10 August","Mr Robert Sales","Mrs Ann Parkinson");
	circuitPlan[1] = new planEntry("17","08","2008","Sun 17 August","Rev Tim Morris","Rev Tim Morris HC");
	circuitPlan[2] = new planEntry("24","08","2008","Sun 24 August","Mr Tim Dutton","Mrs Heather Garbutt");
	circuitPlan[3] = new planEntry("31","08","2008","Sun 31 August","Rev Tim Morris","Mr Stuart Mustow");
	circuitPlan[4] = new planEntry("07","09","2008","Sun 7 September","Rev Tim Morris HC","Rev Trevor Staniforth");
	circuitPlan[5] = new planEntry("14","09","2008","Sun 14 September","Rev Ray Owen","Rev Tim Morris");
	circuitPlan[6] = new planEntry("21","09","2008","Sun 21 September","Mr Tom Parkinson","Sister Merle Wilde HC");
	circuitPlan[7] = new planEntry("28","09","2008","Sun 28 September","Mr Tim Dutton Harvest Festival","Mrs Ann Parkinson");
	circuitPlan[8] = new planEntry("05","10","2008","Sun 5 October","Rev Tim Morris HC","Rev Tim Morris / Mr Tim Dutton, Circuit Service");
	circuitPlan[9] = new planEntry("12","10","2008","Sun 12 October","Mr John Whitehead","Mr John Dyster");
	circuitPlan[10] = new planEntry("19","10","2008","Sun 19 October","Mr Peter Dawson","Rev Tim Morris Christian Aid Service with St. Oswald's");
	circuitPlan[11] = new planEntry("26","10","2008","Sun 26 October","Mr Tim Dutton","Mr John Turner");
	circuitPlan[12] = new planEntry("02","11","2008","Sun 2 November","Rev Tim Morris HC","Mrs Fiona Green");
	circuitPlan[13] = new planEntry("09","11","2008","Sun 9 November","Mr Stuart Mustow at 10.45 Remembrance Sunday","Rev Trevor Staniforth");
	circuitPlan[14] = new planEntry("16","11","2008","Sun 16 November","Miss Diana Whitmill","Rev Tim Morris HC");
	circuitPlan[15] = new planEntry("23","11","2008","Sun 23 November","Mr John Turner","Rev Mark Broadhurst");
	circuitPlan[16] = new planEntry("30","11","2008","Sun 30 November","Rev Tim Morris","Mr Stuart Mustow");
	






	// set a local variable equal to the length of the array
	var maxEntries=circuitPlan.length;
	
	// print out the header
	document.write("<table width='100%' border='2'>");
	document.write("<tr align='center'><td>.....Date......</td><td>morning at 10 30</td><td>evening at 6.30</td></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 (circuitPlan[i].year>=ayear)
		{
			// if the year in the Plan is equal to the current year
			if (circuitPlan[i].year==ayear)
			{
				// is the month in the Plan greater than or equal to the current month 
				if (circuitPlan[i].month==amonth)
				{
					if (aday>circuitPlan[i].day)
					{
						printit=0;
					}
					else
					{
						printit=1;
					}
				}
				else
				{
					if (circuitPlan[i].month>amonth)
					{
						printit=1;
					}
					else
					{
						printit=0;
					}
				}
			}
			else
			{
				printit=1;
			}
		}
		else
		{
			printit=0;
		}
		
		// if the row should be printed
		if (printit==1)
		{
			document.write("<tr bgcolor="+ bgcol + " align='left'><td>" + circuitPlan[i].when + "</td><td>" + circuitPlan[i].preacherm + "</td><td>" + circuitPlan[i].preachere + "</td></tr>")
			
			// change bgcol
			if (bgcol=="#CCCCCC")
			{
				bgcol="white";
			}
			else
			{
				bgcol="#CCCCCC";
			}
		}
	}
	
	// close the table
	document.write("</table>");
}