var timer;
var seconds = 0;
var startButton = 0;
var minutes = 0;
var secondsTotal = 0;

function starter(whichTimer,timeLimit) {
	if (startButton == 1) {
		i = whichTimer;
		limit = timeLimit;
		theTimer(i,limit);		
	}
}
function prepareSubmit(){
	document.getElementById('typeAreaHidden').value = document.getElementById('typeArea').value;
	document.getElementById('typeArea').value = '';
	document.Exercise.timespent1.value = '';
	seconds = 0;
	startButton = 0;
	minutes = 0;
	secondsTotal = 0;
	stopTimer();
	return true;
}

function theTimer(whichTimer,timeLimit) {
	i = whichTimer;
	limit = timeLimit;
	timer = setTimeout('theTimer(i,limit)',1000);
	secondsTotal++;
	seconds = (seconds + 1)%60;
//	document.Exercise.test1.value = secondsTotal;
	if (secondsTotal==timeLimit) {
		prepareSubmit();
		document.Exercise.submit();
	} else {
		minutes = Math.floor(secondsTotal/60);
	}
	theTime = minutes + ":" + seconds;
	switch(whichTimer) {
		case "t1":
			document.Exercise.timespent1.value = theTime;
			document.Exercise['time1.1'].value = secondsTotal;
			break;
		default:
			document.Exercise.timespent1.value = theTime; 
			document.Exercise['time1.1'].value = secondsTotal;
	}
	
}
function stopTimer () {
	startButton = 0;
	minutes = 0;
	seconds = 0;
	clearTimeout(timer);
}


