<!-- Begin

// dateinfo.js - contains date display and info scripts

var months = new Array ( "January", "February", "March", "April", "May", "June",
                         "July", "August", "September", "October", "November", "December" );

var days = new Array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );

// Constant - milliseconds per day
var msPerDay = 24 * 60 * 60 * 1000 ;

// Function - returns the current day of the year
function dateString(inputDate)
{
  replyString = "" ;

  var lMon = months[inputDate.getMonth()]; // month
  var lDow = days[inputDate.getDay()];  // day of week
  var lDay = inputDate.getDate(); // day
  var lYear = inputDate.getFullYear(); // year

  replyString += "" + lDow + ", " + lDay + " " + lMon + ", " + lYear ;

  return replyString ;
}

// Function - this builds and returns 1-line messages for upcoming events
function dateMsg(responses)
{
  var matches = 0 ; // Counts valid matches

  // Get today's date
  today = new Date() ;

  replyString = "" ;

  for (i = 0; i < eventDate.length; i++ )
  {
    // Work out days between today and the current event
    interval = ( eventDate[i].getTime() - today.getTime() ) / msPerDay ;
    interval = Math.ceil(interval) ;

    if( interval < 0 )
      continue ; // Event is in the past
    else if( interval == 0 )
    {
      replyString += "<B>TODAY</B>" ;
    }
    else if( interval == 1 )
    {
      replyString += "<B>TOMORROW</B>" ;
    }
    else
    {
	  replyString += dateString(eventDate[i]) ;
    }

    replyString += " - " + eventTitle[i] + "<BR>" ;

    matches++ ;

    // If responses > zero, only send back that many matches (if responses = zero, send back all)
    if( ( responses > 0 ) && ( responses <= matches ) )
      break ;
  }

  return( replyString ) ; // returns default
}

// Function - this builds and returns a table of events.
function dateTable()
{
  // Get today's date
  today = new Date() ;

  // Start with table tags and column headers.  StyleSheet defaults will be used
  replyString = "<TABLE>" ;
  //replyString += "<TR BGCOLOR=\"#ffffff\"><TH>Date</TH><TH>Event</TH><TH>Speaker</TH><TH>Info</TH></TR>" ;
  replyString += "<TR BGCOLOR=\"#ffffff\"><TH>Date</TH><TH>Event</TH><TH>Speaker</TH></TR>" ;

  // Add entries for every date in the calendar
  for (i = 0; i < eventDate.length; i++ )
  {
    // Check if the event is in the future
    interval = ( eventDate[i].getTime() - today.getTime() ) / msPerDay ;
    interval = Math.ceil(interval) ;

    if( interval < 0 )
      continue ; // Event is in the past

    // Add this event to the table (alternate background colour)
    if( i%2 == 0 )
      replyString += "<TR BGCOLOR=\"#ddeeff\">" ;
    else
      replyString += "<TR BGCOLOR=\"#ccddee\">" ;

    // Start with the date...
    replyString += "<TD>" ;

    // Highlight today's and tomorrow's events
    if( ( interval == 0 ) || ( interval == 1 ) )
      replyString += "<B>" ;

    replyString += dateString( eventDate[i] ) ;

    if( ( interval == 0 ) || ( interval == 1 ) )
      replyString += "</B>" ;

    replyString += "</TD>" ;

    // ... the event ...
    replyString += "<TD>" + eventTitle[i] + "</TD>" ;

    // ... the Speaker / host ...
    replyString += "<TD>" + eventSpeaker[i] + "</TD>" ;

    // ... and now handle any further information
    //if( eventInfo[i].length > 0 )
    //{
	//	var divName = "div_" + i ;
	//	replyString += "<TD><CENTER><A href=\"javascript:show_hide(" + divName + ")\">Info...</a></CENTER></TD>" ;
	//	replyString += "</TR><TR>" ;
	//	replyString += "<TD colspan='4'>"
	//	replyString += "<div id=" + divName + " name=" + divName + " style=\"height: 1px; overflow: hidden\">" ;
	//	replyString += eventInfo[i] ;
	//	replyString += "</div></TD>"
	//}
	//else
	//{
	//	replyString += "<TD>&nbsp;</TD>" ;
	//	replyString += "</TR><TR><TD height=\"2px\"></TD>"
	//}

    // Finally, close off the row
    replyString += "</TR>" ;
  }

  // Close off the table...
  replyString += "</TABLE>" ;

  // ...and return it to the calling page
  return( replyString ) ;
}

// ---------------------------------------------------------------------------------------------

// End -->

