// ****************************************************************************************************************
{<!-- More JavaScript playing by tvb 2000-06-14 -->

    function GetYear (date) {
        var year = date.getYear();
        if (year < 1900) year += 1900;
        return year;
    }
    function GetMonth (date) {
        return date.getMonth() + 1;
    }
    function GetDay (date) {
        return date.getDate();
    }

    function idiv (n, d) { return Math.floor(n / d); }

    function GetMjd (date) {
        var year = GetYear(date);
        var month = GetMonth(date);
        var day = GetDay(date);
        var mjd =
        367 * year
        - idiv(7 * (idiv(month + 9, 12) + year), 4)
        - idiv(3 * (idiv(idiv(month + 9, 12) + year - 1, 100) + 1), 4)
        + idiv(275 * month, 9)
        + day
        + 1721028
        - 2400000;
        return mjd;
    }

    function GetMjdFraction (date) {
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        var elapsed = ((hour * 60) + minute) * 60 + second;
        return Math.floor((elapsed / 86400) * 1E5);
    }

    var DigitImage;

    function LoadImages () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_quad" + i + ".jpg";
        }
    }

    function LoadImagesNix () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_nix" + i + ".jpg";
        }
    }
    function LoadImagesRP () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_rp_" + i + ".jpg";
        }
    }
		
    function LoadImagesEG () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_eg_" + i + ".jpg";
        }
    }
    function LoadImagesRCA () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_num_" + i + ".jpg";
        }
    }

    function LoadImagesHP () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_hp ac-4a_" + i + ".jpg";
        }
    }
    function LoadImagesPIX () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_PIX_" + i + ".jpg";
        }
    }

    function LoadImagesLCD () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_lcd_" + i + ".jpg";
        }
    }
    function LoadImagesBlank () {
        var i;
        DigitImage = new Array;
        for (i = 0; i < 10; i++) {
            DigitImage[i] = new Image;
            DigitImage[i].src = "menuImages/TN_nixdp.jpg";
        }
    }
		
		
    function Digit (n, i) {
        while (--i > 0) {
            n = Math.floor(n / 10);
        }
        return DigitImage[n % 10].src;
    }

    var TimerId = null;
    var TimerIdValid = 0;
    var LastSecond = -1;

    var LeapSecondPendingThisMonth = 0;
    var LeapSecondNow = 0;
    var LeapSecondPcOffset = 0;

    function DisplayTime () {

        // Get current time (millisecond resolution).

        var now = new Date();
        var local = new Date();

        // Avoid re-display if seconds haven't changed.

        var second = local.getSeconds();
        if (second == LastSecond) {
            return;
        }
        LastSecond = second;

        while (1) {

            // Apply leap second correction (PC runs TDT not UTC).

            var t = local.getTime() + LeapSecondPcOffset;
            local.setTime(t);

            // Compute UTC from local time.

            utc = new Date(t + (local.getTimezoneOffset() * 60 * 1000));

            // Check for leap second at end of month.

            if (GetYear(utc) == 2001 && GetMonth(utc) == 6 && GetDay(utc) > 1) {
                LeapSecondPendingThisMonth = 1;
            }

            //
            // At start of leap second recalculate date/time.
            // The JavaScript Date class cannot represent a leap
            // second and the PC/browser is unlikely to know
            // about leap seconds so the calculation and display
            // of leap seconds is done manually.
            //

            if (LeapSecondPendingThisMonth &&
                (utc.getDate() == 1) &&
                (utc.getHours() == 0) &&
                (utc.getMinutes() == 0) &&
                (utc.getSeconds() == 0) ) {
                LeapSecondNow = 1;
                LeapSecondPendingThisMonth = 0;
                LeapSecondPcOffset += -1000;
                continue;
            }
            if (utc.getSeconds() == 0) {
                LeapSecondNow = 0;
            }
            break;
        }

        var n;
        var d = document;

        // Display local time.

        n = Digit(GetYear(local), 4); if (d.Y4.src != n) d.Y4.src = n;
        n = Digit(GetYear(local), 3); if (d.Y3.src != n) d.Y3.src = n;
        n = Digit(GetYear(local), 2); if (d.Y2.src != n) d.Y2.src = n;
        n = Digit(GetYear(local), 1); if (d.Y1.src != n) d.Y1.src = n;

        n = Digit(GetMonth(local), 2); if (d.M2.src != n) d.M2.src = n;
        n = Digit(GetMonth(local), 1); if (d.M1.src != n) d.M1.src = n;

        n = Digit(GetDay(local), 2); if (d.D2.src != n) d.D2.src = n;
        n = Digit(GetDay(local), 1); if (d.D1.src != n) d.D1.src = n;
				
	      n = Digit(local.getHours(), 2); if (d.h2.src != n) d.h2.src = n;
        n = Digit(local.getHours(), 1); if (d.h1.src != n) d.h1.src = n;

        n = Digit(local.getMinutes(), 2); if (d.m2.src != n) d.m2.src = n;
        n = Digit(local.getMinutes(), 1); if (d.m1.src != n) d.m1.src = n;

        var seconds = local.getSeconds() + LeapSecondNow;
        n = Digit(seconds, 2); if (d.s2.src != n) d.s2.src = n;
        n = Digit(seconds, 1); if (d.s1.src != n) d.s1.src = n;

       // Leap second countdown clock.

        utc = new Date(now.getTime() + (now.getTimezoneOffset() * 60 * 1000));
        var leap = new Date("07/01/2001 00:00:00");
        var ms = leap.getTime() - (utc.getTime() - 1000);
        if (ms > 0) {
            var countdown = Math.floor(ms / 1000);

        }
    }

    function TimerThread () {
        if (TimerIdValid) {
            clearTimeout(TimerId);
            TimerIdValid = 0;
        }
        DisplayTime();
        TimerId = setTimeout("TimerThread()", 100);
        TimerIdValid = 1;
    }

    function InitDisplay (){

    window.document.writeln('<IMG name=Y4 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=Y3 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=Y2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=Y1 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_quaddp.jpg">')
    window.document.writeln('<IMG name=M2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=M1 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_quaddp.jpg">')
    window.document.writeln('<IMG name=D2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=D1 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('&nbsp &nbsp')
		    window.document.writeln('<BR>')

    window.document.writeln('<IMG name=h2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=h1 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG src="TN_quadcol.jpg">')
    window.document.writeln('<IMG name=m2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=m1 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_quadcol.jpg">')
    window.document.writeln('<IMG name=s2 src="menuImages/TN_quad0.jpg">')
    window.document.writeln('<IMG name=s1 src="menuImages/TN_quad0.jpg">')
	  window.document.writeln('<BR>')
	  window.document.writeln('<BR>')

     }

    function InitDisplayNixie (){

    window.document.writeln('<IMG name=Y4 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=Y3 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=Y2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=Y1 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_nixdp.jpg">')
    window.document.writeln('<IMG name=M2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=M1 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_nixdp.jpg">')
    window.document.writeln('<IMG name=D2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=D1 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('&nbsp &nbsp')
		    window.document.writeln('<BR>')

    window.document.writeln('<IMG name=h2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=h1 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_nixcol.jpg">')
    window.document.writeln('<IMG name=m2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=m1 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG src="menuImages/TN_nixcol.jpg">')
    window.document.writeln('<IMG name=s2 src="menuImages/TN_nix0.jpg">')
    window.document.writeln('<IMG name=s1 src="menuImages/TN_nix0.jpg">')
	  window.document.writeln('<BR>')
	  window.document.writeln('<BR>')

     }


}





