/**
 * This script writes the next meeting schedule.
 *
 * @author Stanley Kubasek
 * @update 9/11/2008
 *
 * NOTE: If we don't have a meeting on a given Saturday,
 * add that date (mm/dd format) to noMeetingDates variable.
 * 
 * NOTE 2: If we have a meeting in alternate location, modify
 * the alternateMeetingDates variable.
 */

/**
 * MEETING IN A DIFFERENT LOCATION
 * 
 * To add, either edit what's in the alternateMeetingDates variable (below),
 * or add this line below
 * IMPORTANT: leave quotes, brackets, and the comma in place
 * 		
 *		[ "9/20", "place description" ],
 */ 
var alternateMeetingDates = [

		// ADD NEW ONES BELOW THIS LINE
		["11/8", "at the Lyndhurst Public Library on 355 Valley Brook Avenue in Lyndhurst, NJ 07071"],
		["11/15", "at the Lyndhurst Public Library on 355 Valley Brook Avenue in Lyndhurst, NJ 07071"],
		["5/3", "at an ALTERNATE LOCATION. We will meet at 278 Mountain Way, Rutherford, NJ 07070 (<a href=\"http://maps.google.com/maps?f=q&hl=en&geocode=&q=278+Mountain+Way,+Rutherford,+NJ+07070&sll=37.0625,-95.677068&sspn=76.967897,102.480469&ie=UTF8&ll=40.818616,-74.108019&spn=0.009305,0.01251&z=16&iwloc=addr\">location on a map</a>)"]

];

/**
 * NO MEETINGS ON THESE DATES
 * 
 * TO ADD: either replace existing text, or add a ", month/day" to the end.
 * IMPORTANT: leave quotes, brackets, commas in place
 */
var noMeetingDates = new Array( "11/28", "12/19", "12/26", "1/2" );



/*** DO NOT EDIT ANYTHING BELOW ***/

function writeNextMeetingDate() {
	var weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var month = new Array("January","February","March","April","May","June","July", "August", "September", "October", "November", "December")
	var d = getNextMeetingDate();

	document.write(
			weekday[ d.getDay() ] + ", " + 
			month[ d.getMonth() ] + " " + 
			d.getDate() + ", " + 
			getYear(d)); 
}

function getYear(d) {
	if (d.getYear() > 2000)
		return d.getYear();
	
	return (d.getYear() + 1900);
}

function writeNextMeetingLocation() {
	var d = getNextMeetingDate();
	var nxtMtgDate = "" + (d.getMonth() + 1) + "/" + d.getDate();

	var mtgPlace = " at the Rutherford Public Library";
	for (var i = 0; i < alternateMeetingDates.length; i++) {
		if (alternateMeetingDates[i][0] == nxtMtgDate) {
			mtgPlace = alternateMeetingDates[i][1];
		}
	}
	document.write( mtgPlace );

}

function getNextMeetingDate() {
	var d = new Date();
	d.setDate(d.getDate() + 6 - d.getDay());

	var nxtMtgDate = "" + (d.getMonth() + 1) + "/" + d.getUTCDate();

	// take into condiration "the no meetings" array and set
	// a date according to it

	for (var i = 0; i < noMeetingDates.length; i++) {
		// if there is not meeting next week
		if (noMeetingDates[i] == nxtMtgDate) {
			// we have to start over with next week's date
			d.setDate(d.getDate() + 7);
			nxtMtgDate = "" + (d.getMonth() + 1) + "/" + d.getUTCDate();
		}
		else {
			// we have a meeting
			continue; 
		}
	}

	return d;
}