
// from: http://simonwillison.net/2004/May/26/addLoadEvent/
// authors: Peter-Paul Koch, Billy Pan
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
	window.onload = func;
    }
    else {
	window.onload = function() {
	    if (oldonload) {
                oldonload();
	    }
	    func();
	}
    }
}

var timerID = null;
var timerRunning = false;

function stopclock (){
    if(timerRunning)
	clearTimeout(timerID);
    timerRunning = false;
}

function returnObjById( id )
{
    var returnVar;
    if (document.getElementById)
	returnVar = document.getElementById(id);
    else if (document.all)
	returnVar = document.all[id];
    else if (document.layers)
	returnVar = document.layers[id];
    return returnVar;
}

function showtime () {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var timeValue = "" + ((hours >12) ? hours -12 :hours);
    if (timeValue == "0") timeValue = 12;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    timeValue += (hours >= 12) ? " P.M." : " A.M.";
    tobj =  returnObjById("timetxt" );
    if (tobj)
	tobj.innerHTML = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;
}

function startclock() {
    stopclock();
    //timerID = setTimeout("showtime()",1000);
    //timerRunning = true;
    showtime();
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
    /* IN - num:            the number to be formatted
       decimalNum:     the number of decimals after the digit
       bolLeadingZero: true / false to use leading zero
       bolParens:      true / false to use parenthesis for - num

       RETVAL - formatted number
    */
{
    var tmpNum = num;

    // Return the right number of decimal places
    tmpNum *= Math.pow(10,decimalNum);
    tmpNum = Math.floor(tmpNum);
    tmpNum /= Math.pow(10,decimalNum);

    var tmpStr = new String(tmpNum);

    // See if we need to hack off a leading zero or not
    if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
	if (num > 0)
	    tmpStr = tmpStr.substring(1,tmpStr.length);
	else
	    // Take out the minus sign out (start at 2)
	    tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


    // See if we need to put parenthesis around the number
    if (bolParens && num < 0)
	tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";


    return tmpStr;
}

function figure_clock_error() {
    tdiff = (dateVarS * 1000 - dateVarL.getTime()) / 1000;
    if (tdiff > 0)
	thedir = "slow";
    else  {
	thedir = "fast";
	tdiff = -1 * tdiff;
    }
    tdrem = tdiff % 60;
    tdmin = (tdiff - tdrem) / 60;
    tdsec = FormatNumber(tdiff - (tdmin * 60),3,true,false);
    clock_err = "";
    if ( tdmin > 0)
	clock_err = clock_err +  tdmin  + " minutes ";
    clock_err = clock_err + tdsec + " seconds " + thedir;
    ceobj = returnObjById("clockerr");
    ceobj.innerHTML = clock_err;
}

function fillin() {
    if (document.all)
	height = document.body.offsetHeight, width = document.body.offsetWidth;
    else if (document.layers)
	height = window.innerHeight, width = window.innerWidth;
    else
	height = window.innerHeight, width = window.innerWidth;
    jsobj = returnObjById("jsenable");
    jsobj.innerHTML = "Yes";
    sresobj = returnObjById("sres");
    sresobj.innerHTML = screen.width + "x" + screen.height;
    wresobj = returnObjById("wres");
    wresobj.innerHTML = width + "x" + height;
    osobj = returnObjById("opsys");
    osobj.innerHTML = navigator.platform;
    if (navigator.javaEnabled()) {
	javaenableobj = returnObjById("javaenable");
	javaenableobj.innnerHTML = "Yes";
    }
    sdobj = returnObjById("sd");
    sdobj.innerHTML = screen.colorDepth;
    figure_clock_error();
}
