
function Caption1() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2008-05-16
  //             http://www.merlyn.demon.co.uk/include1.js
  //       Routines may be copied, but URL must not be linked to.
  }

var Inc1T=0
var Site = "Merlyn", Owner = "J R Stockton"
// In lieu of DynWrite :
function Wryt(ID, S) { document.getElementById(ID).innerHTML = S }
// General Utilities :
function LS(n) { return String(n).replace(/\b(\d)\b/g, '0$1') }
function LZ(n) { return (n!=null&&n<10&&n>=0?"0":"") + n }
function LZZ(n) { return (n!=null&&n<100&&n>=0?"0"+LZ(n):""+n) }
function lz(n) { var t = n+"" ; return t.length==1 ? "0"+t : t } // slower?

function TrimS() { // used for String.prototype.trim  \u00A0?
  return (this.toString() ?
    this.toString().replace(/\s+$|^\s+/g, "") : "") }
String.prototype.trim = TrimS

function Space(N) { var S = "" ; while (N--) S += " " ; return S }

function T8(Str) { // Expands Tab to spaces up to Column 8N (EjH)
  var Lines = Str.split("\n"), L, Parts, Row, P, S8 = "        "
  for (L=0 ; L < Lines.length ; L++) { Parts = Lines[L].split("\t")
    Row = "" ; P = 0 ; while (1) { Row += Parts[P]
      if (++P==Parts.length) break
      Row += S8.substring(Row.length%8) /* 1..8 spaces */ }
    Lines[L] = Row }
  return Lines.join("\n") }

function NameFunc(Fn) { // Fn is a function; return its name
  var A = Fn.toString().match(/function\s+(\w+)\(/)
  return A ? A[1] : "anon" }

function DummyF(X) { return X /* Dummy */ }

function Sign(X) { return X>0 ? "+" : X<0 ? "-" : " " }

function Sgnd(X) { return Sign(X) + Math.abs(X) }

function PrfxTo(S, L, C) { S += ""
  if (C.length>0) while (S.length<L) S = C + S ; return S }

function SpcsTo(S, L) { S += "" // SpcsTo is a reduction of PrfxTo
  while (S.length<L) S = " " + S ; return S }

function StrU(X, M, N) { // X > -0.5e-N ; to M digits point N digits
  var St = String(Math.round(X*Math.pow(10, N)))
  if (/\D/.test(St)) return SpcsTo(X, M+N+1) // cannot cope
  St = PrfxTo(St, M+N, "0") ; var J = St.length - N
  return St.substring(0, J) + "." + St.substring(J) }

function StrS(X, M, N) { return Sign(X) + StrU(Math.abs(X), M, N) }

function StrT(X, M, N) { return SpcsTo(StrU(X, 1, N), M+N+2) }

function StrW(X, M, N) { return SpcsTo(StrS(X, 1, N), M+N+2) }

if (!Number.prototype.toFixed) {
  Number.prototype.toFixed = // JL
    new Function("X",
      "  /* toFixed */ if (!X) X=0\n  return StrS(this, 1, X)") }

function Expo(E) { return "e" + (E<0?'-':'+') + LZ(Math.abs(E)) }

function GetSEM(X) { // returns Sign Mantissa Exponent (base 10)
  var U, Obj = { S : Sign(X), E : 0, M : X==U?U:Math.abs(X) }
  with (Obj) { if (M==0 || !isFinite(M)) return Obj
    while (M >= 10) { E++ ; M /= 10 }
    while (M < 1.0) { E-- ; M *= 10 } }
  return Obj }

function NumDecSigFig(X, N) { var U // returns a Number
  if (X==0||X==U) return X
  with (GetSEM(X)) var P = Math.pow(10, N-E-1)
  return Math.round(X*P)/P }

function StrSigFigFxd(X, N) { var U // ?? for 2 <= N <= 16 ??
  if (X==U) return " " + U
  with (GetSEM(X)) { var P, Q
    P = Math.pow(10, N-E-1) ; Q = Math.round(Math.abs(X)*P)/P
    return S + StrU(Q, 1, Math.max(1, N-E-1)) } }

function StrSigFigExp(X, N) { // ?? for 2 <= N <= 16 ??
  with (GetSEM(X))
    return S + StrU(M, 1, N-1) + (isFinite(M) ? Expo(E) : " ") }

function SigFigSet() { // sets globals
  SigFigNum = NumDecSigFig
  SigFigFxd = StrSigFigFxd
  SigFigExp = StrSigFigExp }

SigFigSet()

function SigFigAre() { var IzN = "\t"
  document.write( "Across this site,\n",
    "Name Used\tThe Function\tReturn".italics(),
    "\nSigFigNum", IzN, NameFunc(SigFigNum), "\tNumber",
    "\nSigFigFxd", IzN, NameFunc(SigFigFxd), "\tString '#.#'",
    "\nSigFigExp", IzN, NameFunc(SigFigExp), "\tString '#.#e#'") }

function Div(X, Y) { return Math.floor(X/Y) /* full range */ }

function Mod(X, Y) { return X - Math.floor(X/Y)*Y }

function userIn(Ctrl) { // input for numbers and expressions
  return +eval(Ctrl.value) }

function GetNum(Ctrl) { // input for expressions, allows spaces
  return +eval(Ctrl.value.replace(/[ ]/g, '')) }

function RadBtns(Rbtn, Arr) { var Q, J=0 // Read RadioButtons
  while (Q=Rbtn[J]) { if (Q.checked) return Arr[J] ; J++ } }

// After LRN :

var BoxW = 69

function SafeHTML(S) {
  return S.split("&").join("&amp;").split("<").join("&lt;").
    split(">").join("&gt;") } // IAS

function Depikt(X, Y, S, Hue) { // String S is shown in a box
   }

function ShoTrim(St) {
  var match = /\S([\s\S]*\S)*/.exec(St)
  return match ? match[0] : " eh? " }

function ShoLinCnt(St, Mx) { // counts lines when wrapped at     lineLength Mx
  var Ch, j = xj = CR = NL = 0, Len = St.length, X = 1
  while (j<Len) { Ch = St.charCodeAt(j++)
    if (Ch!=10 && Ch!=13) continue
    if (Ch==10) NL++
    if (Ch==13) CR++
    X += Math.max(Math.floor((j-xj-2)/Mx), 0) ; xj = j }
  // In principle, not quite right, as MSIE wraps at whitespace
  return X + Math.max(NL, CR) }

function ShoGen(A) { // see ShoFFF
  var St = "", Len = A.length, j = 0, Vis = 1, Arg, LC = 0
  while (Len>0) {
    Arg = A[j++]
    if (!Arg) { Vis = 0 ; continue }
    if (Arg.join) Arg =
      "[\n" + Arg.join("\n,\n") + "\n]" // ?? 2006-10-29 ??
    Arg = ShoTrim(Arg.toString())
    St += Arg ; if (Vis) LC += ShoLinCnt(Arg, BoxW)
    if (j==Len) break
    St += "\n\n" ; LC += Vis }
  return {Str:St, Cnt:LC} }

function ShoFFF() {
  // Show code of ArgListed functions, strings; 0 ends visibles
  with (ShoGen(arguments)) Depikt(BoxW, Cnt, Str, "lightgreen") }

function ShoCod(Fn) { // N.B. Fn() should be called externally
  var St = ShoTrim(Fn.toString())
  Depikt(BoxW, ShoLinCnt(St, BoxW), St, "red") }

function ShoDoo(Fn) { // N.B. this calls  Fn() - ADD show others ?
  ShoCod(Fn) ; Fn() /* no visible output expected */ }

function ShoDuu(Fn) { // N.B. this calls  Fn() - ADD show others ?
  ShoCod(Fn) ; ShoOut(Fn) /* visible output expected */ }
// .
var Inc1B=0 // end.

function GlobalNames() {
  Mon3 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  Day3 = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'] }
function Lz(x) { return (x<0||x>=10?"":"0") + x /* local */ }
function LengthOfMonth(Y, M) { // M=1..12 // OK in NS4? Mac?
  with (new Date(Y,M,1,12)) { setDate(0) ; return getDate() } }
ShoDoo(GlobalNames)
ShoFFF(Lz, LengthOfMonth)
