﻿//<![CDATA[
<!--  Clock --
// Display day-of-week and time in both Laoshan & Columbia.
// Update time every 30 seconds.
// To do:
// (1) users or browser defaults may elect to not run Javascript, and won't see
// the clock.  We might provide the initial value from the server side.
// (2) This doesn't yet handle the precise switch between CST/CDT for Columbia
// in March and November.  China does not currently use daylight time.
var timerID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(){
    stopclock()
    showtime()
}

function showtime(){
                var dow = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')
    var now = new Date()
    var offset = now.getTimezoneOffset()
    var time = now.getTime()
    var uctime = time + offset*60*1000  // Universal Time
    // Determine Columbia time from anywhere in the world
    var cotime = uctime - 6*3600*1000 // Central Standard Time = UTC - 6 hours
    var DT = 2 * offset - (new Date(2007, 0)).getTimezoneOffset() - (new Date(2007, 6)).getTimezoneOffset()
    if (DT<0) { // Central Daylight Time
			 cotime = uctime - 5*3600*1000
    }
    now.setTime(cotime)

    var day = now.getDay()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var m = " am"
    var timeValue = "" + dow[day] + ", "
    if (hours>11) {
			 m = " pm"
	 	   hours = hours - 12
    }
    if (hours==0) { hours = 12}
		timeValue  += hours
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += m
    document.clock.columbia.value = timeValue

		// Determine Laoshan time from anywhere in the world
    var lstime = now.getTime()
		lstime = uctime + 8*3600*1000   // Laoshan time = UTC + 8 hours
		now.setTime(lstime)
		day = now.getDay()
    hours = now.getHours()
    minutes = now.getMinutes()
    m = " am"
    timeValue = "" + dow[day] + ", "
    if (hours>11) {
			  m = " pm"
				hours = hours - 12
    }
    if (hours==0) { hours = 12}
		timeValue  += hours
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += m
    document.clock.laoshan.value = timeValue

    timerID = setTimeout("showtime()",30000) // Update every 30 seconds
    timerRunning = true
}
//-->
