
// Object constructor
function diaryEntry(day, month, year,  date, event)
{
   this.day = day;
   this.month = month;
   this.year = year;
   this.date = date; 
   this.event = event;
}

// this function builds the table component of the page
function display_diary()
{
	var dPlan = 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";	
	
	
	
						
	
	
	
	
	dPlan[0] = new diaryEntry("26","11","2009","Thursday 26 November","ACT Pre Advent Service Ashbourne Methodist Church 7.30 pm ");	
	dPlan[1] = new diaryEntry("07","12","2009","Monday 7 December","Midday Prayers at St. John's Ashbourne");	
	dPlan[2] = new diaryEntry("04","01","2010","Monday 4 January","Midday Prayers at Ashbourne Methodist Church");	
	dPlan[3] = new diaryEntry("24","01","2010","Sunday 17 - Sunday 24 January ","Week of prayer for Christian Unity <br> see link on home page.");	
	dPlan[4] = new diaryEntry("01","02","2010","Monday 1 February ","Midday Prayers at All Saints' RC Ashbourne");	
	dPlan[5] = new diaryEntry("31","03","2010","March ","Lent Lunches, details to follow");	
	dPlan[6] = new diaryEntry("12","04","2010","Monday 12 April","Midday Prayers at Christ Church Hulland (provisional");	
	dPlan[7] = new diaryEntry("10","05","2010","Monday 10 May","Midday Prayers at Dovedale House Ilam, by Ashbourne Christian Fellowship");	
	dPlan[8] = new diaryEntry("07","06","2010","Monday 7 June ","Midday Prayers at St Oswald's Parish Church Ashbourne");	
	dPlan[9] = new diaryEntry("05","07","2010","Monday 5 July ","Prayers in the Park, bring a picnic (provisional)");	
	dPlan[10] = new diaryEntry("02","08","2010","Monday  2 August","Midday Prayers at All Saints' RC Ashbourne");	
	dPlan[11] = new diaryEntry("06","09","2010","Monday 6 September","Midday Prayers at Tissington Methodist Chapel");	
	dPlan[12] = new diaryEntry("04","10","2010","Monday 4 October","Midday Prayers at Brailsford Methodist Chapel");	
	dPlan[13] = new diaryEntry("01","11","2010","Monday 1 November","Midday Prayers at St Peter's Parwich (provisional)");	
	dPlan[14] = new diaryEntry("06","12","2010","Monday 6 December","Midday Prayers at St John's Ashbourne");	




	


// set a local variable equal to the length of the array
	var maxEntries=dPlan.length;
	
	// print out the header
	document.write("<table width='100%' border='2'>");
	document.write("<tr align='center'><td>Date</td><td>Event</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 (dPlan[i].year>=ayear)
		{
			// if the year in the Plan is equal to the current year
			if (dPlan[i].year==ayear)
			{
				// is the month in the Plan greater than or equal to the current month 
				if (dPlan[i].month==amonth)
				{
					if (aday>dPlan[i].day)
					{
						printit=0;
					}
					else
					{
						printit=1;
					}
				}
				else
				{
					if (dPlan[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>" + dPlan[i].date + "</td><td>" + dPlan[i].event + "</td></tr>")
			
			// change bgcol
			if (bgcol=="#CCCCCC")
			{
				bgcol="white";
			}
			else
			{
				bgcol="#CCCCCC";
			}
		}
	}
	
	// close the table
	document.write("</table>");
}