﻿var _currentSeconds=5400;
var _AnzElm=0;
var _timerID=0;
var sw_currentSeconds=0;
var sw_AnzElm=0;

function initTimer() {
	_AnzElm = document.getElementById("Anzeige");
	sw_AnzElm = document.getElementById("Stopwatch");
	StartTimer();
}


function StartTimer() {
	if (_timerID == 0) {
		_timerID = window.setInterval("Tick()", 1000);
	}
}

function stopTimer() {
	if (_timerID > 0) {
		window.clearInterval(_timerID);
		_timerID = 0;
	}
}

function Tick() {
	if (_currentSeconds <= 0) {
		_currentSeconds=5400;
	}
	if (sw_currentSeconds >= 5400) {
		sw_currentSeconds = 0;
	}
	
	SetDisplayTextCountdown(_currentSeconds - 1);
	SetDisplayTextWatch(sw_currentSeconds + 1);
}

function SetDisplayTextCountdown(seconds) {
	_currentSeconds = seconds;
	var minutes=parseInt(seconds/60);
	seconds = (seconds%60);
	var hours=parseInt(minutes/60);
	minutes = (minutes%60);
	var strText = AddNull(hours) + ":" + AddNull(minutes) + ":" + AddNull(seconds);
	_AnzElm.innerHTML = strText;
}

function SetDisplayTextWatch(seconds) {
	sw_currentSeconds = seconds;
	var minutes=parseInt(seconds/60);
	seconds = (seconds%60);
	var hours=parseInt(minutes/60);
	minutes = (minutes%60);
	var strText = AddNull(hours) + ":" + AddNull(minutes) + ":" + AddNull(seconds);
	sw_AnzElm.innerHTML = strText;
}

function AddNull(num) {
	return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}