///////////////////////////////////////////////////////////////////////////////////////////
//
// Program : diary.js
// Purpose : To provide an events diary where only today and future events are displayed to 
//		reduce the update time required. Translates dates into standard format
//		e.g. Friday 15 February 2002.
// Author : Greg Griffiths (greg.griffiths@greggriffiths.org)
// Version : 1.0
// Release Date : 15 February 2002
// URL : http://www.greggriffiths.org/webdev/clientside/javascript/eventsdiary/
//
// © Copyright : Greg Griffiths (2002)
//
// This Javascript script is for freeware use, however, the owner would appreciate a mention on the
// users site including a link back to his site as well as being told where his code is being used.
// 
///////////////////////////////////////////////////////////////////////////////////////////

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

// this function builds the table component of the page
function display_diary()
{
	var eventDiary = 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";	
	
	// this is the diary, one row per event, remember that the first row must be eventDiary[0]
eventDiary[0] = new eventInfo("02","01","2004","Cyprus","Deadline submitting songs");
eventDiary[1] = new eventInfo("03","01","2004","Lithuania","first semi-final");
eventDiary[2] = new eventInfo("04","01","2004","Belarus","Announcement songs for the final");
eventDiary[3] = new eventInfo("06","01","2004","Greece","start second round EuroStar");
eventDiary[4] = new eventInfo("07","01","2004","The Netherlands","announcement participants Nationaal Songfestival 2004");
eventDiary[5] = new eventInfo("10","01","2004","Lithuania","second semi-final");
eventDiary[6] = new eventInfo("11","01","2004","Slovenia","first semi-final EMA 2004");
eventDiary[7] = new eventInfo("16","01","2004","Finland","first semi-final Euroviisut 2004");
eventDiary[8] = new eventInfo("17","01","2004","Lithuania","third semi-final");
eventDiary[9] = new eventInfo("17","01","2004","Finland","second semi-final Euroviisut 2004");
eventDiary[10] = new eventInfo("18","01","2004","Slovenia","second semi-final EMA 2004");
eventDiary[11] = new eventInfo("18","01","2004","Portugul","Operacio Triunfo 2 final");
eventDiary[12] = new eventInfo("18","01","2004","Belgium","Semifinal 1 Eurosong 2004");
eventDiary[13] = new eventInfo("22","01","2004","The Netherlands","first semi-final Nationaal Songfestival 2004");
eventDiary[14] = new eventInfo("24","01","2004","Finland","final Euroviisut 2004");
eventDiary[15] = new eventInfo("24","01","2004","Lithuania","fourth semi-final");
eventDiary[16] = new eventInfo("24","01","2004","Poland","final");
eventDiary[17] = new eventInfo("24","01","2004","Turkey","song selection for band Athena");
eventDiary[18] = new eventInfo("25","01","2004","Belarus","final");
eventDiary[19] = new eventInfo("25","01","2004","Portugal","final results (Operacio Triunfo 2)");
eventDiary[20] = new eventInfo("25","01","2004","Slovenia","third semifinal EMA 2004");
eventDiary[21] = new eventInfo("25","01","2004","Belgium","second semifinal Eurosong 2004");
eventDiary[22] = new eventInfo("28","01","2004","Spain","Operation Triunfo-final-song chosen");
eventDiary[23] = new eventInfo("29","01","2004","Israel","final");
eventDiary[24] = new eventInfo("29","01","2004","The Netherlands","second semi-final Nationaal Songfestival 2004");
eventDiary[25] = new eventInfo("31","01","2004","Lithuania","fifth semi-final");
eventDiary[26] = new eventInfo("01","02","2004","Slovenia","fourth semi-final EMA 2004");
eventDiary[27] = new eventInfo("01","02","2004","Belgium","third Semi-final Eurosong 2004");
eventDiary[28] = new eventInfo("05","02","2004","The Netherlands","third semifinal Nationaal Songfestival 2004");
eventDiary[29] = new eventInfo("07","02","2004","Estonia","final Eurolaul 2004");
eventDiary[30] = new eventInfo("07","02","2004","Denmark","final Melodi Grand Prix 2004");
eventDiary[31] = new eventInfo("07","02","2004","Lithuania","sixth semi-final");
eventDiary[32] = new eventInfo("08","02","2004","Belgium","fourth semi-final Eurosong 2004");
eventDiary[33] = new eventInfo("12","02","2004","The Netherlands","second semi-final Nationaal Songfestival 2004");
eventDiary[34] = new eventInfo("14","02","2004","Latvia","Previews songs for national final");
eventDiary[35] = new eventInfo("14","02","2004","Lithuania","final");
eventDiary[36] = new eventInfo("14","02","2004","Malta","final");
eventDiary[37] = new eventInfo("15","02","2004","Slovenia","final EMA 2004");
eventDiary[38] = new eventInfo("15","02","2004","Belgium","final Eurosong 2004");
eventDiary[39] = new eventInfo("17","02","2004","Cyprus","final");
eventDiary[40] = new eventInfo("19","02","2004","The Netherlands","2nd chance heat Nationaal Songfestival 2004");
eventDiary[41] = new eventInfo("20","02","2004","Serbia & Montenegro","Beovivija 2004 (4 songs go to Evropesma)");
eventDiary[42] = new eventInfo("21","02","2004","Sweden","first semi-final Melodifestivalen 2004");
eventDiary[43] = new eventInfo("21","02","2004","Serbia & Montenegro","Evropesma 2004");
eventDiary[44] = new eventInfo("22","02","2004","The Netherlands","final Nationaal Songfestival 2004");
eventDiary[45] = new eventInfo("28","02","2004","Sweden","second semi-final Melodifestivalen 2004");
eventDiary[46] = new eventInfo("28","02","2004","Latvia","final Eirodziesma 2004");
eventDiary[47] = new eventInfo("28","02","2004","United Kingdom","final Making Your Mind Up");
eventDiary[48] = new eventInfo("06","03","2004","Switzerland","final Song://04");
eventDiary[49] = new eventInfo("06","03","2004","Norway","final Melodi Grand Prix 2004");
eventDiary[50] = new eventInfo("06","03","2004","Ireland","first part final You're a star");
eventDiary[51] = new eventInfo("06","03","2004","Sweden","third semi-final Melodifestivalen 2004");
eventDiary[52] = new eventInfo("07","03","2004","Ireland","final You're a star");
eventDiary[53] = new eventInfo("13","03","2004","Croatia","semi-final Dora 2004");
eventDiary[54] = new eventInfo("13","03","2004","Sweden","fourth semi-final Melodifestivalen 2004");
eventDiary[55] = new eventInfo("14","03","2004","Croatia","final Dora 2004");
eventDiary[56] = new eventInfo("14","03","2004","Sweden","second chance heat Melodifestivalen 2004");
eventDiary[57] = new eventInfo("14","03","2004","Andorra","final 12 points");
eventDiary[58] = new eventInfo("19","03","2004","Germany","final 12 points for Germany");
eventDiary[59] = new eventInfo("20","03","2004","Sweden","final Melodifestivalen 2004");
eventDiary[60] = new eventInfo("22","03","2004","Istanbul","Head of Delegations meeting & draw for running order");
eventDiary[61] = new eventInfo("23","03","2004","Istanbul","Head of Delegations meeting");
eventDiary[62] = new eventInfo("12","05","2004","Istanbul","Eurovision Song Contest Qualifier round");
eventDiary[63] = new eventInfo("15","05","2004","Istanbul","Eurovision Song Contest Final");

	// set a local variable equal to the length of the array
	var maxEntries=eventDiary.length;
	
	// print out the header
	document.write("<table width='100%' border='1' BORDERCOLOR='#000000' CELLPADDING=1 CELLSPACING=0>");
	document.write("<tr align='center'><td><font size='2'>Date</font></td><td><font size='2'>Country</font></td><td><font size='2'>Event</font></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 (eventDiary[i].year>=ayear)
		{
			// if the year in the Plan is equal to the current year
			if (eventDiary[i].year==ayear)
			{
				// is the month in the Plan greater than or equal to the current month 
				if (eventDiary[i].month==amonth)
				{
					if (aday>eventDiary[i].day)
					{
						printit=0;
					}
					else
					{
						printit=1;
					}
				}
				else
				{
					if (eventDiary[i].month>amonth)
					{
						printit=1;
					}
					else
					{
						printit=0;
					}
				}
			}
			else
			{
				printit=1;
			}
		}
		else
		{
			printit=0;
		}
		
		// if the row should be printed
		if (printit==1)
		{
			// build a date 
			var myDate = new Date (eventDiary[i].year,(eventDiary[i].month - 1),eventDiary[i].day);
			whichDay = myDate.getDay();
					
			// convert the day value to a proper day value
			switch (whichDay)
			{
				case 0:
					whichDayName="Sunday";
					break;
				case 1:
					whichDayName="Monday";
					break;
				case 2:
					whichDayName="Tuesday";
					break;
				case 3:
					whichDayName="Wednesday";
					break;
				case 4:
					whichDayName="Thursday";
					break;
				case 5:
					whichDayName="Friday";
					break;
				case 6:
					whichDayName="Saturday";
					break;
			}
			
			// convert the month value to a proper month value
			whichMonth = myDate.getMonth();
			
			switch(whichMonth)
			{
				case 0:
					whichMonthName="January";
					break;
				case 1:
					whichMonthName="February";
					break;
				case 2:
					whichMonthName="March";
					break;
				case 3:
					whichMonthName="April";
					break;
				case 4:
					whichMonthName="May";
					break;
				case 5:
					whichMonthName="June";
					break;
				case 6:
					whichMonthName="July";
					break;
				case 7:
					whichMonthName="August";
					break;
				case 8:
					whichMonthName="September";
					break;
				case 9:
					whichMonthName="October";
					break;
				case 10:
					whichMonthName="November";
					break;
				case 11:
					whichMonthName="December";
					break;
			}

			document.write("<tr align='center'><td><font size='2'>" + whichDayName + " " + eventDiary[i].day + " " + whichMonthName + " " + eventDiary[i].year + "</font></td><td><font size='2'>" + eventDiary[i].venue + "</font></td><td><font size='2'>" + eventDiary[i].event + "</font></td></tr>")

		}
	}
	
	// close the table
	document.write("</table>");
}
