
var timerID = null; 
var timerRunning = false; 
 
    // Start the clock 
 
function startClock() { 
    stopClock(); 
    showTime(); 
} 
 
 
function stopClock() { 
    if ( timerRunning ) { 
        clearTimeout( timerID ); 
    } 
    timerRunning = false; 
} 
 
 
function showTime() { 
 
    var curTime  = new Date(); 
    var minutes  = curTime.getMinutes(); 
    var seconds  = curTime.getSeconds(); 
    var hours    = ( curTime.getHours() ); 
    if ( hours > 12 ) { 
        hours = ( hours - 12 ); 
    } 
 
    var timeValue = ""; 
    timeValue    += (( hours <  10 ) ? "0" : "" ) + hours; 
    timeValue    += (( minutes <  10 ) ? ":0" : ":" ) + minutes; 
    timeValue    += (( seconds <  10 ) ? ":0" : ":" ) + seconds; 
    timeValue    += ( hours >= 12 ) ? " PM" : " AM"; 
 
    if ( document.all ) { 
 
            // print into the form field 
        if( document.clock.timeForm != null ) { 
            document.clock.timeForm.value = timeValue; 
        } 
 
            // change span value 
        if( document.getElementById( "timeSpan" ) != null ) { 
            timeSpan.innerText = timeValue; 
        } 
    } 
 
    document.status = timeValue

    timerID      = setTimeout( "showTime()", 1000 ); 
    timerRunning = true; 
} 

