var seconds = 0;
var the_timeout;

function maketime (n) {
	var hours, minutes,seconds, s, rem;
	hours = Math.floor(n/3600);
	if (hours < 10) {
		s = "0" + hours;
	}
	else {
		s = hours;
	}

	rem = n%3600;
	minutes = Math.floor(rem/60);

	if (minutes < 10) {
		s = s + ":0" + minutes;
	}
	else {
		s = s + ":" + minutes;
	}

	seconds = Math.floor(rem%60);
	if (seconds < 10) {
		s = s + ":0" + seconds;
	}
	else {
		s = s + ":" + seconds;
	}
	return (s);
}

function costoftime (secs) {
	//var ratemult, totcost, formatted, x, ttl, dec1, dec2;
	var ratemult = window.document.my_form.rate.value / 3600;
	var ttl = "" + (Math.round(ratemult * secs * 100)) / 100;
	var dec1 = ttl.substring(ttl.length-3, ttl.length-2);
	var dec2 = ttl.substring(ttl.length-2, ttl.length-1);
	if (dec1 != '.') { // adds trailing zeroes if necessary
		if (dec2 == '.') ttl += "0";
		else ttl += ".00";	
	}
	var formatted = "$" + ttl;
	return formatted;
}

function stopTime() {
	clearTimeout(the_timeout);
}

function doTime() {
	window.document.my_form.cost.value =  costoftime(seconds);
	window.document.my_form.time.value = maketime(seconds);
	seconds = seconds + 1;
	the_timeout = setTimeout('doTime();', 1000);
}