
/*function decompte()
{
	var aujourdhui = new Date();
	time_tmp = parseInt(aujourdhui.getTime() / 1000, 10);
	restant = time - time_tmp;
	
	jour = parseInt((restant / (60 * 60 * 24)), 10);
	heure = parseInt((restant / (60 * 60) - jour * 24), 10);
	minute = parseInt((restant / 60 - jour * 24 * 60 - heure * 60), 10);
	seconde = parseInt((restant - jour * 24 * 60 * 60 - heure * 60 * 60 - minute * 60), 10);
	
	document.getElementById('jours').innerHTML  = jour;
	document.getElementById('heures').innerHTML  = heure;
	document.getElementById('minutes').innerHTML  = minute;
	document.getElementById('secondes').innerHTML = seconde;
	
	if (time_tmp < time)
		setTimeout('decompte()', 1000);
	else
	{
		// Temps fini, on fait ce qu'on veux
		document.getElementById('jours').innerHTML  = 0;
		document.getElementById('heures').innerHTML  = 0;
		document.getElementById('minutes').innerHTML  = 0;
		document.getElementById('secondes').innerHTML = 0;
		//url="http://127.0.0.1/freeglobe/index.php?id=<? echo $id;?>"  // Changer ici l'url
        //Go(url)
	}
}
setTimeout('decompte()', 500);*/

/*function Go(url) {
window.status="Go !"
setTimeout("window.location=url", 500)
}*/

function screentimer(fid, madate)
{
    if (document.getElementById)
    {
	var date1 = new Date(); // date et heure du jours à l'instant T.
	var time = (madate-date1) / 1000; // Temps donné en millièmes de seconde
	var txtHorloge = "<div id=\"horlogeDiv"+fid+"\">Un erreur dans la fonction</div>";
	document.write(txtHorloge);
	updatetimer(fid, time);	
    }
}
function updatetimer(fid, sec)
{
    var n = 24 * 3600; //nombre de secondes dans un jour
    if(sec>0)
    {
	j = Math.floor (sec / n);
	h = Math.floor ((sec - (j * n)) / 3600);
	mn = Math.floor ((sec - ((j * n + h * 3600))) / 60);
	seconde = Math.floor (sec - ((j * n + h * 3600 + mn * 60)));
	h = showFilled(h),
	mn = showFilled(mn),
	seconde = showFilled(seconde),
	timer = " <center><td><B style=\"font:100% Arial Black; \">"+ j +" Jrs</B></td> <td><B style=\"font:100% Arial; \">"+ h +":</B></td><td><B style=\"font:100% Arial; \">"+ mn +":</B></td><td><B style=\"font:100% Arial; \">"+ seconde +"</B></td> </center>";
	document.getElementById("horlogeDiv"+fid+"").innerHTML = ""+timer+"";
    }
    else
    {
	document.getElementById("horlogeDiv"+fid+"").innerHTML = " <center><font color=\"red\">Terminé</font> </center>";
    url="http://troquealsace.fr/index.php?id="+fid+""  // Changer ici l'url
        Go(url)
    }
    sec = calcultimer(sec);
    setTimeout ("updatetimer("+fid+", "+sec+");", 1000);
	
}
function calcultimer(sec)
{
	sec--;
	return sec;
}
function showFilled(Value) 
{
	return (Value > 9) ? "" + Value : "0" + Value;
}

function Go(url) {
window.status="Go !"
setTimeout("window.location=url", 500)
}
