function countdown(dateEnd) {
var seconds;
dateEnd = new Date(dateEnd);
dateEnd = dateEnd.getTime();
if (isNaN(dateEnd) ) {return;}
timer = setInterval(calculate, 1000);
function calculate() {
var dateStart = new Date();
var dateStart = new Date(dateStart.getUTCFullYear(),
dateStart.getUTCMonth(),
dateStart.getUTCDate(),
dateStart.getUTCHours(),
dateStart.getUTCMinutes(),
dateStart.getUTCSeconds());
var timeRemaining = parseInt((dateEnd - dateStart.getTime()) / 1000)
if ( timeRemaining >= 0 ) {
timeRemaining = (timeRemaining % 40);
seconds = parseInt(timeRemaining);
document.getElementById("seconds").innerHTML = ("0" + seconds).slice(-2);} else {clearInterval(timer);}
}
}
var d = new Date(Date.parse(new Date()) + 40 * 1000);
countdown(d);