//
// Usage Example:
//
//<body onLoad="startCountdown('June 4, 2004 13:0:00','Festival hat begonnen !',
//  'June 7, 2004 00:00:00','Wir sehen uns in 2005 !')">
//
// <span id="countdown">00:00:00</span> 
//
//
//
        var eventTime;
        var eventTime2;
        var textAfter;
        var textAfter2;
        var iTimerID;
        var startingServerTime;
        var startingClientTime;

        // This function updates countdown
        function updateCountdown()
        {
	  var countdownText;
	  curClientTime = (new Date()).getTime();
	  runningTime = curClientTime - startingClientTime;

          // calculate current server time
	  curServerTime = startingServerTime + runningTime;

	  if (curServerTime > eventTime2)
	  {
	    countdownText = textAfter2;
	    //used to stop the script - the value won't change anymore
	    clearInterval(iTimerID);
	  }
	  else
	  {
	    if (curServerTime > eventTime)
	    {
  	      countdownText = textAfter;
	    }
	    else
	    {
	      timeLeft = (eventTime - curServerTime);
	      secondsLeft = Math.round(timeLeft / 1000);

	      days = 0;
	      hours = 0;
	      minutes = 0;
	      seconds = 0;

	      secPerMin = 60;
	      secPerHour = (60 * 60);
	      secPerDay = (60 * 60 * 24);
	      days = Math.floor(secondsLeft / secPerDay);

	      tmpSeconds = secondsLeft - (days * secPerDay);
	      hours = Math.floor(tmpSeconds / secPerHour);

	      tmpSeconds = tmpSeconds - (hours * secPerHour);
	      minutes = Math.floor(tmpSeconds / secPerMin);

	      seconds = tmpSeconds - (minutes * secPerMin);

	      if (hours < 10) hours = "0" + hours;
	      if (minutes < 10) minutes = "0" + minutes;
	      if (seconds < 10) seconds = "0" + seconds;

	      dayText = 'Tage';
	      if (days == 1) dayText = 'Tag';
	      hourText = 'Std';
	      minText = 'Min';
	      secText = 'Sek';
	      //countdownText = days + " " + dayText + " " + 
	      //hours + ":" + minutes + ":" + seconds;
	      countdownText = days + " " + dayText + " " + 
		hours + " " + hourText + " " + minutes + " " + minText + " " + seconds + " " + secText;
		//+ " - " + Math.round(runningTime / 1000);
	    }
	  }

	  document.getElementById("countdown").firstChild.data = countdownText;
	    
	  //Math.floor(secondsLeft)
        }

        // This function starts the countdown
        // before the time specified by datetimeStr, the countdown will be displayed
        // after the time specified by datetime2Str, the textAfterTime2 will be displayed
        // between those 2 times, the textAfterTime will be displayed
        //
        // (the script assumes that datetime2Str is later than datetimeStr)
        // currentTime - used to get the time from server, this time will be used for calculating
        //   the countdown

        function startCountdown(currentTime,datetimeStr,textAfterTime,datetime2Str,textAfterTime2)
        {
	  started = false;
	  startingServerTime = (new Date(currentTime)).getTime();
	  startingClientTime = (new Date()).getTime();
	  runningTime = 0;

	  textAfter = textAfterTime;
	  textAfter2 = textAfterTime2;

	  eventTime = (new Date(datetimeStr)).getTime();
	  eventTime2 = (new Date(datetime2Str)).getTime();

	  if (!started)
	  {
            //display the right value at the beginning
	    updateCountdown();
	    started = true;
	  }
	  iTimerID = window.setInterval("updateCountdown()", 1000);
        }
