/*
   ###########################################################################
   Friday the 13th

   This function simply returns a table of all Friday-the-13ths for any given
   year or range of years on the modern Gregorian calendar or the old Julian
   calendar.

   There must be at least one Friday-the-13th in a year, but there can be as
   many as three in some years.

   THE GENERAL RULE:
   On either the old Julian or the modern Gregorian calendar, any month that
   begins on a Sunday, has a Friday-the-13th in that month.

   ARGUMENTS:
   StartYear = Calendar Year > 0
   StopYear >= StartYear
   CalMode   = Calendar Mode ('J' = Julian  or  'G' = Gregorian = Default)

   Given any two years where (StopYear >= StartYear), this function will
   return a table of all Friday the 13ths in the given year range.
   If StopYear == empty, then StopYear = StartYear.

   If (StopYear) is empty, then only the single (StartDate) is used.

   For old Julian calendar dates, the returned dates will have a 'J' suffix.

   ERRORS:
   An error message is returned if non-numeric argument(s).

   NO DEPENDENCIES
   ###########################################################################
*/

   function Friday_the_13th ($StartYear='', $StopYear='', $JorG='G')
{
// ---------------------
// Read input arguments.

   $StartY  = trim($StartYear);
   $StopY   = trim($StopYear);

// ------------------------------------------------------
// If (StartY is empty, then use current year as default.

   if ($StartY == '') {$StartY = date('Y');}

// ------------------------------------------------
// If (StopY) is empty, then equate it to (StartY).

   if ($StopY == '') {$StopY = $StartY;}

// ---------------------------------
// Error if non numeric argument(s).

   if (!Is_Numeric($StartY) or !Is_Numeric($StopY))
       {return 'ERROR: Year argument must be an integer (Negative = BC).';}

// ------------------------------------------------------
// If (StopY < StartY), then Swap (StartY, StopY) values.

   if ($StopY < $StartY){$w = $StopY;  $StopY = $StartY;  $StartY = $w;}

// -----------------------------------
// Get Julian/Gregorian calendar mode.
// Only 'J' or 'G' allowed.
// Logic: If not 'J', then 'G', by default.

   $JG = substr(StrToUpper(trim($JorG)),0,1);
   $JG = ($JG == 'J')? 'J' : 'G';

// -------------------------------------------
// Cycle through each year in the given range.

   $uTable = '';

   for ($Y = $StartY;  $Y <= $StopY;  $Y++)
{
   $wTable = '';

// -------------------------------------------
// Cycle through each month of the given year.

   for ($m=1;   $m <= 12;   $m++)
  {
   $JDNum = ($JG == 'J')? JulianToJD($m,1,$Y) : GregorianToJD($m,1,$Y);

// -----------------------------------------------
// If a month begins on a Sunday, then the 13th of
// that month is a Friday, so add it to the list.

   if (($JDNum + 1) % 7 == 0)
      {
       $YStr = Str_Replace('-','BC ', $Y);
       $Mmm = JDMonthName($JDNum,(($JG == 'J')? 2:0));
       $wTable .= "$YStr-$Mmm-13-Fri $JG\n";
      }
  }
   $uTable .= "\n".trim($wTable)."\n";
}
   $w = trim($uTable);

   return "
$w
"; } // END OF Friday_the_13th (...)