var starttime = Math.floor(new Date().getTime()/1000);
function iat(){
	t();
}
function t(){
  for (cn = 1; cn <= anz; cn++) {
    timer = document.getElementById("timer" + cn);
    s = timer.title - (Math.floor(new Date().getTime()/1000)-starttime);
	rs = s;
    m = 0;
    h = 0;
	d = 0;
	ausgabe = "";
	if(s < 1 && s % 5 == 0){
		if (document.getElementById('Sound').checked == true) {
			soundManager.play("mySound1");
		}
	}
	if(s==0){
		if (document.getElementById('Popup').checked == true) {
  			alert("Countdown Abgelaufen!");
		}
	}
	if (s < 0){
		s = s * -1;
	}
    if (s < 0){
      timer.innerHTML = "-";
    }else {
		if (s > 59) {
			m = Math.floor(s/60);
			s = s - m * 60;
		}
		if (m > 59) {
			h = Math.floor(m / 60);
			m = m - h * 60;
		}
		if (h > 24) {
			d = Math.floor(h / 24);
			h = h - d * 24;
		}
		if (s < 10) {
			s = "0" + s;
		}
		if (m < 10) {
			m = "0" + m;
		}
		if (h < 10) {
			h = "0" + h;
		}
		if(rs < 0){
			ausgabe = ausgabe + "<font style=color:red;>";
		}else{
			ausgabe = ausgabe + "<font style=color:green;>";
		}
		ausgabe = ausgabe + d + "Days " + h + ":" + m + ":" + s + "";
			ausgabe = ausgabe + "</font>";
		timer.innerHTML = ausgabe;
		if(cn == 1){
			output = "";
			if(rs<0){
				output = "-";
			}
			if(d > 0){
				output = output + d + "Days " + h + ":" + m + ":" + s;
			}else{
				output = output + h + ":" + m + ":" + s;
			}
			document.title = output;
		}
    }
  }
  window.setTimeout("t();", 999);
}
function setcookie(){
	Schreiben('sound',1);
	Schreiben('popup',1);
}
function Schreiben(name,wert)
{
 var a = new Date();
 a = new Date(a.getTime() +1000*60*60*24*365);
 document.cookie = name+'='+wert+'; expires='+a.toGMTString()+';';
}
function Lesen(n)
{
 a = document.cookie;
 res = '';
 while(a != '')
 {
  cookiename = a.substring(0,a.search('='));
  cookiewert = a.substring(a.search('=')+1,a.search(';'));
  if(cookiewert == '')
  {cookiewert = a.substring(a.search('=')+1,a.length);}

  if(n == cookiename){res = cookiewert;}

  i = a.search(';')+1;
  if(i == 0){i = a.length}
  a = a.substring(i,a.length);
 }
 return(res)
}
