// Meetings page script

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

function updateMeetingScheduleImage()
{

	var today=new Date();
	// Need to match the meetingDates variable array to the meeting.html information
	// Also, add the 1st of September to cover the end of the summer break
	// Date format needs year first or it screws up the year end transition.
	var meetingDates = new Array("2010-01-12",
				     "2010-02-09",
				     "2010-03-09",
				     "2010-04-13",
				     "2010-05-11",
				     "2010-09-01",
				     "2010-09-14",
				     "2010-10-12",
				     "2010-11-09",
				     "2010-12-14");
	var year           = today.getFullYear();
	var month          = today.getMonth() + 1;  //adding 1 because the returned value is base 0
	var todaysDate     = today.getDate();
	//var theCurrentDate = checkTime(month) + "-" + checkTime(todaysDate) + "-" + year;
	var theCurrentDate = year + "-" + checkTime(month) + "-" + checkTime(todaysDate);
	
	var numberOfMeetings = meetingDates.length;
	var i = 0;
	var dateRange = "0000-00-00";  //NOT USED
	
	while(i < numberOfMeetings)
	{
		//return theDate<=meetingDates[i];
		//return theDate + " " + meetingDates[i];
		if(theCurrentDate <= meetingDates[i])
		{
			// RETURN the value of i to select the appropriate 
			// meeting schedule image but remember it starts at 0
			return i;
		}
		
		i++;
		
	}
	
	return "10";
	
	//return theCurrentDate;

}

//Added 11-20-2010
function getSecondTuesdayOfTheMonth(month)
{
//This function is to discover what the second Tuesday of the current month is
// and return that value as it represents the meeting date.
var today      = new Date();
//var month      = today.getMonth() + 1;  //adding 1 because the returned value is base 0
var tuesdayCTR = 0;
var dayCTR     = 1;
var dayOfWeekToTest = 0;  

if(month == "year")
{
	return today.getFullYear();
}

	today.setMonth(month - 1); //Sets so we can check the passed in month for its second Tuesday

	while(dayCTR < 32)
	{
		today.setDate(dayCTR);
		dayOfWeekToTest = today.getDay();
		
		if(dayOfWeekToTest == 2)
		{
			tuesdayCTR++;
			if(tuesdayCTR == 2)
				{
				// we have found the second Tuesday of the week for the current month
				
				// var secondTuesDate = checkTime(month) + "-" + checkTime(today.getDate()) + "-" + today.getFullYear();

				// return secondTuesDate;
				return today.getDate();
				}
		}	
		dayCTR++;
	}
	return "0000-00-00"  //nothing found if this is returned
}

function hasDatePassed(month)
{
	var computerDate = new Date();
	
	// todaysDate in the YYYYMMDD format
	var todaysDate = computerDate.getFullYear() +""+ checkTime(addOne(computerDate.getMonth())) +""+ checkTime(computerDate.getDate());
	//return todaysDate;
	var secondTuesToCompare = computerDate.getFullYear() +""+ checkTime(month) +""+ checkTime(getSecondTuesdayOfTheMonth(month));
	//return secondTuesToCompare;
	if(todaysDate > secondTuesToCompare)
	{
		return "#7E7E7E"; //greyish color
	}
	
	return "black";
}

function addOne(whatToAddTo)
{
	return whatToAddTo + 1;
}
