// Anytime Anywhere Web Page Clock Generator
// Clock Script Generated at
// http://rainbow.arch.scriptmania.com/tools/clock/clock_generator.html
// Modified by Terry D. Norbraten TNorb@comcast.net 05 DEC 07

var dayNames = new Array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT');

var monthNames = new Array('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC');

var fr = 0;

var outputTime = "leadingZero(timeSource().getHours()) + ':' + leadingZero(timeSource().getMinutes()) + ':' + leadingZero(timeSource().getSeconds()) + ' GMT'";

var dayMonthYear = "dayNames[timeSource().getDay()] + ' ' + leadingZero(timeSource().getDate()) + ' ' + monthNames[timeSource().getMonth()] + ' ' + fixYear4(timeSource().getYear())";

function timeSource() {
    
    x = new Date(timeNow().getUTCFullYear(), timeNow().getUTCMonth(), 
        timeNow().getUTCDate(), timeNow().getUTCHours(), timeNow().getUTCMinutes(),
        timeNow().getUTCSeconds());
    
    //x.setTime(x.getTime() + daylightSaving());
		x.setTime(x.getTime());
    
    return x;
}

function timeNow() {
    return new Date();
}

// This function adds an hour making PDT PST, commented out above
function daylightSaving() {
    return ((timeNow().getTime() > findDay(0, 2, 3, 2).getTime()) && 
        (timeNow().getTime() < findDay(0, 10, 3, 1).getTime())) ? 3600000 : 0;
}

function findDay(d, m, h, p){
    var week = (p < 0) ? 7 * (p + 1) : 7 * (p - 1), 
    nm = (p < 0) ? m + 1 : m, 
    x = new Date (timeNow().getUTCFullYear(), nm, 1, h, 0, 0), 
    dOff = 0;
    
    if(p < 0) {
        x.setTime(x.getTime() - 86400000);
    }
    
    if(x.getDay()!= d) {
        dOff = (x.getDay() < d) ? (d - x.getDay()) : 0 - (x.getDay() - d);
        
        if(p < 0 && dOff > 0){
            week -= 7;
        }
        
        if(p > 0 && dOff < 0){
            week += 7;
        }
        
        x.setTime(x.getTime() + ((dOff + week) * 86400000));
    }
    
    return x;
}

function leadingZero(x) {
    return (x > 9) ? x : '0' + x;
}

function displayTime() {
    
    if(fr == 0) {
        fr = 1;
        document.write('<font size=2 face=Arial><b><span id="tP">' + 
            eval(outputTime) + '<\/span><\/b><\/font>');
    }
    
    document.getElementById('tP').innerHTML = eval(outputTime);
    setTimeout('displayTime()', 1000);
}

function fixYear4(x) {
    return (x < 500) ? x + 1900 : x;
}

