
//**************************************************************************
// Note that the clock on the paris-brest-paris clock is has two problems -
// a) It gets the start date wrong! (it uses August 22), and
// b) It doesn't account for the local timezone;
//**************************************************************************

// These functions copied and corrected from the paris-brest-paris website.

function disp_delai(){
    // Time until Sunday, August 21, 2011 at 5pm (80hr start time)
    document.getElementById('countdown').innerHTML=delai (2011,8,21,17,0);
    //setTimeout("disp_delai()",1000);
    setTimeout("disp_delai()",15000);
}
	
function utc_adjust(localtime, utc_offset_hrs) {
    return localtime + (utc_offset_hrs * 60 * 60 * 1000);
}

function delai(annee,mois,jour,heure,min) {
    var date_fin=new Date(annee,mois-1,jour,heure,min)
    var date_jour=new Date();

    // Finish time specified in CEST, convert to UST;
    var time_end=utc_adjust(date_fin.getTime(), -2) 

    // Convert browser local time to UST;
    var time_start=utc_adjust(date_jour.getTime(), date_jour.getTimezoneOffset()/60)

    var tps=(time_end-time_start)/1000;
    if (tps < 0) {
	tps = -tps;
	if (tps < 96 * 3600) {
            return "PBP 2011 in progress!";
	} else {
	    return "PBP 2011 is finished!";
   	}
    }

    var w=Math.floor(tps/3600/24/7);
    tps=tps % (3600*24*7);
    var j=Math.floor(tps/3600/24);    
    tps=tps % (3600*24);
    var h=Math.floor(tps / 3600);	
    tps=tps % 3600;
    var m=Math.floor(tps/60);
    tps=tps % 60
    var s=Math.floor(tps);

    // var txt="<strong>"+w+"</strong>w <strong>"+j+"</strong>d <strong>"+h+"</strong>h <strong>"+m+"</strong>m <strong>"+s+"</strong>s";
    var txt="<strong>"+w+"</strong>w <strong>"+j+"</strong>d <strong>"+h+"</strong>h <strong>"+m+"</strong>m <strong>";
    // var txt="<strong>"+w+"</strong>w <strong>"+j+"</strong>d <strong>"+h+":"+m+"</strong>";
    return txt;
}

