//-----------------------------------------------------------------------------
//
// Returns the month name
//
//-----------------------------------------------------------------------------
function getMonthName( today )
{
   switch( today.getMonth() )
   {
      case 0: month = "January";
         break;
      case 1: month = "February";
         break;
      case 2: month = "March";
         break;
      case 3: month = "April";
         break;
      case 4: month = "May";
         break;
      case 5: month = "June";
         break;
      case 6: month = "July";
         break;
      case 7: month = "August";
         break;
      case 8: month = "September";
         break;
      case 9: month = "October";
         break;
      case 10: month = "November";
         break;
      case 11: month = "December";
         break;
   }
   
   return month;
}


//-----------------------------------------------------------------------------
//
// Write the calendar table
//
//-----------------------------------------------------------------------------
function showCurrentCalendarMonth()
{
   // I snagged this from http://javascript.internet.com and modified it.
   //
   // Initialize some useful calendar information
   //
   var week = new Array("Su", "M", "T", "W", "Th", "F", "Sa");
   var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // How many days in each month
   var today = new Date();
   var month = today.getMonth();
   var sMonth = getMonthName(today);
   var day = today.getDay();
   var dayN = today.getDate();
   var days = monthdays[month];
   var year = today.getYear();
   // Figure out that old Feb leap year thing
   if (month == 1) 
   {
      if (year%4 == 0) 
      {
         days = 29;
      }
   }
   
   //
   // Start writing calendar table
   //
   document.write("<table border='0' cellspacing='1' cellpadding='3' width='100%'>");
   
   // Write month/year header line
   document.write("<tr><td colspan='7' bgcolor='#9fa189' align='left'><font size='-2' color='#ffffff'><b>&nbsp;" + sMonth + "&nbsp;&nbsp;&nbsp;" + year + "</b></td></tr>");
   
   // Write days of week header line
   document.write("<tr>");
   for (var i=0; i<7; i++) 
   {
      document.write("<td bgcolor='#9fa189' width='30'> <font size='-2' color='#ffffff'>");
      document.write("<div align='center'>" + week[i] + "</div>");
      document.write("</td>");
   }
   document.write("</tr>");
   
   // Write day cells, week by week
   var jumped = 0;
   var tuesdayCount=0;
   var inserted = 1;
   var start = day - dayN%7 + 1;
   if (start < 0) 
      start += 7;
   
   // How many weeks in this month?
   var weeks = parseInt((start + days)/7);
   if ((start + days)%7 != 0) 
      weeks++;
   
   // For each week, write 7 day cells
   for (var i=weeks; i>0; i--) 
   {
      document.write("<tr  bgcolor='#e7e7ca'>");
      for (var j=7; j>0; j--) 
      {
          // If not a valid day for this month leave a blank cell
          if (jumped<start || inserted>days) 
          {
            document.write("<td>");
            document.write("<div align='center'> <font size='-1' color='#336666'></div>");
            jumped++;
          }
          else // Is a valid calendar day for the month
          {
            // Flag special days with color font
            var cellColor = "#336666";  // Default color
            
            // If its the 4th Tuesday flag it (j=5 is tues)
            if( j==5 )
            {
               if( ++tuesdayCount == 4 )
               {
                  cellColor = "red";
               }
            }
               
            // If writing the current day, reverse the colors for emphasis
            if (inserted == dayN) 
            {
               if( cellColor != "red" )
                  cellColor = "#e7e7ca";
               document.write("<a href=\"calendar.htm#" + sMonth + inserted + "\"><td bgcolor='#336666'>");
               document.write("<div align='center'><font size='-1' color=" + cellColor + ">" + inserted + "</div></a>");
            }
            else // otherwise just write the day the normal way
            {
               document.write("<a href=\"calendar.htm#" + sMonth + inserted + "\"><td>");
               document.write("<div align='center'><font size='-1' color=" + cellColor + ">" + inserted + "</div></a>");
            }
            inserted++;
          }
          document.write("</td>")
      }
      document.write("</tr>");
   }
   document.write("</table>");
   document.write("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
   document.write("<tr><td colspan='7' bgcolor='#e7e7ca'><font size=\"-2\" color=\"#336666\">");
   document.write("Click on day to scroll to scheduled event</font></td></tr></table>");
}


//-----------------------------------------------------------------------------
//
// Writes general monthly info below the calendar on the calendar page.
//
//-----------------------------------------------------------------------------
function writeGeneralMonthlyInfo()
{
   document.write("<ul>");
   document.write("   <li>");
   document.write("      <font size=\"-1\" color=\"#336666\"><B>Monthly meetings</B></font><BR>");
   document.write("      <font size=\"-2\" color=\"#336666\"><B>4th Tuesday of each month.<BR>");
   document.write("      <A href=\"meeting.htm\">");
   document.write("      </A><BR>");
   document.write("      Join us at 6:00 pm; bring a snack or brown-bag supper.");
   document.write("      The meeting starts at 6:30. Join us for socializing");
   document.write("      and let's get to know each other!</FONT><BR><BR>");
   document.write("   </li>");
   document.write("</ul>");
   document.write("<BR><center><img src=\"images\\TownSticksSmall.gif\"></center><BR>");
}

