
function Caption3() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2004-03-22
  //             http://www.merlyn.demon.co.uk/include3.js
  //       Routines may be copied, but URL must not be linked to.
  //               Needs, for LZ at least, include1.js
  }

var Inc3T=0

// Date/Time Utilities :


// Date.prototype.getTimezoneOffset = new Function("with (this) return 0 ")


if (String.prototype && !String.prototype.substr) {
  String.prototype.substr =
    new Function("J", "K", "return this.substring(J, J+K)") }


function DoWstr(DoWk) { // JS & ISO
  return "SunMonTueWedThuFriSatSun".substr(3*DoWk, 3) }

var Mon3 =
  ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']


Date.prototype.ISOlocaltimeStr =
  new Function("  /* Date.ISOlocaltimeStr */ with (this)\n    return " +
    "LZ(getHours())+':'+LZ(getMinutes())+':'+LZ(getSeconds())")


Date.prototype.USlocaltimeStr =
  new Function("  /* Date.USlocaltimeStr */ var H\n" +
    "  with (this) return " +
    "LZ(  1+((H=getHours())+11)%12  )+':'+\n      LZ(getMinutes())+':'+ " +
    "LZ(getSeconds())+[' AM',' PM'][+(H>11)]")


Date.prototype.ISOlocaldateStr =
  new Function("  /* Date.ISOlocaldateStr */ with (this)\n    return " +
    "getFullYear()+'-'+LZ(getMonth()+1)+'-'+LZ(getDate())")


Date.prototype.ISOlocalDTstr =
  new Function("  /* Date.ISOlocalDTstr */  with (this)\n    return " +
    "ISOlocaldateStr()+' '+ISOlocaltimeStr()")


Date.prototype.UTCstr =
  new Function("  /* Date.UTCstr */ with (this)\n    return " +
    "getUTCFullYear() + '-' + LZ(getUTCMonth()+1) + '-' +\n" +
    "      LZ(getUTCDate()) + ' ' + LZ(getUTCHours()) + ':' +\n" +
    "      LZ(getUTCMinutes()) + ':' + LZ(getUTCSeconds()) ")


Date.prototype.UTCDstr =
  new Function("  /* Date.UTCDstr */ with (this)\n    return " +
    "DoWstr(getUTCDay())+', '+UTCstr()")


Date.prototype.YMDDstr =
  new Function("  /* Date.YMDDstr */ with (this)\n    return " +
    "ISOlocaldateStr() + ' ' + DoWstr(getDay())")


Date.prototype.TZstr = // SIGN SHOULD BE RIGHT
  new Function("  /* Date.TZstr */\n" +
    "  var X, Y, Z ;\n" +
    "  with (this) {\n" +
    "    X = getTimezoneOffset() ; Y = Math.abs(X) ;\n" +
    "    Z = Y % 60 ; Y = (Y-Z)/60 ;\n" +
    "    return (X>0?'-':'+') + LZ(Y) + ':' + LZ(Z) }")



function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
  with (new Date(y, m, d))
    return (getMonth()==m && getDate()==d) /* was y, m */ }


function ReadISO8601date(Q) { var T // adaptable for other layouts
  if ((T = /^(\d+)([-\/])(\d\d)(\2)(\d\d)$/.exec(Q)) == null)
    { return -2 } // bad format
  for (var j=1; j<=5; j+=2) T[j] = +T[j] // some use needs numbers
  if (!ValidDate(T[1], T[3]-1, T[5])) { return -1 } // bad value
  return [ T[1], T[3], T[5] ] }




// MJD 40587 = 1970-01-01 = Javascript day 0.

function YMDtoMJD(y, m, d) { // m = 1..12
  return 40587 + (Date.UTC(y, m-1, d)/864e5) }

function MJDtoYMD(MJD) {
  with (new Date((MJD-40587)*864e5)) {
    return [getUTCFullYear(), getUTCMonth()+1, getUTCDate()] } }

// function MJDtoISOdow(MJD) { return ((MJD-40587+77777773)%7)+1 } // ISO

// function WkNoDtoMJD(Y, N, D) {
//   var Jan4 = YMDtoMJD(Y, 1, 4)
//   var DoWk = (Jan4+777772)%7
//   return Jan4 - DoWk + 7*(N-1) + (D-1) }

// function JDNtoMJD(YYYY, DDD) {
//   return YMDtoMJD(YYYY, 1, 1) + (DDD-1) }

// function LastSun(y, m, ult) {
//   return ult - (YMDtoMJD(y, m, ult)+77777773)%7 }

// end of MJD use



function YMDtoYWD(y, m, d) { // ISO WkNo. m = 1..12
  var ms1d = 864e5, ms3d=3*ms1d, ms7d=7*ms1d
  var D3=Date.UTC(y,m-1,d)+ms3d
  var wk=Math.floor(D3/ms7d)
  with (new Date(wk*ms7d)) { var yy=getUTCFullYear() }
  return [yy, 1+wk-Math.floor((Date.UTC(yy,0,4)+ms3d)/ms7d),
    ((D3/ms1d)+777777)%7+1] // revised 2001-06-28 for < 1970.
  /* for the general case, alter that "0, 4" and maybe "ms3d" */ }


function UKtaxWN(y, m, d) { // m = 1..12
  var St = 'UK Inland Revenue Tax:'
  var fy = y ; if (m*32+d<134) fy--
  var dd = (Date.UTC(y, m-1, d) - Date.UTC(fy, 3, 6))/864e5
  St += ' Year ' + fy + ', week ' +
    LZ(Math.floor(dd/7)+1) + ', day ' + LZ((dd%7)+1) + ';'
  var yy = y, mm = m
  if (d<6) mm--
  if (mm<4) { yy-- ; mm += 12 }
  St += ' Year ' + yy + ', month ' + LZ(mm-3) + '.'
  return St }


function Easter(Yr) { // Gregorian
  // after E G Richards, Algorithm P - upper limit ~ AD 112000?
  var AA = Math.floor(Yr / 100)
  var BB = AA - Math.floor(AA / 4)
  var CC = Yr % 19
  var DD = (15 + 19*CC + BB -
    Math.floor((AA + 1 - Math.floor((AA+8) / 25)) / 3)) % 30
  var EE = DD - Math.floor((CC+11*DD) / 319)
// var S = 22 + EE +
//   (140004 -  Yr - Math.floor(Yr / 4)    + BB - EE) % 7
  var S = 22 + EE +
    (140004 - (Yr + Math.floor(Yr / 4))%7 + BB - EE) % 7
// Extra %7 greatly increases year range - jrs 20021012
  var EMo = 3 + Math.floor(S / 32)
  var EDy = 1 + (S-1) % 31
  return [EMo, EDy] }


function DaysInMonth(Y, M) { // M=1..12   >= 2000-09-01
  with (new Date(Y, M, 1, 12)) {
    setDate(0) ; return getDate() } } // OK in NS4?


function leapyear(y)
  { return (new Date(y, 1, 29)).getMonth() == 1 } // F X Mahoney


function Suffix(j) { return "thstndrd".
  substr("01230000000000000000012300000001".
    charAt(j)*2,2) }


function TimeChangeDates(YYYY) {
  var Ton, Tof, JanOff, JulOff, TonMin, TonMax, TofMin, TofMax, K
  with(new Date(YYYY, 00, 01)) {
    TonMin = TofMin = getTime() ; JanOff = getTimezoneOffset()
    setMonth(06) ; JulOff = getTimezoneOffset()
    if (JanOff == JulOff) { return [0,0] }
    setMonth(12) ; TonMax = TofMax = getTime()
    var Min = Math.min(JanOff, JulOff),
        Max = Math.max(JanOff, JulOff)
    Ton = Tof = (TonMin + TofMax)/2
    for (K=0; K<22; K++) {
      setTime(Ton) ; if (getTimezoneOffset() != Max)
        { TonMax = Ton ; Ton = (TonMin+Ton)/2 }
        else
        { TonMin = Ton ; Ton = (Ton+TonMax)/2 }
      setTime(Tof) ; if (getTimezoneOffset() != Min)
        { TofMax = Tof ; Tof = (TofMin+Tof)/2 }
        else
        { TofMin = Tof ; Tof = (Tof+TofMax)/2 }
      }
    }
  return [Math.round(Ton/6e4)*6e4, Math.round(Tof/6e4)*6e4] }




var Inc3B=0 // end.

