/*
 * Utilisation
 //var compteur = new compteRebours('prochain_tirage_compteur');
 //compteur.init(<?php echo(date('Y')); ?>, <?php echo(date('m')); ?>, <?php echo(date('d') +1); ?>, <?php echo(0); ?>, <?php echo(0); ?>, <?php echo(0); ?>);
 //compteur.load();

function compteRebours(element)
{

    // Variables
    this.yr      = 0;
    this.mo      = 0;
    this.da      = 0;
    this.hr      = 0;
    this.min     = 0;
    this.sec     = 0;
    this.element = document.getElementById(element);


    // Methodes
    this.init = init;
    this.load = load;

    function init(year, month, day, hours, minutes, seconds)
    {

        this.yr  = year;
        this.mo  = month;
        this.da  = day;
        this.hr  = hours;
        this.min = minutes;
        this.sec = seconds;
    }


    function load()
    {

        var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
        // 2Â°) Changez les deux textes ci-dessous. Le premier pour annoncer l'Ã©vÃ¨nement, le second qui s'affichera Ã  la fin du compte Ã  rebours.
        
        var message_on_occasion = 'Tirage en cours';

        var today=new Date();
        var todayy=today.getYear();
		
		if (todayy < 1000) {
			
			todayy += 1900;
		}
		
		if (navigator.userAgent.indexOf("Opera") != -1) {
	
			if (todayy < 1000) {
			
				todayy += 1900;
			}
		}
		
        var todaym		= today.getMonth();
        var todayd		= today.getDate();
        var todayh		= today.getHours();
        var todaymin	= today.getMinutes();
        var todaysec	= today.getSeconds();
        var todaystring = montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
		
        futurestring = montharray[this.mo-1]+" "+this.da+", "+this.yr+" "+this.hr+":"+this.min+":"+this.sec;
        dd	  		 = Date.parse(futurestring) - Date.parse(todaystring);
        dday  		 = Math.floor(dd/(60*60*1000*24)*1);
        dhour 		 = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
        dmin  		 = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
        dsec  		 = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
        //if on day of occasion
        if((dday<=0)&&(dhour<=0)&&(dmin<=0)&&(dsec<=1)&&(todayd==this.da)){
            if (document.layers){
                document.countdownnsmain.document.countdownnssub.document.write(message_on_occasion);
                document.countdownnsmain.document.countdownnssub.document.close();
            }
            else if ((document.all)||(document.getElementById))
            crosscount.innerHTML=message_on_occasion;
            return;
        }
        //if passed day of occasion
        else if (dday<=-1){

            this.element.innerHTML = "L'évènement est déjà  arrivé ! ";
            return;
        } else {

        	if (dmin < 10) {
           
            	dmin = '0' + dmin;
        	}
        
	        if (dsec < 10) {

    	        dsec = '0' + dsec;
        	}
			
            this.element.innerHTML = dhour + ' h ' + dmin + ' m ' + dsec + ' s';
        }
        
		//setTimeout(this.load(), 1);
        setTimeout(function(thisObj) { thisObj.load(); }, 1, this);
    }
}
*/



    // Variables
    var yr      = 0;
    var mo      = 0;
    var da      = 0;
    var hr      = 0;
    var min     = 0;
    var sec     = 0;

    function initCompteur(year, month, day, hours, minutes, seconds, element)
    {

        yr  = year;
        mo  = month;
        da  = day;
        hr  = hours;
        min = minutes;
        sec = seconds;
		
		myelement = document.getElementById(element);
    }


    function loadCompteur()
    {

        var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
        // 2Â°) Changez les deux textes ci-dessous. Le premier pour annoncer l'Ã©vÃ¨nement, le second qui s'affichera Ã  la fin du compte Ã  rebours.
        
        var message_on_occasion = 'Tirage en cours';

        var today=new Date();
        var todayy=today.getYear();
		
		if (todayy < 1000) {
			
			todayy += 1900;
		}
		
		if (navigator.userAgent.indexOf("Opera") != -1) {
	
			if (todayy < 1000) {
			
				todayy += 1900;
			}
		}
		
        var todaym		= today.getMonth();
        var todayd		= today.getDate();
        var todayh		= today.getHours();
        var todaymin	= today.getMinutes();
        var todaysec	= today.getSeconds();
        var todaystring = montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
		
        futurestring = montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+":"+sec;
        dd	  		 = Date.parse(futurestring) - Date.parse(todaystring);
        dday  		 = Math.floor(dd/(60*60*1000*24)*1);
        dhour 		 = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
        dmin  		 = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
        dsec  		 = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
        //if on day of occasion
        if((dday<=0)&&(dhour<=0)&&(dmin<=0)&&(dsec<=1)&&(todayd==da)){
            if (document.layers){
                document.countdownnsmain.document.countdownnssub.document.write(message_on_occasion);
                document.countdownnsmain.document.countdownnssub.document.close();
            }
            else if ((document.all)||(document.getElementById))
            crosscount.innerHTML=message_on_occasion;
            return;
        }
        //if passed day of occasion
        else if (dday<=-1){

            myelement.innerHTML = "L'évènement est déjà  arrivé ! ";
            return;
        } else {

        	if (dmin < 10) {
           
            	dmin = '0' + dmin;
        	}
        
	        if (dsec < 10) {

    	        dsec = '0' + dsec;
        	}
			
            myelement.innerHTML = dhour + ' h ' + dmin + ' m ' + dsec + ' s';
        }
        
		setTimeout('loadCompteur()', 1);
    }
