function StopWatch (showTime) { this.id = StopWatch.watches.length; StopWatch.watches[this.id] = this; this.showTime = typeof showTime == 'function' ? showTime : function () {}; this.reset(); } StopWatch.prototype.reset = function () { this.time = 1265723553; // Seconds since 1970/01/01 00:00:00 - get from server rather than client this.time -= 1234567890 + 345600 + 1710; // 1234567890 sec since 1970 = 13 Feb 2009, 23:31:30, + 4 days + 28.5 minutes this.components = {}; this.computeComponents(); this.showTime(this.components); } StopWatch.prototype.start = function () { this.tid = setTimeout('StopWatch.watches[' + this.id + '].run()', 200); } StopWatch.prototype.run = function () { this.tid = setTimeout('StopWatch.watches[' + this.id + '].run()', 200); this.time+= 0.2; // updated 5 times per second this.computeComponents(); this.showTime(this.components); } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } StopWatch.prototype.computeComponents = function () { var hours = Math.floor(this.time / StopWatch.secondsPerHour); var remainingTime = this.time - hours * StopWatch.secondsPerHour; var minutes = Math.floor(remainingTime / StopWatch.secondsPerMinute); var seconds = remainingTime - minutes * StopWatch.secondsPerMinute; var formattedTime = ''; var debsec = 1885.028350; formattedTime = formatCurrency( this.time * debsec ); this.components.formattedTime = formattedTime; } StopWatch.secondsPerMinute = 60; StopWatch.secondsPerHour = StopWatch.secondsPerMinute * 60; StopWatch.watches = new Array(); function showTimeFormWatch (components) { document.watch0.time.value = components.formattedTime; } var stopWatch;