/* JavaScript Clock written by Kevin Harrington ____________________________________________ Pushes the current server time to the client, then figures out correction factor between server and client clocks, then keeps the on-screen clock current using the client clock +- the correction factor. Clock output goes to spans on the screen named 'clock_date', 'clock_hours', 'clock_colon', and 'clock_mins' */ var timeAdjust; var weekdays = new Array(7); var months = new Array(12); function startupClock() { localTime = new Date(); serverTime = new Date("May 09, 2008 09:43:26"); timeAdjust = localTime.getTime() - serverTime.getTime(); weekdays[0] = 'Sun'; weekdays[1] = 'Mon'; weekdays[2] = 'Tue'; weekdays[3] = 'Wed'; weekdays[4] = 'Thu'; weekdays[5] = 'Fri'; weekdays[6] = 'Sat'; months[0] = 'Jan'; months[1] = 'Feb'; months[2] = 'Mar'; months[3] = 'Apr'; months[4] = 'May'; months[5] = 'Jun'; months[6] = 'Jul'; months[7] = 'Aug'; months[8] = 'Sep'; months[9] = 'Oct'; months[10] = 'Nov'; months[11] = 'Dec'; now = new Date(); now.setTime(now.getTime() - timeAdjust); updateTime(now); setTimeout("tickTock()",1000); } function tickTock() { now = new Date(); now.setTime(now.getTime() - timeAdjust); if(now.getSeconds() % 2 == 0) { document.getElementById('clock_colon').className='clock'; } else { document.getElementById('clock_colon').className='clockTrans'; } if(now.getSeconds() == '00') updateTime(now); setTimeout("tickTock()",1000); } function updateTime(now) { var time = ''; document.getElementById('clock_date').childNodes[0].nodeValue = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate(); if(now.getHours() == 0) { time = time + '12'; } else if(now.getHours() > 12) { time = time + parseInt(now.getHours() - 12); } else { time = time + now.getHours(); } document.getElementById('clock_hours').childNodes[0].nodeValue=time; time = ''; if(now.getMinutes() < 10) time = time + '0'; time = time + now.getMinutes(); if(now.getHours() < 12) { time = time + ' am'; } else { time = time + ' pm'; } document.getElementById('clock_mins').childNodes[0].nodeValue=time; } /* end of JavaScript Clock */