
window.onload = writeMessage;

function writeMessage()
{
	var now = new Date();
	
	var dayName   = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
	var monthName = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var numSuffix = new Array("", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
	                              "th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
	                              "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
	                              "st");  
	
	var events = new Array (

"04/18/2010 SunXI v Wonersh (H)",
"04/24/2010 1stXI v Frensham II (H)",
"04/25/2010 SunXI v Godalming (H)",
"05/01/2010 1stXI v Witley (A)",
"05/01/2010 2ndXI v Shalford II (H)",
"05/02/2010 SunXI v Uplands (H)",
"05/08/2010 1stXI v Wrecclesham (H)",
"05/08/2010 2ndXI v Hindhead II (A)",
"05/09/2010 SunXI v Churt (A)",
"05/11/2010 Stevens Cup v Peper Harow (H)",
"05/15/2010 1stXI v Lurgashall (A)",
"05/15/2010 2ndXI v Alton V (H)",
"05/16/2010 SunXI v Brook Strollers (H)",
"05/18/2010 Stevens Cup v Chiddingfold (H)",
"05/22/2010 1stXI v Cody (H)",
"05/22/2010 2ndXI v Alfold (A)",
"05/23/2010 SunXI v Old Woking (H)",
"05/29/2010 1stXI v Wood Street (A)",
"05/29/2010 2ndXI v Bramley (H)",
"05/30/2010 SunXI v Weybridge Vandals (A)",
"06/05/2010 1stXI v Peper Harow (A)",
"06/05/2010 2ndXI v Lindford (H)",
"06/06/2010 SunXI v Abinger (A)",
"06/06/2010 DevXI v Bramley (H)",
"06/08/2010 Pope Cup v Lindford (H)",
"06/12/2010 1stXI v Alfold (H)",
"06/12/2010 2ndXI v Kingsley (A)",
"06/13/2010 SunXI v August Flies (H)",
"06/19/2010 1stXI v Thursley (H)",
"06/19/2010 2ndXI v Farncombe Wanderers (A)",
"06/20/2010 SunXI v Park Hill (H)",
"06/20/2010 DevXI v Grafham & Smithbrook (A)",
"06/22/2010 Pope Cup v Headley (A)",
"06/26/2010 1stXI v Lindford (A)",
"06/26/2010 2ndXI v Alford (h)",
"06/27/2010 SunXI v Waverley (H)",
"07/03/2010 1stXI v Lurgashall (H)",
"07/03/2010 2ndXI v Bramley II (A)",
"07/04/2010 SunXI v Shamley Green (H)",
"07/10/2010 1stXI v Grayshott II (H)",
"07/10/2010 2ndXI v Alton V (A)",
"07/11/2010 SunXI v Tilford (TBC) (A)",
"07/11/2010 DevXI v Ewhurst (H)",
"07/17/2010 1stXI v Wrecclesham (A)",
"07/17/2010 2ndXI v Peper Harow II (A)",
"07/18/2010 DevXI v Littlehampton 2nd XI (H)",
"07/24/2010 1stXI v Wood Street (H)",
"07/24/2010 2ndXI v Shalford II (A)",
"07/25/2010 SunXI v Old Suttonians (H)",
"07/31/2010 1stXI v Cody (A)",
"07/31/2010 2ndXI v Hindhead II (H)",
"08/01/2010 SunXI v Gents of Old Windsor (H)",
"08/02/2010 Blackheath v Cricket Society (H)",
"08/03/2010 Blackheath v Grasshoppers (H)",
"08/04/2010 Blackheath v Kenja Kongonis (H)",
"08/05/2010 Blackheath v Woodpeckers (H)",
"08/06/2010 President's Match (H)",
"08/07/2010 1stXI v Cody (A)",
"08/07/2010 2ndXI v Lindford (H)",
"08/08/2010 SunXI v Cryptics (H)",
"08/14/2010 1stXI v Grayshott II (A)",
"08/14/2010 2ndXI v Farncombe Wanderers (H)",
"08/15/2010 SunXI v The Blues (H)",
"08/21/2010 1stXI v Alfold (A)",
"08/21/2010 2ndXI v Peper Harow II (H)",
"08/22/2010 SunXI v Sunbury Squires (A)",
"08/28/2010 1stXI v Witley (H)",
"08/29/2010 SunXI v Grayswood (A)",
"09/04/2010 1stXI v Frensham II (A)",
"09/04/2010 2ndXI v Kingsley II (H)",
"09/05/2010 SunXI v Mad Hatters (H)",
"09/11/2010 1stXI v Lindford (H)",
"09/12/2010 SunXI v Jack Frost (H)",
"09/18/2010 1stXI v Thursley (A)",
"09/19/2010 SunXI v Ripley (A)",
"09/19/2010 DevXI v Weybridge Vandals (H)",
"09/26/2010 Club Match (H)",
"10/09/2010 End of season dinner",
"11/26/2010 AGM"
	);
	
	var totalEventStr = "";
	var totalDiaryStr = "";
	var eventCount = 0;
	totalEventStr = "<font size=\"2\">";
	
	for (var i = 0; i < events.length; i++)
	{
		var eventStr = events[i];
		var eventDate = eventStr.substring(0,10);
		eventStr = eventStr.substring(11);
		var date = new Date(eventDate);
		if (
		   
		      (date.getFullYear() > now.getFullYear()) ||
		   
		      ((date.getFullYear() == now.getFullYear()) && 
		       ((date.getMonth() == now.getMonth()) && (date.getDate() >= now.getDate()) || 
		        (date.getMonth() > now.getMonth())
		       )
		      )
		   
		   )
		{
			dateStr = dayName[date.getDay()] + " " + date.getDate() + numSuffix [date.getDate()] + " " + monthName[date.getMonth()];
			var str = dateStr + " - " + eventStr;
			if (eventCount < 9)
			{
				if (eventCount > 0)
				{
					totalEventStr = totalEventStr + "<br>" + str;
				}
				else
				{
					totalEventStr = totalEventStr + str;
				}
			}
			eventCount = eventCount + 1;
	
		}	
	}
	totalEventStr = totalEventStr + "</font>";
	
	document.getElementById("WhatsComingList").innerHTML = totalEventStr;
}