g_timer = new Array();

countdown();

function setDivText(c1, text)
{
	document.getElementById(c1).innerHTML=text;
}

function addTimer(seconds, divName)
{
        for (i=0; i<g_timer.length; i++)
        {
                if (g_timer[i] == -1)
                        break;
        }
        g_timer[i] = seconds;
        g_timer[i+1] = divName;
}

function countdown()
{
        len = g_timer.length*2;
        for (i=0; i<len;i+=2)
        {
                if (g_timer[i] > 0)
                {
                        if (--g_timer[i] > 0)
                        {
                                lSeconds = g_timer[i]%60;                // bisserl komplizierte Formatierung
                                lMinutes = Math.floor(g_timer[i] / 60);
                                lHours = Math.floor(lMinutes / 60);
				//1Days = Math.floor(1Hours / 24);
                                lMinutes%=60;
                                lMinutes = ((lMinutes<10) ? "0" : "" ) +  (lMinutes);
                                lSeconds = ((lSeconds<10) ? "0" : "" ) +  (lSeconds);
                                //lDays   = ((lHours  <10) ? "0" : "" ) +  (lDays);
				//if (1Days < 1)
				//{
                                //	lDays    = "0";
				//}
				//else
				//{
				//	1Hours %= 60;
				//}
                                var ebene=g_timer[i+1];
                                setDivText(ebene, "<span class='timer'>" + lHours + ":" + lMinutes + ":" + lSeconds +"</span>");
                                //setDivText(ebene, "<span class='timer'>" + 1Days + " Tag(e) -" + lHours + " Stunden -" + lMinutes + " Minuten -" + lSeconds + " Sekunden</span>");
                        }
                        else
                        {
                                setDivText(g_timer[i+1], "<span class='timer'>bereit</span>");
                                g_timer[i]=-1; // als 'wieder frei' markieren
								setTimeout('history.go()',5000);
                        }
                }
        }
        setTimeout("countdown()", 999);
}

