// JavaScript Document
function NbHMS(Temps)
{
		Heures=Math.floor(Temps/3600);
		Temps=Temps-(Heures*3600);
		Minutes=Math.floor(Temps/60);
		Temps=Temps-(Minutes*60);
		Secondes=Temps;
		if(Heures<10)
		{
			Heures='0'+Heures;
		}
		if(Minutes<10)
		{
			Minutes='0'+Minutes;
		}
		if(Secondes<10)
		{
			Secondes='0'+Secondes;
		}
		return(Heures+':'+Minutes+':'+Secondes);
}

function PositionUnite(XAbsDepart,XAbsArrivee,YAbsDepart,YAbsArrivee,Vitesse,LargCarte,HeureDepart,ETA,DifferenceTemps)
{
	var Gruik= new Date()
	HeureActuelle=(Gruik.getTime()/1000)-DifferenceTemps;
	DXAbs=XAbsArrivee-XAbsDepart;
	if(XAbsArrivee>XAbsDepart)
	{
		DXRel=XAbsArrivee-XAbsDepart-LargCarte;
	}
	else
	{
		DXRel=XAbsArrivee-XAbsDepart+LargCarte;
	}
	if(Math.abs(DXAbs)<=Math.abs(DXRel))
	{
		DX=DXAbs;
	}
	else
	{
		DX=DXRel;
	}
	XActuel=XAbsDepart+(((HeureActuelle-HeureDepart)/(ETA-HeureDepart))*DX);
	if(XActuel<0)
	{
		XActuel+=LargCarte;
	}
	if(XActuel>LargCarte)
	{
		XActuel-=LargCarte;
	}
	
	DYAbs=YAbsArrivee-YAbsDepart;
	if(YAbsArrivee>YAbsDepart)
	{
		DYRel=YAbsArrivee-YAbsDepart-LargCarte;
	}
	else
	{
		DYRel=YAbsArrivee-YAbsDepart+LargCarte;
	}
	if(Math.abs(DYAbs)<=Math.abs(DYRel))
	{
		DY=DYAbs;
	}
	else
	{
		DY=DYRel;
	}
	YActuel=YAbsDepart+(((HeureActuelle-HeureDepart)/(ETA-HeureDepart))*DY);
	if(YActuel<0)
	{
		YActuel+=LargCarte;
	}
	if(YActuel>LargCarte)
	{
		YActuel-=LargCarte;
	}
	return Array(XActuel,YActuel);
}

function CalculPret(Montant, Taux, NbRemb)
{
		Gain=Math.round(parseInt(Montant)*((parseInt(Taux)*parseInt(NbRemb))/100));
		if(NbRemb==0) NbRemb=1;
		MontantRemb=Math.round((parseInt(Montant)+parseInt(Gain))/parseInt(NbRemb));
		var gruik=new Array(Gain, MontantRemb);
		return gruik;
}

function DecrementerChronos()
{
	for(Cle in Chronos)
	{
		Chronos[Cle]-=1;
		document.getElementById(Cle).firstChild.nodeValue=NbHMS(Chronos[Cle]);
		if(Chronos[Cle]<=0)
		{
			if(window.location.href.search(/\?/)>=0)
			{
				window.location.href=window.location.href+"&PasDePub=1";
			}
			else
			{
				window.location.href=window.location.href+"?PasDePub=1";
			}
		}
	}
	setTimeout("DecrementerChronos()",1000);
}

function IncrementerChronos()
{
	for(Cle in ChronosInc)
	{
		ChronosInc[Cle]+=1;
		document.getElementById(Cle).firstChild.nodeValue=NbHMS(ChronosInc[Cle]);
		if(ChronosInc[Cle]<=0)
		{
			window.location.href=window.location.href;
		}
	}
	setTimeout("IncrementerChronos()",1000);
}


function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
		var value = arr[item];
	 
		if(typeof(value) == 'object') { //If it is an array,
		 dumped_text += level_padding + "'" + item + "' ...\n";
		 dumped_text += dump(value,level+1);
		} else {
		 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
		}
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
} 

function SeparMilliers(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function SansEspace(Str)
{
  StrNewStr="";
	 for(i=0;i<=Str.length;i++)
	 {
		 StrChar=Str.substring(i,i+1);
		 if(StrChar!=" " || Str.substring(i-1,i)!=" ")
		 {
			 StrNewStr=StrNewStr+StrChar;
		 }
	 }
	 return StrNewStr;
}

function ReplacerLayers()
{
	for(var i in LayersADeplacer)
	{
		Chaine=document.getElementById(LayersADeplacer[i]).style.left;
		X=Chaine.substring(0,Chaine.length-2);
		dx=X-480;
		M=Math.max(document.body.offsetWidth,960)/2;
		Position=Math.round(M+dx,0);
		document.getElementById(LayersADeplacer[i]).style.left=Position+'px';
		document.getElementById(LayersADeplacer[i]).style.visibility='visible';
	}
}
