// Event handling array and functions
// implementing events for day and month

// NOTE: Fix bug in generator that forgets the colon after day.
var events = new Array(
{ month: 1, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 2, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 3, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 4, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 5, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 6, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 7, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 8, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 9, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 10, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 11, day: 1, title: "Events", times: "Information", description: "To Be Announced"},
{ month: 12, day: 1, title: "Events", times: "Information", description: "To Be Announced"}
);

//{ month: 2, day: 14, title: "Pantomime &#58; Cinderella", times: "7&#58;15 PM", description: "Cinderella at Gargrave Village Hall<br />AdvanceTickets from newsagents from 18th January&#46;<br />Tickets also on the door&#46; Adults £4&#46;00&#44; Concessions £3&#46;00"},
//{ month: 2, day: 15, title: "Pantomime &#58; Cinderella", times: "7&#58;15 PM", description: "Cinderella at Gargrave Village Hall<br />AdvanceTickets from newsagents from 18th January&#46;<br />Tickets also on the door&#46; Adults £4&#46;00&#44; Concessions £3&#46;00"},
//{ month: 2, day: 16, title: "Pantomime &#58; Cinderella", times: "2&#58;15 PM and 7&#58;15 PM", description: "Cinderella at Gargrave Village Hall<br />AdvanceTickets from newsagents from 18th January&#46;<br />Tickets also on the door&#46; Adults £4&#46;00&#44; Concessions £3&#46;00"})

// Fix dates to this year
var thisYear = 2009;
var dayStrings = new Array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
var monthStrings = new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );

function displayEventDate(day, month)
{
var eventDate = new Date();
var dayMod10 = 0;
var daySuffix;

	eventDate.setFullYear(thisYear,month-1,day);

	// Calculate what suffix to add to the day. like 11th, 21st 3rd
	if(day < 10 || day >= 20)
	{
	  dayMod10 = day % 10;
	}
	
	switch(dayMod10)
	{
  case 1:  daySuffix = "st"; break;
  case 2:  daySuffix = "nd"; break;
  case 3:  daySuffix = "rd"; break;
	default: daySuffix = "th";	  
	}

	document.write('<b>'+dayStrings[eventDate.getDay()]+' '+monthStrings[month-1]+' '+day+daySuffix+'</b> ');
}

// Display an event from the table
function displayTableEntry( i )
{
document.write('<table width="500" cellspacing="0" cellpadding="0" class="smalltext">');
document.write('<tr>');
document.write('<td width="100" align="right" valign="top"><b>'+events[i].title+'</b></td>');
document.write('<td width="5"><img src="transdot.gif" width="5" height="2"></td>');
document.write('<td bgcolor="#808080" width="1"><img src="transdot.gif" width="1" height="2"></td>');
document.write('<td width="5"><img src="transdot.gif" width="5" height="2"></td>');
document.write('<td width="389" valign="top"><b>');
displayEventDate(events[i].day, events[i].month);
document.write(events[i].times+'</b><br />');
document.write(events[i].description+'</td>');
document.write('</tr>');
document.write('</table> <img src="greydot.gif" width="500" height="1" vspace="5">');
}

// Display the title for today's events.
function displayTitle()
{
document.write('<table width="500" cellspacing="0" cellpadding="0" CLASS="smalltext">');
document.write('<tr>');
document.write("<td><b>What's On Today</b></td>");
document.write('</tr>');
document.write('</table>');
}

// Display the events that are on today
function displayDay()
{
  var today = new Date();
	title = 1;
  for(i in events)
	{
	  if(events[i].month == (today.getMonth() + 1) && events[i].day == today.getDate())
		{
		  if(title == 1)
			{
			  title--;
				displayTitle();
			}
		  displayTableEntry(i);
		}
	}
}

// Display the events that are on today
function displayFrontPageDay()
{
  var today = new Date();
	title = 1;
	tableStart=1;
  for(i in events)
	{
	  if(events[i].month == (today.getMonth() + 1) && events[i].day == today.getDate())
		{
		  if(tableStart == 1)
			{
			  tableStart--; // Only display this once.
        document.write('<table width="100%" border="1" bgcolor="#0000ff" cellspacing="1" cellpadding="1" CLASS="smalltext">');
        document.write('<tr><td bgcolor="#ffffff">');
			}
		  if(title == 1)
			{
			  title--;
        document.write("<b>What's On Today</b><br />");
			}
      document.write(events[i].title + ": " + events[i].times + "<br />");
		}
	}
	if(tableStart == 0)
	{
	  document.write('<a href="whatsonthismonth.htm">More Details</a>');
    document.write('</tr></table>');
	}
	else
	{
    document.write('<table width="100%" border="1" bgcolor="#0000ff" cellspacing="1" cellpadding="1" CLASS="smalltext">');
    document.write('<tr><td bgcolor="#ffffff">');
	  document.write('<img src="rightarrow_sw.gif" align="left" hspace="5">Take a look at <a href="whatsonthismonth.htm">whats on this month</a>');
    document.write('</tr></table>');
	}
}

// Display the events that are on this month
function displayMonth(month)
{
  var i;
  for(i in events)
	{
	  if(events[i].month == month)
		{
		  displayTableEntry(i);
		}
	}
}
