/*
####################################################
# JavaScript Archive                               #
# Author: Paul Thornton                            #
# Creation Date: 15/3/99                           #
# Last Modified: 25/10/99 by Paul Thornton         #
#                                                  #
# Copyright 1999, Paul Thornton,                   #
# Email: P.C.Thornton@exeter.ac.uk                 #
# No part of this script may be used or duplicated #
# without prior consent from the author.           #
####################################################
*/

dayname = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
monthname = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

// showDate(which,format,testing) function
//
// To display the date and/or time in an output format of your choosing with the following options...
//
// "which" variable can be set to either...
//     modified - last modified date and/or time displayed.
//     now (or any other string) - current date and/or time displayed.
//
// "format" variable contains the text to be displayed that can also contain the following codes...
//     hh - display the hour in 24-hour-clock format.
//     mm - display the minute with a leading zero.
//     ss - display the second with a leading zero.
//     DD - display the date as a number.
//     date - display the date as a number with its ordinal (ie 1st, 2nd, 3rd, 4th, etc).
//     day - display the day of the week.
//     MM - display the month as a number.
//     month - display the month name.
//     YY - display the year as its last two digits.
//     year - display the year as four digits.
// "testing" variable can be set to either...
//     "" or left out - last modified date and/or time written to web page.
//     return (or any other string) - last modified date and/or time returned by function.
//
function showDate(which,format,testing) {
  if (which == "modified") {
    d=new Date(document.lastModified);
  }
  else {
    d=new Date();
  }
  hour = ((d.getHours() < 10)?"0":"")+d.getHours();
  minute = ((d.getMinutes() < 10)?"0":"")+d.getMinutes();
  second = ((d.getSeconds() < 10)?"0":"")+d.getSeconds();
  datenum = d.getDate();
  datetext = "th";
  if (datenum == 1 || datenum == 21 || datenum == 31) {
    datetext = "st";
  }
  if (datenum == 2 || datenum == 22) {
    datetext = "nd";
  }
  if (datenum == 3 || datenum == 23) {
    datetext = "rd";
  }
  day = dayname[d.getDay()];
  monthnum = d.getMonth()+1;
  month = monthname[monthnum-1];
  tempyear = d.getYear();
  if (tempyear < 100) {
    yearlong = 2000 + tempyear;
  }
  else {
    if (tempyear < 2000) {
      yearlong = 1900 + tempyear;
    }
    else {
      yearlong = tempyear;
    }
  }
  if (tempyear < 100) {
    yearshort = tempyear;
  }
  else {
    yearshort = tempyear - (Math.floor(tempyear/100)*100);
  }
  yearshort = ((yearshort < 10)?"0":"")+yearshort;
  if (format == "" || format == null) {
    document.write("ERROR!");
  }
  output = "";
  for (i=0;i<=format.length;i++) {
    answer = format.substring(i,i+1);
    if (format.substring(i,i+2) == "hh") {
      answer = hour;
      i+=1;
    }
    if (format.substring(i,i+2) == "mm") {
      answer = minute;
      i+=1;
    }
    if (format.substring(i,i+2) == "ss") {
      answer = second;
      i+=1;
    }
    if (format.substring(i,i+2) == "DD") {
      answer = datenum;
      i+=1;
    }
    if (format.substring(i,i+4) == "date") {
      answer = datenum+datetext;
      i+=3;
    }
    if (format.substring(i,i+3) == "day") {
      answer = day;
      i+=2;
    }
    if (format.substring(i,i+2) == "MM") {
      answer = monthnum;
      i+=1;
    }
    if (format.substring(i,i+5) == "month") {
      answer = month;
      i+=4;
    }
    if (format.substring(i,i+2) == "YY") {
      answer = yearshort;
      i+=1;
    }
    if (format.substring(i,i+4) == "year") {
      answer = yearlong;
      i+=3;
    }
    output += answer;
  }
  if (testing == "" || testing == null) {
    document.write(output);
  }
  else {
    return output;
  }
}

// popup(file,options,width,height) function
//
// To display a popup window containing an HTML file with the following options...
//
// "file" absolute or relative address of the HTML file to be displayed.
// "options" variable containing the window display options comma separated. If no options
//   are specified then all will be set to yes, with options specified all unspecified
//   options are set to no. Possible options are...
//     toolbar=yes/no - display browser toolbar (yes/no).
//     location=yes/no - display browser location entry field (yes/no).
//     directories=yes/no - display browser directory buttons (yes/no).
//     status=yes/no - display browser status bar (yes/no).
//     menubar=yes/no - display browser menu (yes/no).
//     scrollbars=yes/no - display browser scrollbars if required (yes/no).
//     resizable=yes/no - allow popup window to be resized (yes/no).
// "width" width of window variable can be set to either...
//     0 or left out - popup window will appear full screen size.
//     integer value - width of popup window in pixels.
// "height" height of window variable can be set to either...
//     0 or left out - popup window will appear full screen size.
//     integer value - height of popup window in pixels.
//
function popup(file,options,width,height) {
  if ((width != 0 || width !=null) && (height != 0 || height !=  null)) {
    options = options+",width="+width+",height="+height;
  }
  var textWindow=window.open(file,"TextWindow",options);
}
