// Filename     : modtime.js
// Version      : 1.0
// Date         : 25/01/2000
// Author       : Anthony West
// Copyright    : Copyright © 1999 Anthony West.

// Displays the modification time of the document
function ModTime()
{
  // Create Array of weekdays
  Weekday = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday");
  // Get last modified time
  ModDate = new Date(document.lastModified);

  // If browser isn't Y2K compliant, fix it
  // Netscape was showing the year to be 1900. Therefore,
  // to fix the problem, I had to add 100 years on to
  // 01/01/1970 and add that onto the lastModified date.
  Y2KTest = ModDate.getTime();
  if (Y2KTest < "0")
  {
    Y2Kfix = new Date(2070,00,00,00,00,00);
    Y2KfixDate = Math.floor(ModDate.getTime()+Y2Kfix.getTime());
    ModDate = new Date(Y2KfixDate);
  }

  // From 'Weekday' Array, get day
  ModDay = Weekday[ModDate.getDay()];

  // Convert modified time to string
  ModString = ModDate.toGMTString();
  ModArray = ModString.split(" ");

  // Same as above but to get local time. Not GMT
  UTCString = ModDate.toString();
  UTCArray = UTCString.split(" ");
  UTCTime = UTCArray[3].split(":");	// UTCTime is in hours:mins:secs format
  // Create suffix depending on date
  DayNum = ModArray[1];
  if (DayNum.substring(0,1) == "0")
  {ModArray[1] = DayNum.substring(1,2);}
  if (ModArray[1] == "1" || ModArray[1] == "21" || ModArray[1] == "31")
  {suffix = "st";}
  else if (ModArray[1] == "2" || ModArray[1] == "22")
  {suffix = "nd";}
  else if (ModArray[1] == "3" || ModArray[1] == "23")
  {suffix = "rd";}
  else
  {suffix = "th";}

  // Create time output. This part is needed as Opera doesn't use the
  // same locations for the time. So if it cannot be calculated correctly,
  // just omit it.
  if(UTCTime[0] == null || UTCTime[1] == null)
  {timeOutput = "last modified";}
  else
  {timeOutput = "last modified at " + UTCTime[0] + ":" + UTCTime[1];}

  // Create message to display
  ModDisplay = timeOutput + " on " + ModDay + " " +
    ModArray[1] +  "" + suffix + " " +
    ModArray[2] + " " + ModArray[3];

  // Display message
  document.write(ModDisplay);
}