//
//  Board meeting display Javascript program
//	Copyright 2003. Greater West Melbourne Athletic Association
//
// To override a date, enter it in the following strings in the format
// mm/dd/yyyy. To note a time other than 7:00 p.m., enter it in the
// time strings. The time will be shown in red exactly as is in these
// strings.
//
wmdate=""; wmtime=""; // GWMAA Meeting Override Date/Time
fbdate=""; fbtime=""; // Football Meeting Override Date/Time
bbdate=""; bbtime="";	// Baseball Meeting Override Date/Time
//
// Gets the R.D. of the next meeting, which occurs on the nth occurence
// of a given day of the week (0 = Sunday, etc.). The value of n should
// always be positive.
//
function NextMeeting(n, day, ordate, ortime)
{
//
// Get the day, month, year values of today.
//
   now = new Date();

   thisday = now.getDate();
   thismonth = now.getMonth() + 1; // javascript returns 0-11
   thisyear = y2k(now.getYear());
//
// Get today's R.D.
//
   thisrd = FixedFromGregorian(thismonth, thisday, thisyear);
//
// Check to see if an override date has been set. If it has not been
// set (length equal 0), then set the meeting's R.D. to -1 so that it
// will always be less than today. If it has been set, convert the
// date to R.D.
//
   if (ordate.length == 0) {
      meetrd = -1; 
   }
   else {
      specmeet = new Date(Date.parse(ordate));

      meetrd = FixedFromGregorian(specmeet.getMonth() + 1,
                                  specmeet.getDate(),
                                  y2k(specmeet.getYear()));
//
//    Set the font color to Red when the override date has been set.
//
      fontcolor = "#ff0000";
   }
//
// If the special meeting date has passed, or if no special meeting
// date was given, then compute the regular meeting date.
//
   if (meetrd < thisrd) {
//
//    If n is negative, then we want the date from the end of the
//    month (e.g., Last Thursday of the month). If n is positive then
//    we want the date from the first of the month (e.g., Third Tuesday
//    of the month). If n is zero, then we want an offset from today 
//    (e.g., Next Wednesday).
//
      if (n < 0) {
         xday = DaysInMonth(thismonth, thisyear);
      }
      else if (n > 0) {
         xday = 1;
      }
      else {
         xday = thisday;
      }
//
//    Find the R.D. of this month's meeting.
//
      meetrd = NthKDay(n, day, thismonth, xday, thisyear);
//
//    If the meeting date has already passed for this month, then
//    get next month's date.
//
      if (thisrd > meetrd) {
         thismonth = thismonth + 1;
         if (thismonth > December) {
            thisyear = thisyear + 1;
            thismonth = January;
         }

         meetrd = NthKDay(n, day, thismonth, xday, thisyear);
      }
//
//    Set the font color to black.
//
      fontcolor = "#000000";
   }

   return(FormatDate(meetrd, fontcolor, ortime));
}
//
// This function converts an R.D. date to a printable Month, Day, Year
// format.
//
function DisplayGregorianDate(rd)
{
   year = GregorianYearFromFixed(rd);
   month = GregorianMonthFromFixed(rd, year);
   day = GregorianDayFromFixed(rd, month, year);

   return(GregorianMonthName(month) + " " + day + ", " + year);
}
//
// This function formats the HTML for the date and time of the meeting.
//
function FormatDate(meetrd, fontcolor, ortime)
{
   retval = '<font color="' + fontcolor + '">' +
            DisplayGregorianDate(meetrd) + " " +
			ortime
            '</font>';

   return(retval);

}
//
// This function returns the date and time of the next GWMAA meeting,
// and the necessary HTML tags to display it.
//
function DisplayGwmaaMeeting()
{
   return(NextMeeting(First, Tuesday, wmdate, wmtime));
}
//
// This function returns the date and time of the next Football board
// meeting and the necessary HTML tags to display it.
//
function DisplayFootballMeeting()
{
   return (NextMeeting(Third, Tuesday, fbdate, fbtime));
}
//
// This function returns the date and time of the next Baseball board
// meeting and the necessary HTML tags to display it.
//
function DisplayBaseballMeeting()
{
   return (NextMeeting(Second, Tuesday, bbdate, bbtime));
}