/* 
	JavaScript Timer
	Written by Jerry Aman, Optima System, June 1, 1996.
	Part of the PageSpinner distribution.
 
	Portions based upon the JavaScript setTimeout example at:
	http://home.netscape.com/eng/mozilla/Gold/handbook/javascript/

   We will not be held responsible for any unwanted 
	effects due to the usage of this script or any derivative.  
	No warrantees for usability for any specific application are 
	given or implied.

   You are free to use and modify this script,
	if the credits above are given in the source code
*/

var    timerID = null
var timerRunning = false
var startDate
var startSecs

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

function startclock()
{
	startDate = new Date()
	startSecs = (startDate.getHours()*60*60) + (startDate.getMinutes()*60) 
	                   + startDate.getSeconds()

   stopclock()
	showtime()
}


/*  -------------------------------------------------
	showtime()
	Puts the amount of time that has passed since 
	loading the page into the field named timerField in 
	the form named timeForm 
	-------------------------------------------------  */

function showtime()
{
	// this doesn't work correctly at midnight...

   var now = new Date()
	var nowSecs = (now.getHours()*60*60) + (now.getMinutes()*60) + now.getSeconds()
	var elapsedSecs = nowSecs - startSecs;

   var hours = Math.floor( elapsedSecs / 3600 )
	elapsedSecs = elapsedSecs - (hours*3600)

   var minutes =   Math.floor( elapsedSecs / 60 )
	elapsedSecs = elapsedSecs - (minutes*60)

   var seconds = elapsedSecs

   var timeValue = "" + hours
	timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue  += ((seconds < 10) ? ":0" : ":") + seconds

       // Update display
	document.timerForm.timerField.value = timeValue 
	timerID = setTimeout("showtime()",1000)
	timerRunning = true
}
