// 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("30","11","2003","Sun 30 November","Rev Chris Eddy / Rev Mair Bradley HC","Mr Roger Mallard");
	circuitPlan[1] = new planEntry("07","12","2003","Sun 7 December","Mrs Ann Parkinson","Rev Chris Eddy HC");
	circuitPlan[2] = new planEntry("14","12","2003","Sun 14 December","Rev Chris Eddy","Mis Diana Whitmill");
	circuitPlan[3] = new planEntry("21","12","2003","Sun 21 December","Miss Tracy Dawson","Rev Chris Eddy HC");
	circuitPlan[4] = new planEntry("24","12","2003","Wed 24 December","Christmas at Milldale 4.00pm","Christmas Eve Communion Ashbourne HC 11.15 pm");
	circuitPlan[5] = new planEntry("25","12","2003","Thur 25 December","Christmas Morning 10.00 am","");
	circuitPlan[6] = new planEntry("28","12","2003","Sun 28 December","Mr Tom Parkinson","Circuit Service Hulland 2.30 pm");
	circuitPlan[7] = new planEntry("31","12","2003","Wed 31 December","","Rev Trevor Staniforth, Watchnight Service 11.15 pm");
	circuitPlan[8] = new planEntry("04","01","2004","Sun 4 January","Rev Chris Eddy, Covenant Service","Mr John Turner");
	circuitPlan[9] = new planEntry("11","01","2004","Sun 11 January","Rev Duncan Tuck","Mrs Sue Massey");
	circuitPlan[10] = new planEntry("18","01","2004","Sun 18 January","Rev Chris Eddy","Mr Tim Dutton");
	circuitPlan[11] = new planEntry("25","01","2004","Sun 25 January","Rev Trevor Staniforth","Rev Chris Eddy, HC");
	circuitPlan[12] = new planEntry("01","02","2004","Sun 1 February","Rev Chris Eddy","Mr Jeff Thompson");
	circuitPlan[13] = new planEntry("08","02","2004","Sun 8 February","Mr John Turner","Miss Diana Whitmill");
	circuitPlan[14] = new planEntry("15","02","2004","Sun 15 February","Rev Chris Eddy HC","Sister Merle Wilde");
	circuitPlan[15] = new planEntry("22","02","2004","Sun 22 February","Mr Stuart Mustow","Mr Tom Parkinson");	
	circuitPlan[16] = new planEntry("29","02","2004","Sun 29 February","Rev Chris Eddy","Mr Jim Scott");
	circuitPlan[17] = new planEntry("07","03","2004","Sun 7 March","Rev Mair Bradley","Rev Chris Eddy, HC");
	circuitPlan[18] = new planEntry("14","03","2004","Sun 14 March","Rev Chris Eddy, HC","Mrs Ann Parkinson");
	circuitPlan[19] = new planEntry("21","03","2004","Sun 21 March","Miss Diana Whitmill","Mrs Tracy Dawson");
	circuitPlan[20] = new planEntry("28","03","2004","Sun 28 March","Rev Chris Eddy, HC","Mr Roger Mallard");


	// 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>");
}