﻿
function GetCurrentYear( )
{
    var now;
    
    now = new Date;
    document.write( now.getFullYear( ) );
}


function CalculateSecondSaturday( theDate )
{
  var dayToCheck, testDate, currentMonth, currentYear;

  currentMonth = theDate.getMonth(); // 0-11
  currentYear  = theDate.getFullYear(); // 2010

  // Get to 1st Saturday

  dayToCheck = 1;
  testDate = new Date( currentYear, currentMonth, dayToCheck );

  while ( testDate.getDay() < 6 )
  {
    dayToCheck++;
    testDate = new Date( currentYear, currentMonth, dayToCheck );    
  }

  // At this point should be at 1st Saturday

  dayToCheck += 7;

  // This date should be 2nd Saturday

  return new Date( currentYear, currentMonth, dayToCheck );

}




function CalculateNextSecondSaturday( )
{
  var months = new Array(13);
  months[0]  = "January";
  months[1]  = "February";
  months[2]  = "March";
  months[3]  = "April";
  months[4]  = "May";
  months[5]  = "June";
  months[6]  = "July";
  months[7]  = "August";
  months[8]  = "September";
  months[9]  = "October";
  months[10] = "November";
  months[11] = "December";

  var now, secondSaturday, nowMonth, nowDay, nowYear;

  now = new Date();

  secondSaturday = CalculateSecondSaturday( now );

  if ( now > secondSaturday )
  {

    // Set day to 1st of month
    now.setDate( 1 );
    // Add a month
    now.setMonth(now.getMonth() + 1);

    
    secondSaturday = CalculateSecondSaturday( now );
  }

  nowMonth = secondSaturday.getMonth();
  nowDay   = secondSaturday.getDate();
  nowYear  = secondSaturday.getFullYear();

  document.write( "<span id='blue'><strong>--> Next Distribution Date:&nbsp;&nbsp;" + months[nowMonth] + " " + nowDay + ", " + nowYear + " <--</strong></span>" );

}

