//--------------------------------CHRONOMETRE


//initialisation des digits de l'horloge
preload_pic("IMAGES/0.png","IMAGES/1.png","IMAGES/2.png","IMAGES/3.png","IMAGES/4.png","IMAGES/5.png","IMAGES/6.png","IMAGES/7.png","IMAGES/8.png","IMAGES/9.png");
var i;
var picfiles; 
var pictime;
//preload des images

function preload_pic(){
    picfiles=preload_pic.arguments;
    pictime=new Array();
    for (i=0; i<picfiles.length; i++) {
          pictime[i]=new Image;
          pictime[i].src=picfiles[i];}
}

//fonction qui affiche l'heure dans le chronometre
function show_time(hh, mm,ss) {

	/*	 	<img class="decGauche" src="IMAGES/0.png" />
            	<img class="decDroite" src="IMAGES/0.png" />
                <img src="IMAGES/0.png" />
               <img class="decDroite" src="IMAGES/0.png" />
                <img src="IMAGES/0.png" />
                <img src="IMAGES/0.png" />*/
			 
         if (hh<10) {phh='<img class="decGauche" src='+picfiles[0]+' ><img class="decDroite" src='+picfiles[hh]+' >';}
         if (hh>9) {
             hh=hh.toString();
             phh='<img class="decGauche" src='+picfiles[(hh.substr(0,1))]+' ><img class="decDroite" src='+picfiles[(hh.substr(1))]+' >';}

         if (mm<10) {pmm='<img  src='+picfiles[0]+' ><img class="decDroite" src='+picfiles[mm]+' >';}
         if (mm>9) {
             mm=mm.toString();
             pmm='<img  src='+picfiles[(mm.substr(0,1))]+' ><img  class="decDroite" src='+picfiles[(mm.substr(1))]+' >';}

         if (ss<10) {pss='<img  src='+picfiles[0]+' ><img  src='+picfiles[ss]+' >';}
         if (ss>9) {
             ss=ss.toString();
             pss='<img class="digit" src='+picfiles[(ss.substr(0,1))]+' ><img class="digit" src='+picfiles[(ss.substr(1))]+' >';}
		document.getElementById("decompte").innerHTML=phh+pmm+pss;
}


//--------------------------------COMPTE A REBBOUR
 //fonction d'initialisation des variables
function finDuDecompte(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;
mo=themonth;
da=theday;
hr=thehour;
min=themin;
sec=thesec
}
 
////////// CONFIGUREZ LE COMPTEUR CI-DESSOUS //////////////////
 
// 1°) Configurez la FIN DE L'EVENEMENT dans le format ANNEE, MOIS, JOUR, HEURES sur 24h (0=minuit,23=11pm), MINUTES, SECONDES
//setcountdown(2013,02,26,23,43,00)

 

 
////////// NE RIEN EDITER CI-DESSOUS //////////////////

//declaration des moi, utilisé pour formalise le date pour la COMMANDE DATE
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
  
function decompte(){
	var todayMachine=new Date();
	var today =new Date(todayMachine);
	
	today.setSeconds ( todayMachine.getSeconds() -decalageSeconde );
	var todayy=today.getYear()
	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)
	

	
	//si l'evenement est passe de plus d'un jour
	if (dday<=-1){
		if (document.layers){
	
			show_time(0,0,0)
		}
		else if (document.all||document.getElementById){
				show_time(0,0,0)
		}
		return
	
	//si l'evenement est toujours en cours
	}else{
		if (document.layers){
			show_time(dhour,dmin,dsec)
		}
		else if (document.all||document.getElementById){
			show_time(dhour,dmin,dsec)
		}
	}
	
		
	setTimeout("decompte()",1000)
}

function separerDatetime(date){
		
	
		var DateSeparator="-";
		var Sp1 = date.indexOf(DateSeparator, 0);//Index of Date Separator 1
		var Sp2 = date.indexOf(DateSeparator, parseInt(Sp1, 10) + 1);//Index of Date Separator 2
	
			if (DateSeparator === ""){
				strMonth = date.substring(4, 6 + offset);
				strDate = date.substring(6 + offset, 8 + offset);
				strYear = date.substring(0, 4);
			}
			else{
				strMonth = date.substring(Sp1 + 1, Sp2);
				strDate = date.substring(Sp2 + 1, Sp2 + 3);
				strYear = date.substring(0, Sp1);
			}
				
		var tSp1 = date.indexOf(":", 0);
		var tSp2 = date.indexOf(":", (parseInt(tSp1, 10) + 1));
		if (tSp1 > 0)
			{
	
				strHour = date.substring(tSp1, tSp1 - 2);
				strMinute = date.substring(tSp1 + 1, tSp1 + 3);
				strSecond = date.substring(tSp2 + 1, tSp2 + 3);
				

			}
			else if (date.indexOf("D*") !== -1)
			{   //DTG
				strHour = date.substring(2, 4);
				strMinute = date.substring(4, 6);
			

			}

	
		 var resultat=new Array;
		 
   			resultat["annee"]=strYear;
   			resultat["moi"]=strMonth;
   			resultat["jour"]=strDate;
   			resultat["heure"]=strHour;
   			resultat["minute"]=strMinute;
			
		return resultat;
		
		

	}
