/*************************************
	Spartasoft Next Meeting Update	*
	Mathew Mason				*
*************************************/

/*********************
	Initialization	*
*********************/

window.onload = NextMeetingInitialize;	// Initialization functionality

/*********************
	Event Handlers	*
*********************/
// NextMeetingInitialize()
// Sets event handlers

function NextMeetingInitialize()
{
	var dateElement = document.getElementById("nextmeeting");	// span element to add date text to
	var today = new Date();										// today's date
	var nextSunday = new Date();								// object to hold next sunday's date
	var textNode = document.createTextNode("");					// text node to hold date string
	
	nextSunday.setUTCDate(today.getUTCDate() + (7 - today.getUTCDay()));	// set next sunday's date
	
	/*********************************
	 * Start of code edited by Andrea
	 ********************************/
	if(today.getDay() == 0)		// checks to see if today is Sunday. If it is, prints that today is the meeting day
	{
		textNode.nodeValue = PrintDate(today);		// convert to string
		dateElement.appendChild(textNode);		// add to page
	}
	else 		// else if today is not Sunday, says that the date of the meeting is the upcoming Sunday
	{
		textNode.nodeValue = PrintDate(nextSunday);	// convert to string
		dateElement.appendChild(textNode);		// add to page
	}
	/********************************
	 * End of code edited by Andrea
	********************************/
}

/*********************
	Utility Functions	*
*********************/

// GetMonth(month)
// month is some number representing the months (0-11)
// Returns some string value representing the month ("October")

function GetMonth(month)
{
	var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");	// array to hold strings representing all the months
	
	return months[month];
}

// GetDay(day)
// day is some number representing the day of the week (0-6)
// Returns some string value representing the day ("Sunday")

function GetDay(day)
{
	var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");	// array to hold strings representing all the days
	
	return days[day];
}

// PrintDate(nextMeeting)
// nextMeeting is some date object representing the next spartasoft meeting
// returns a string in the form of DayOfTheWeek, Month Date, Year

function PrintDate(nextMeeting)
{
	var day = GetDay(nextMeeting.getUTCDay());			// convert day to string
	var month = GetMonth(nextMeeting.getUTCMonth());	// convert month to string
	var date = nextMeeting.getUTCDate();				// int for date
	var year = nextMeeting.getUTCFullYear();			// int for year (4 digit)
	
	return new String(day + ", " + month + " " + date + ", " + year);
}
