
function Caption1() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2004-05-02
  //             http://www.merlyn.demon.co.uk/include1.js
  //       Routines may be copied, but URL must not be linked to.
  }

var Inc1T=0

function VSF() { document.writeln( // After Michael Donn
  '<a href="view-source:'+this.location+'">View Source File<\/a>') }


// DynWrite(target, text) (Jim Ley) works on controls, after page load :
// it is a computed function :

// Classify browser :

function GetDocVars() { // set 4 Globals; called in include1.js
  nCheck = 0
  if (DocDom = (document.getElementById?true:false))
                                           nCheck++ // NS6 also IE5
  if (DocLay = (document.layers?true:false))
                                           nCheck++ // NS4
  if (DocAll = (document.all?true:false))
                                           nCheck++ // IE4
  }  GetDocVars() // call *here*

// if (nCheck!=1) alert('Browser classification problem!  nCheck = ' +
//  String(nCheck) + '\nPlease let me know how the page works and what' +
//  ' the\nbrowser is; and, if possible, what needs to be done about it.')
function ReportDocVars() {
  if (nCheck==0)
    document.write(' None of DocDom, DocLay, DocAll is set;',
      ' Dynamic Write will fail.'.italics(), '<p>')
  if (DocDom) document.write(' DocDom is set. ')
  if (DocLay) document.write(' DocLay is set. ')
  if (DocAll) document.write(' DocAll is set. ') }

function TableDocVars() {
  document.writeln('<br><br><table summary="Browser class info"',
    ' bgcolor=blue align=center cellpadding=10 border=4>',
    '<tr><th bgcolor=wheat>For the displaying computer :</th>',
    '</tr><tr><td bgcolor=gainsboro align=center>',
    'Your browser gives<br>',
    '<b>DocAll = ', DocAll, ' ; DocDom = ', DocDom,
    ' ; DocLay = ', DocLay, '.</b><br>',
    'Check : ', nCheck, ' browser classification(s) set.',
    '</td></tr></table>') }


// Define Function DynWrite(Where, What) to suit browser :
DocStr=''
if (DocLay) DocStr="return document.layers['NS_'+id]"
if (DocAll) DocStr="return document.all[id]"
if (DocDom) DocStr="return document.getElementById(id)"
GetRef=new Function("id", DocStr)

// DocLay = true ; DocAll = DocDom = false // Simulate NS4.7
DynWarn = 0

if (DocStr=='') { DynWrite=new Function("return false") } else {
  if (DocAll || DocDom) {
    DynWrite=new Function("id", "S", "GetRef(id).innerHTML=S; return true")
    }
// if (DocLay) DynWrite=new Function("id", "S", "var x=GetRef(id).document;"+
//  "x.open('text/html'); x.write(S); x.close(); return true")
if (DocLay) DynWrite=new Function(
    "if (0==DynWarn++)"+
    " alert('DynWrite not supported in \".layers\" browsers');"+
    "return false")
 }


function NoDynLay() {
  if (DocLay) document.writeln(
    '<p><i>Dynamic Writing in a ".layers" browser such as yours ',
    'is difficult and I cannot now test it.  Therefore, ',
    'I don\'t now attempt it. An alert will be given in the ',
    'first use in each load/reload of a page.<\/i>') }

// DynWrite() end.



// General Utilities :

function LS(x) { return String(x).replace(/\b(\d)\b/g, '0$1') }

function LZ(x) { return (x<0||x>=10?"":"0") + x }

function LZZ(x) { return x<0||x>=100?""+x:"0"+LZ(x) }

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

function TrimS() { // Grant Wagner = String.prototype.trim
  return (this.toString() ?
    this.toString().replace(/\s+$|^\s*/g, "") : "") }
String.prototype.trim = TrimS

function Sign(y) {return(y>0?'+':y<0?'-':' ')}

function Prfx(Q, L, c) { var s = Q+"" // ??
  // if (!c) var c = ' '
  if (c.length>0) while (s.length<L) { s = c+s } ;
  return s }

function StrU(X, M, N) { // X>=0.0 ; gives M digits point N digits
  var T, S=new String(Math.round(X*Number("1e"+N))) // *10^N
  if (/\D/.test(S)) { return ''+X } // cannot cope
  with (new String(Prfx(S, M+N, '0')))
    return substring(0, T=(length-N)) + '.' + substring(T) }

function StrT(X, M, N) { return Prfx(StrU(X, 1, N), M+N+2, ' ') }

function StrS(X, M, N) { return Sign(X)+StrU(Math.abs(X), M, N) }

function StrW(X, M, N) { return Prfx(StrS(X, 1, N), M+N+2, ' ') }

if (!Number.toFixed) { // 20030313
  Number.prototype.toFixed = // JL
    new Function('n',
      '  /* toFixed */ if (!n) n=0\n  return StrS(this, 1, n)') }


function SigFigNo(X, N) {
  var p = Math.pow(10, N-Math.ceil(Math.log(Math.abs(X))/Math.LN10))
  return isFinite(p) ? Math.round(X*p)/p : X }


function SigFigExp(X, N) { // N<22
  if (X==0) return SigFigExp(1, N).replace(/\+1/, ' 0')
  var p = Math.floor(Math.log(Math.abs(X))/Math.LN10)
  if (!isFinite(p)) return X
  return (X>0?'+':"") + String(
    Math.round(X*Math.pow(10, N-p-1))).replace(/(\d)/, "$1.") +
    (p>=0?"e+":"e-") + LZ(Math.abs(p)) } // All OK?


function Div(a, b) { return Math.floor(a/b) }

function Mod(a, b) { return a-Math.floor(a/b)*b }


var IxIt=0, BoxX=68


function Depict(X, Y, S, Hue) { // String S is shown and returned
  if (!Hue) Hue = "black"
  var AutoID = "Auto" + ++IxIt
  document.writeln("<form name=", AutoID, ">",
    "<table align=center bordercolor=", Hue, " border=3><tr><td>",
    "<textarea name=N cols=", X, " rows=", Y, " readonly>",
    "<\/textarea><\/td><\/tr><\/table><\/form>")
  document.forms[AutoID].elements["N"].value = S
  return S }


function ShowFF() { // Args are functions, last Arg is box height
  var Len = --arguments.length, S = ""
  for (var j=0 ; j<Len ; j++) {
    if (j>0) S += "\n\n"
    S += arguments[j].toString() } // ???  but replace < > &  ???
  Depict(BoxX, arguments[Len], S, "lightgreen") }


function ShowDo(Fn, Ht) {
  Depict(BoxX, Ht, Fn.toString(), "red" ) ; Fn() }


function eIVSF() {
  Depict(47, 1, "  For the code, view the source of this page.") }


var BID = 0

function PopCode(btn) {
  var Wndw = window.open("", "X"+new Date().getTime(), // /scr-bar?
    "height=" + (16*btn.btnargs[1]+40) + ",width=" + (8*BoxX+40) +
    ",resizable")
  Wndw.document.write(
    '<textarea rows=', btn.btnargs[1], ' cols=', BoxX, '>')
  for (var J=0 ; J < btn.btnargs[0].length ; J++) {
    if (J!=0) Wndw.document.write('\n\n')
    Wndw.document.write(btn.btnargs[0][J].toString()) }
  Wndw.document.write('<\/textarea>')
  Wndw.document.close() /* DU */ }

function Btn() { var I = 'JJ' + BID++ // var BID = 0 precedes these
  document.write("<form name=", I, ">",
    "<input type=button name=N value='Pop Up Code'",
    " onClick='PopCode(this)'><\/form>")
  document.close() // DU
  document.forms[I].elements["N"].btnargs = arguments }


function FuncName(Fn) { // Fn is a function; return its name
  return Fn.toString().match(/( \w+)/)[0] }

var Inc1B=0 // end.


function Caption3() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2004-05-02
  //             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 ZelCMJD(y, m, d) { // Fast.  y += 7e8, result -= ...
  if (m<3) { m += 12 ; y-- }
  return -678973 + d + (((153*m-2)/5)|0) + // 153 = 13 + 5*28
    365*y + ((y/4)|0) - ((y/100)|0) + ((y/400)|0) }


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) { // Detect OS settings
  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.










function DatVal(Q, F) {
		    var Mon, x, Rex, B, Y, ND = 0;
		    Q = Q.trim();
		    if (F == 0) {
		        Rex = /(\d+)(\d{2})(\d{2})$/;
		        Q = Q.search(Rex) == -1 ? "" : Q.replace(Rex, "$1 $2 $3");
		    }
		    Rex = new RegExp(Suf[Lx], "i");
		    Q = Q.replace(Rex, " ");
		    Rex = /([^A-Z]+)([IVX]{1,4})(.*)/i;
		    if (Rex.test(Q)) {
		        Mon = Q.replace(Rex, "$2").toUpperCase();
		        x = " I    II   III  IV   V    VI   VII  VIII IX   X    XI   XII ".indexOf(" " + Mon);
		        Q = Q.replace(Rex, "$1 " + (1 + x / 5) + " $3");
		    }
		    Rex = /([^A-Z]*)([A-Z]{1,3})(.*)/i;
		    if (Rex.test(Q)) {
		        Mon = Q.replace(Rex, "$2").toUpperCase();
		        x = Months[Lx].indexOf(" " + Mon);
		        Q = Q.replace(Rex, "$1 " + (1 + x / 4) + " $3").trim();
		    }
		    Rex = /^(\d+)\D+(\d+)\D+(\d+)$/;
		    if (F == 2) {
		        Q = Q.replace(Rex, "$3 $2 $1");
		    }
		    if (F == 3) {
		        Q = Q.replace(Rex, "$3 $1 $2");
		    }
		    B = Rex.test(Q);
		    if (B) {
		        with (RegExp) {
		            Y = +$1;
		            if (Y < 100) {
		                Y += (Y < 60 ? 2000 : 1900);
		            }
		            with (ND = new Date(Y, $2 - 1, $3)) {
		                B = ((getMonth() == $2 - 1) && (getDate() == $3));
		            }
		        }
		    }
		    return [ND];
		}
		
		
		
		function LangSel() {
		    Lx++;
		    Lx %= Months.length;
		    document.forms.Frm5.Lingo.value = Ln[Lx];
		}
		
		
		
		function Press(F) {
		    with (document.forms.Frm5) {
		        var D = DatVal(In.value, F);
		        Out.value = D[0] ? D[1].ISOlocaldateStr() + " : " + D[1] : "Bad";
		    }
		}
		
		
		
		function TestVal() {
		    document.forms.Frm5.In.value = Tests[TestNo++];
		    TestNo %= Tests.length;
		}
		
		
		
function Setup() {
    Lx = 0;
    Months = new Array(" JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", " JAN FEB MAR APR MAI JUN JUL AUG SEP OKT NOV DEZ");
    Suf = new Array("(st|nd|rd|th)", "(te|ste)");
    Ln = new Array("English", "German");
    Tests = new Array("", "6 3 09", "23/04/1564", "Okt 3 04", "1 au 6", "29 ii 4", "2002-11-23", "12/25/02", "20010203", "25 Novemba 12");
    TestNo = 1;
}
