// Date Modified: 04/22/10 getNewsLetter() - added to provide dynamic link to newsletter editions from bulk email service (specified in html of the email)
// Date Modified: 01/22/10 getEventCalendar() - change to drop yyyy/ from dir string; calendar directory moved up one level under "events"
// Date Modified: 08/21/09 Get sender domain from web page if not specified
// Date Modified: 08/20/09 Add getSSLDomain()
// Date Modified: 02/17/09 Add club to getEventCalendar argument list
// Date Modified: 09/04/08 Alter displayIT to write table definition with correct background color for IT_Class 'All-Day'
// Date Modified: 08/07/08 Alter displayIT to write table definition with correct background color for daily Deadline and Holiday displays
// Date Modified: 07/08/08 Alter displayIT to write table definition with correct background color and id (added 6th argument)
// Date Modified: 02/01/07 Alter sender to accept link class as 5th parameter called class
// Date Modified: 01/10/07 Alter sender to pass W3C xhtml-strict validation
// Date Modified: 12/31/06 Alter getBoardMessage to display monthly file MM.htm
// Date Modified: 11/10/06 Alter displayIT to pass W3C xhtml validation
function sender (ID, which, who, what, classID)
  {
   //alert (ID + ", " + which + ", " + who + ", " + what + ", " + classID);
   var connector = "@";
   var domain = document.domain;
   if (domain.indexOf("www.") >= 0){domain = domain.substring("www.".length)}
   if (which == ''){which = domain;}
   if (sender.arguments.length < 5)
      {var fv1 = ""; var fv2 = "</a>"; var wb="";} 
      else
          if ( isNaN(classID))
             {var fv1 = ""; var fv2 = "</a>"; var wb=" class=\"" + classID + "\" ";} 
             else 
                if (classID == 1) {var fv1 = "<span class=\"small b\">"; var fv2 = "</span></a>"; var wb=" class=\"webmaster\" ";}
                         else {var fv1 = "<span class=\"small b\">"; var fv2 = "</span></a>"; var wb=" class=\"photo\" ";}
   document.write("<a " + wb + "href=\"mail" + "to:" + ID + connector + which + "?" + "subject=" + what + "\">" + fv1 +  who + fv2);
   //alert ("<a " + wb + "href=\"mail" + "to:" + ID + connector + which + "?" + "subject=" + what + "\">" + fv1 +  who + fv2);
   }

function getEventCalendar(club,dir,eventName)
{
  var today = new Date();
  var thisMonth = today.getMonth() + 1;
  if (thisMonth < 10) thisMonth = '0' + thisMonth;
  var thisYear = today.getFullYear();
  //dir = dir.substring(0,dir.length-5);
  document.write ('<a href="' + dir + 'calendar/' + club + '_Events_' + thisYear + '_' + thisMonth + '.htm">' + eventName + '</a>');
  }
function getBoardMessage(dir,eventName)
{
  var today = new Date();
  var thisMonth = today.getMonth() + 1;
  if (thisMonth < 10) thisMonth = '0' + thisMonth;
  var thisYear = today.getFullYear() - 2000;
  if (thisYear < 10) thisYear = '0' + thisYear;
  document.write ('<a href="' + dir + 'messages/' + thisMonth + '.htm">' + eventName + '</a>');
  }
  
function getNewsLetter(history)
{
  var oddMonth, evenMonth, url, urlHeader, urlSuffix;
  var month_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  var today = new Date();
  var thisYear = today.getFullYear();
  var thisMonth = today.getMonth() + 1;
  if (getNewsLetter.arguments.length != 0) {
                                            if (history === 'History'){
                                                                        url = '<a href="http://www.psrr.org/memberinfo/' + thisYear + '/PACESETTER/index.htm"><em><strong>Pacesetter</strong></em>  History</a>';
                                                                        document.write (url);
                                                                        return;
                                                                        }
                                                        else          { 
                                                                        thisMonth = history; //assume a digit was specified
                                                                        for (i=0; i <month_names.length; i++){
                                                                             if (month_names[i] === history) {//check to see if month name specified
                                                                                                              thisMonth = i + 1;
                                                                                                              break; //exit for loop
                                                                                                                }
                                                                                                              }
                                                                        }
                                            }
  if (thisMonth % 2 === 0) {oddMonth = thisMonth - 1; evenMonth= thisMonth;}
                  else     {oddMonth = thisMonth; evenMonth= thisMonth + 1;}
  if (oddMonth < 10) {oddMonth = '0' + oddMonth;}
  if (evenMonth < 10) {evenMonth = '0' + evenMonth;}
  if (thisMonth > today.getMonth() + 1){
                                        urlHeader = "";
                                        urlSuffix = "";
                                        }
                      else              {
                                        urlHeader = '<a href="http://www.psrr.org/memberinfo/' + thisYear + '/PACESETTER/' + oddMonth + '-' + evenMonth +'.pdf">';
                                        urlSuffix = '</a>';
                                        }
                      
  var url = urlHeader + month_names[parseFloat(oddMonth)-1] + '-' + month_names[parseFloat(evenMonth)-1] + urlSuffix;
  //alert(url);
  document.write (url);
  }

function displayIT(IT_date, IT_class, IT_type, IT_id, IT_updated, IT_interval)
{  
  var ITs_date;
  var today = new Date();
  if (displayIT.arguments.length == 0) {document.write ('</span>'); return; }
  if (displayIT.arguments.length > 6) {document.write ('<span style="visibility:hidden;display:none;">'); return; }
  //alert("displayIT: " + IT_date + ', class=' + IT_class  + ', type=' + IT_type + ', id=' + IT_id + ', updated=' + IT_updated + ', interval=' + IT_interval)
  if (IT_updated !== ''){
                          var IT_update_date = new Date(Date.parse(IT_updated));
                          var daysUPDATED = parseInt((today - IT_update_date)/(24*60*60*1000));
                          //alert("Last Updated: " + IT_update_date + " Days: " + daysUPDATED);
                          if (daysUPDATED <= IT_interval){
                                                //alert("displayIT - updated within a week: " + today + ', class=' + IT_class  + ', type=' + IT_type + ', id=' + IT_id + ', updated=' + IT_update_date)
                                                IT_class = 'Updated';
                                                }
                        }
  if (IT_date.indexOf("Midnight") >= 0) {
                                        ITs_date = new Date(Date.parse(IT_date.substr(0,IT_date.indexOf("Midnight")-1))); //Get base Date
                                        //alert("ID=" + IT_id + " Midnight - " + ITs_date);
                                        var ITs_month = ITs_date.getMonth() +1; //get the day of the month (1-12)
                                        var ITs_day = ITs_date.getDate() + 1; //get the day of the month (1-31) plus one
                                        var ITs_year = ITs_date.getFullYear(); //get the year
                                        ITs_date = new Date(Date.parse(ITs_month + '/' + ITs_day  + '/' + ITs_year + ' 00:00:00 AM'));
                                        //alert("Converted Midnight - " + ITs_date);
                                        }
  else if (IT_date.indexOf("Noon") >= 0) {
                                        ITs_date = new Date(Date.parse(IT_date.substr(0,IT_date.indexOf("Noon")-1))); //Get base Date
                                        //alert("Noon - " + ITs_date);
                                        var ITs_month = ITs_date.getMonth() +1; //get the day of the month (1-12)
                                        var ITs_day = ITs_date.getDate(); //get the day of the month (1-31)
                                        var ITs_year = ITs_date.getFullYear(); //get the year
                                        ITs_date = new Date(Date.parse(ITs_month + '/' + ITs_day  + '/' + ITs_year + ' 12:00:00 AM'));
                                        //alert("Converted Noon - " + ITs_date);
                                        }
  else if (isNaN(new Date(Date.parse(IT_date)))) {
                                          //alert('IT_date is not a date: ' + IT_date);  
                                          var ITs_date = today;
                                        }
                        else            {
                                          ITs_date = new Date(Date.parse(IT_date));
                                        }
  if (IT_type == 'd' && IT_class != 'Deadline' && IT_class != 'Holiday' && IT_class != 'All-Day'){if (ITs_date < today) { IT_class = "After";}
                                    else  { IT_class = "Before";}
                      }
//alert ('IT_class=' + IT_class + ' ' + ITs_date + ' today=' + today); 
//For daily displays, keep it visible for the month it happens

  if (IT_type == 'd') {today.setDate(1);} //Set day of month to 1 for daily displays
  //alert ('Today: ' + today + ' ITs_date: ' + ITs_date + ' input date: ' + IT_date);
  if (ITs_date < today) { document.write ('<span class="Invisible">');}
     else               { document.write ('<span class="' + IT_class + '">');}
  //if (displayIT.arguments.length > 5) { 
  //                                     document.write ('<table id="' + IT_id + '" class="' + IT_class + '">');
  //                                     //alert ('<table id="' + IT_id + '" class="' + IT_class + '">');
  //                                      }
  }
  
// Is the date/time after noon
function IsPM(d)
{
   return (d.getHours() >= 12 ? true : false);
}
// Is the date/time noon?
function IsNoon(d)
{
   return (12 == d.getHours() && 0 == d.getMinutes()); 
}
// Is the date/time midnight?
function IsMidnight(d)
{
   return (0 == d.getHours() && 0 == d.getMinutes());
}

function setSSLDomain(fileLocation, eventname)
{
 var domain = document.domain;
 if (domain.indexOf("www.") < 0){domain = "www." + domain}
 //alert('Domain: ' + domain);
 if (domain =='')
                {document.write('<a href="' + fileLocation + '">' + eventname + '</a>');}
         else   {document.write('<a href="https://' + domain + '/' + fileLocation + '">' + eventname + '</a>');}
}