//http://www.kostenlose-javascripts.de/javascripts/zaehler/countdown-bis-silvester.html

function toSt2(n) {
	s = "";
	if (n < 10)
		s += "0";
	return (s + n).toString();
}
function toSt3(n) {
	s = "";
	if (n < 10)
		s += "00";
	else if (n < 100)
		s += "0";
	return (s + n).toString();
}
function matchCountdown(matchId, endDate) {
	var d = new Date();
	var end = new Date(endDate);
	count = Math.floor(end.getTime() - d.getTime());
	if (count > 0) {
		// miliseconds = toSt3(count%1000);
		count = Math.floor(count / 1000);
		seconds = toSt2(count % 60);
		count = Math.floor(count / 60);
		minutes = toSt2(count % 60);
		count = Math.floor(count / 60);
		hours = toSt2(count % 24);
		count = Math.floor(count / 24);
		days = toSt2(count);

		document.getElementById('cntMatchDay_' + matchId).innerHTML = days + ':';
		document.getElementById('cntMatchHour_' + matchId).innerHTML = hours + ':';
		document.getElementById('cntMatchMin_' + matchId).innerHTML = minutes + ':';
		document.getElementById('cntMatchSec_' + matchId).innerHTML = seconds;
		setTimeout("matchCountdown('" + matchId + "','" + endDate + "')", 2000);
	}
}
