// util.js
/* <SCRIPT language="Javascript 1.2"> */
// Divers scripts utiles
// Prefixe : _ (au moins pour pour les fonctions d'interface)
// Auteur : Judith Ruck ruck@free.fr
/*************************************/


//***********************
// FONCTIONS DE DEBUG
//***********************

// Trace des messages dans une fenetre console par document
//*******************************************************
// appeler la page avec comme argument : ?trace
var wDebug = null;
// Trace pour le debug
function _console(p_message,p_focus)
{
	if (wDebug != null && wDebug.location !=null)
	{
		wDebug.document.write(p_message+"<BR>");
		if (p_focus == true) wDebug.focus();
	}
	/*else
		alert("ERREUR _console("+p_message+") : console de debug non ouverte");
	*/
}

function _closeDocConsole()
{
	if (wDebug!=null)
	{	
		wDebug.document.write("</BODY>");
		wDebug.document.close();
	}
}

function _openConsole()
{
	//alert("DEBUG _openConsole()");
	var nomConsole = document.location.href;
	var index=nomConsole.lastIndexOf("/");
	if (index==-1) index=nomConsole.lastIndexOf("\\");
	nomConsole = nomConsole.substring(index+1);
	nomConsole = nomConsole.substring(0,nomConsole.indexOf('.'))+"_DEBUG";
	
	//alert("DEBUG _openConsole() : nomConsole = "+nomConsole);

	//
	if (wDebug==null)
	{
		// ouvre une fenetre sans barre d'etat
		//alert("DEBUG _openConsole() : ouverture...");
		
		wDebug=open('',nomConsole,'resizable,scrollbars,WIDTH=400,HEIGHT=500');
		wDebug.document.write("<TITLE>"+nomConsole+"</TITLE><BODY>");
	}
	else
	{
		alert("ERREUR _openConsole() : deja ouvert");
	}
}

// FONCTIONS DE TRACE APPELEES DEPUIS LES FICHIERS A DEBUGGER
// 1 :  _openTrace : a appeler juste apres BODY
function _openTrace()
{
	//alert("DEBUG _openTrace()");
	_openConsole();
}
// 2 : _closeTrace()
function _closeTrace()
{
	_closeDocConsole();
}
// 3 : _trace(p_msg) : pour tracer un message
function _trace(p_msg)
{
	//alert("DEBUG "+p_msg);
	if (TRACE==true) _console(p_msg,false);
}

var TRACE=false;
if (location.search == "?trace") {alert("Execution avec trace");TRACE=true; _openTrace();}

/***********************************************************************************************************************/
/***********************************************************************************************************************/
/***********************************************   FIN FONCTIONS DE DEBUG   ********************************************/
/***********************************************************************************************************************/
/***********************************************************************************************************************/


function _convertFrToEuro(p_prixFr)
{
	var val=Math.round( (p_prixFr/6.55957)*100 )/100;
	return (val);
}

function _convertEuroToFr(p_prixEu)
{
	var val=Math.round( (p_prixEu*6.55957)*100 )/100;
	return (val);
}


//**************************************************************************************
// réécriture de la fonction split (pb selon la position du separateur, et bug sous NN6
function _split(p_input, p_sep)
{
	var itemArray = new Array();
	var offset = 0;
	var i = 0;
	//_trace(" _split : itemArray.length à la creation = "+itemArray.length);
	if (p_sep==null) {alert("ERROR  _split(p_input, p_sep) : p_sep=null"); return itemArray;}
	if (p_input == null) {alert("ERROR  _split(p_input, p_sep) : p_input=null"); return itemArray;}
	var input = p_input;
	while (offset!= -1 && input.length>0)
	{
		offset=input.indexOf(p_sep);	//_trace(" _split : offset="+offset);
		if (offset == 0 ) {input = input.substring(1,input.length); continue;}
		if (offset!= -1)
		{
			itemArray[i] = input.substring(0, offset);
			input = input.substring(offset+1, input.length);
		}
		else itemArray[i] = input; // et on sort
		
		//_trace(" _split : itemArray["+(i)+"] = "+itemArray[i]);
		i++;
	}
	//_trace(" _split : itemArray.length="+itemArray.length);
	return itemArray;
}

//****************************************************************************
// recuperation du nom de fichier à partir de l'URL courante
// ex : pour une url de type http://www.machin.com/rep1/rep2/rep3/nom_fic.htm
// renvoie nom_fic.htm
function _getNomFichierCourant()
{
	var url = document.location.href;
	var path = _split(url,"/");
	var pos=(path[path.length-1]).indexOf("#");
	if (pos!=-1) return (path[path.length-1]).substring(0,pos);
	else	return(path[path.length-1]);
}

//*************************************************************************************
// determine si p_item est compris dans la chaine p_string, entre les separateurs p_sep
function _isInString(p_string, p_item, p_sep)
// p_string : chaine à explorer
// p_item : chaine recherchee
// p_sep : caractere separateur d'items dans p_string
// retourne l'index si trouvé, -1 si absent
{
	_trace(" >>> _isInString(p_string="+p_string+" p_item="+p_item+" p_sep="+p_sep+")");
	var items = _split(p_string,p_sep);
	_trace(" _isInString: apres _split : items.length="+items.length);
	for(var i=0; i<items.length; i++)
	{
		_trace(" _isInString items["+i+"]="+items[i]); 
		if (items[i] == p_item) return i;
	}
	return (-1);
}

//*************************************************************************************
// CODE POUR L'AFFICHAGE D'UNE INFOBULLE 
// adapté de DHTMLCentral.com, Thomas Brattli/Michael van Ouwerkerk
//*************************************************************************************
// Detection du navigateur
function _bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=this.agent.indexOf("Opera 5")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
}
_bwcheck.prototype.determine= function(){
	_trace("Browser version="+this.ver+"<BR>Browser agent="+this.agent+"<BR>Browser DOM="+this.dom);
	var nav=this.opera5 ? "opera5" : this.ie5 ? "ie5" : this.ie6 ? "ie6" : this.ie4 ? "ie4" : this.ns6 ? "ns6" : this.ns4 ? "ns4" : "inconnu";
	alert("votre navigateur est : "+nav);
	return nav;
}

var BW=new _bwcheck();
//BW.determine();

// variables definissant les parametres par defaut des claques. Les redefinir a la fin du HEAD du document si besoin.
POS_X= "X_DROITE";          // How from the actual mouse X should the description box appear? X_DROITE/X_GAUCHE/X_CENTRE_PAGE
POS_Y= "Y_DESSOUS";          // How from the actual mouse Y should the description box appear? Y_DESSOUS/Y_DESSUS/Y_CENTRE_PAGE											
USE_FADING= 0;        // 1 for a fading effect in windows explorer 5+ and all platforms ns6, 0 for no fading effect.
ANIMATION= 0;        // 1 if you want animation, 0 for no animation.
DETECTIONTYPE= 0;    // 1 for 'smooth' window size detection, 0 for 'flip' window size detection.
DELAY= 10;          // The time before showing the popup, in milliseconds.
	
// A unit of measure that will be added when setting the position of a layer.
var PX = BW.ns4||window.opera?"":"px";
	
if(document.layers)
{ //NS4 resize fix.
   SCR_X= innerWidth;
	 SCR_Y= innerHeight;
   onresize= function()
	 					{if(SCR_X!= innerWidth || SCR_X!= innerHeight){history.go(0)}
						};
}

// object constructor...
function makeTooltip(obj,pos_x, pos_y){								
   	this.elm= document.getElementById? document.getElementById(obj):BW.ie4?document.all[obj]:BW.ns4?document.layers[obj]:0;
   	this.css= BW.ns4?this.elm:this.elm.style;
   	this.wref= BW.ns4?this.elm.document:this.elm;
		this.obj= obj+'makeTooltip'; eval(this.obj+'=this');
		this.w= BW.ns4? this.elm.clip.width: this.elm.offsetWidth;
		this.h= BW.ns4? this.elm.clip.height: this.elm.offsetHeight;
		this.pos_x = pos_x;
		this.pos_y = pos_y;
};
makeTooltip.prototype.measureIt= function(){
	this.w= BW.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= BW.ns4? this.elm.clip.height: this.elm.offsetHeight;
}
makeTooltip.prototype.writeIt= function(text){
	if (BW.ns4) {this.wref.write(text); this.wref.close()}
	else this.wref.innerHTML= text;
}

// Mousemove detection
var MOUSE_X=0,MOUSE_Y=0,SET_X=0,SET_Y=0;

function getMousemove(e){
	MOUSE_X= (BW.ns4||BW.ns6)? e.pageX: BW.ie&&BW.win&&!BW.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
	MOUSE_Y= (BW.ns4||BW.ns6)? e.pageY: BW.ie&&BW.win&&!BW.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
	if (IS_LOADED && HOVERING && ANIMATION) placeIt();
}

function placeIt()
{
	var from_x, from_y;
	if (TOOLTIP.pos_x != "X_CENTRE_PAGE")
	{
		from_x = (TOOLTIP.pos_x == "X_DROITE") ? -1 : 0-(TOOLTIP.w);
		if (DETECTIONTYPE==1) SET_X= MOUSE_X+from_x+TOOLTIP.w > SCREEN_W_SCROLLED ? SCREEN_W_SCROLLED-TOOLTIP.w: MOUSE_X+from_x;
		if (DETECTIONTYPE==0) SET_X= MOUSE_X+from_x+TOOLTIP.w > SCREEN_W_SCROLLED ? MOUSE_X-from_x-TOOLTIP.w: MOUSE_X+from_x;
		if (SET_X<0) SET_X= 0;
	}
	else
	{
		SET_X = (BW.ie?document.body.scrollLeft:pageXOffset)+(SCREEN_W/2)-(TOOLTIP.w/2);
	}
	if (TOOLTIP.pos_y != "Y_CENTRE_PAGE")
	{
		from_y = (TOOLTIP.pos_y == "Y_DESSOUS") ?  21 : -(TOOLTIP.h+5);
		if (DETECTIONTYPE==1) SET_Y= MOUSE_Y+from_y+TOOLTIP.h > SCREEN_H_SCROLLED ? SCREEN_H_SCROLLED-TOOLTIP.h: MOUSE_Y+from_y;
		if (DETECTIONTYPE==0) SET_Y= MOUSE_Y+from_y+TOOLTIP.h > SCREEN_H_SCROLLED ? MOUSE_Y-from_y-TOOLTIP.h: MOUSE_Y+from_y;
		if (SET_Y<0) SET_Y= 0;
	}
	else
	{
		SET_Y = (BW.ie?document.body.scrollTop:pageYOffset)+(SCREEN_H/2)-(TOOLTIP.h/2);
	}
	TOOLTIP.css.left= SET_X+PX;
	TOOLTIP.css.top= SET_Y+PX;
}

// Main popUp function.
var HOVERING=false, SCREEN_W_SCROLLED=0, SCREEN_H_SCROLLED=0;
makeTooltip.prototype.showTimer= null;
function popUp(){
	if(IS_LOADED){	
		SCREEN_W_SCROLLED= SCREEN_W + (BW.ie?document.body.scrollLeft:pageXOffset);
		SCREEN_H_SCROLLED= SCREEN_H + (BW.ie?document.body.scrollTop:pageYOffset);
		HOVERING= true;
		
		/* I'm using a timeout for ie4 here, because it doesn't store the measurements quickly enough. Does anybody know why this happens? */
		if (BW.ie4) setTimeout('TOOLTIP.measureIt(); placeIt();', DELAY/2);
		else { TOOLTIP.measureIt(); placeIt(); }
		if (USE_FADING) TOOLTIP.showTimer= setTimeout('TOOLTIP.blendIn()', DELAY);
		if (!USE_FADING) TOOLTIP.showTimer= setTimeout('TOOLTIP.css.visibility="visible"', DELAY);
  }
}

// Hiding routines
makeTooltip.prototype.popTimer= null;
function popOut(){
	if (IS_LOADED) TOOLTIP.popTimer= setTimeout('dopopOut()', 0)
}
function dopopOut(){
	HOVERING = false;
	clearTimeout(TOOLTIP.showTimer);	
	TOOLTIP.css.visibility= 'hidden';
	clearTimeout(TOOLTIP.fadeTimer);
	TOOLTIP.i= 0;
}

// Measure screensize.
var SCROLLBAR_WIDTH= BW.ns6&&BW.win?14:BW.ns6&&!BW.win?16:BW.ns4?16:0;
var SCREEN_W, SCREEN_H;
function measureScreen() {
	if (IS_LOADED && TOOLTIP != null) {TOOLTIP.css.top= 0+PX;	TOOLTIP.css.left= 0+PX; }
	SCREEN_W = (BW.ie?document.body.clientWidth:innerWidth) - SCROLLBAR_WIDTH;
	SCREEN_H = (BW.ie?document.body.clientHeight:innerHeight);
}

// Opacity methods.
makeTooltip.prototype.blendIn= function(){
	if (BW.ie && BW.win && !BW.ie4) {
		this.css.filter= 'blendTrans(duration=0.5)';
		this.elm.filters.blendTrans.apply();
		this.css.visibility= 'visible';
		this.elm.filters.blendTrans.play();
	}
	else {
		this.css.visibility= 'visible';
		if (!BW.ns4 && !BW.ns6) this.fadeIt();
		// j'ai supprime le fading sous ns6. car pb sur un fond couleur si on efface un calque qui est en train de faire le fading.
	}
}

makeTooltip.prototype.step= 8;
makeTooltip.prototype.i= 0;
makeTooltip.prototype.fadeTimer= null;
makeTooltip.prototype.fadeIt= function(){
	this.i+= this.step;
	//this.css.filter= 'alpha(opacity='+this.i+')';
	this.css.MozOpacity= this.i/100;
	if (this.i<100) this.fadeTimer= setTimeout(this.obj+'.fadeIt()', 40);
	else this.i= 0;
}

// Init function...
var IS_LOADED= false;
var TOOLTIP; // le calque courant à afficher
function popupInit(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	BW.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (BW.opera5) BW.ns6 = 0
	
	//Extending the browsercheck to add windows platform detection.
	BW.win= (navigator.userAgent.indexOf('Windows')>-1)

	if (BW.ns4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove= getMousemove;
	measureScreen();
	if (!BW.ns4) onresize= measureScreen;
	//if (!BW.ns4) TOOLTIP.elm.className= 'normalStyle';
	//if (BW.ie && BW.win && !BW.ie4) TOOLTIP.css.filter= 'alpha(opacity=100)'; //Preloads the windows filters.
	IS_LOADED= true;
}

//*************************************************************************************
// Initialisation des legendes avec les differents calques du document
// Les ID des layers sont passes en argument, avec X et Y pour chaque claque
// ex d'appel : _initLegende("CENTRE_PAGE","DESSOUS","LAYER1","LAYER4","DROITE","DESSUS","LAYER3","LAYER2")
// LAYER1 et 4 seront affiches en dessous du curseur et au centre de la page
// LAYER3 et 2 seront affiches au dessus et à droite du curseur
// On construit TAB_TOOLTIPS qui contient les calques à afficher
var TAB_TOOLTIPS = new Array;
function _initLegendes()
{
	if (_initLegendes.arguments.length == 0) { alert("ERREUR : _initLegendes() n'a pas de parametres"); return; }
	if (!IS_LOADED)
	{
		var id;
		var next_x = POS_X;
		var next_y = POS_Y;
		var param_layer = 0;
		for (var i=0; i<_initLegendes.arguments.length; i++)
		{
			switch (_initLegendes.arguments[i])
			{
				case "X_CENTRE_PAGE" :
				case "X_DROITE" :
				case "X_GAUCHE" :
					next_x = _initLegendes.arguments[i];
					_trace("_initLegendes() : next_x ="+next_x);
					continue;
				case "Y_DESSOUS" :
				case "Y_DESSUS" :
				case "Y_CENTRE_PAGE" :
					next_y = _initLegendes.arguments[i];
					_trace("_initLegendes() : next_y ="+next_y);
					continue;
				default :
					_trace("_initLegendes d'un layer");
					if (param_layer == 0) param_layer = 1; // on a eu au moins un layer en parametre
			}		
			id = _initLegendes.arguments[i];
			_trace("_initLegendes pour le calque : "+id+" next_x="+next_x+" next_y="+next_y);
			TAB_TOOLTIPS[id] = new makeTooltip(id);
			TAB_TOOLTIPS[id].elm.onmouseover= function(){ clearTimeout(TAB_TOOLTIPS[id].popTimer); if(BW.ns4){setTimeout('clearTimeout(TAB_TOOLTIPS[id].popTimer)',20)}; };
			TAB_TOOLTIPS[id].elm.onmouseout= dopopOut;
			TAB_TOOLTIPS[id].pos_x = next_x;
			TAB_TOOLTIPS[id].pos_y = next_y;
		}
		if (param_layer == 0) {alert("ERREUR _initLegendes() : il faut passer au moins un layer en parametre !"); return;}
		popupInit();
	}
}

//Affichage d'une legende sur un lien
var NEXT_ETAT = "show";
function _legende(p_layerName,p_etat)
{
	_trace("_legende("+p_layerName+","+p_etat+") NEXT_ETAT="+NEXT_ETAT);
	NEXT_ETAT = (_legende.arguments[1]!=null ? _legende.arguments[1]: NEXT_ETAT);
	//_trace("--------puis NEXT_ETAT="+NEXT_ETAT);
	if (NEXT_ETAT == "hide") { popOut(); NEXT_ETAT = "show"; }
	else // show
	{
		if (TOOLTIP != null && TOOLTIP.css.visibility == 'visible')
		{
			//_trace("ancien calque à effacer ");
			clearTimeout(TOOLTIP.popTimer);
			dopopOut();
		}
		// affecter le nouveau calque
		TOOLTIP = TAB_TOOLTIPS[p_layerName];
		popUp();
		NEXT_ETAT = "hide";
	}
}

// Interdire le click droit
var rien_a_faire="";
function clickIE(){if (document.all)(rien_a_faire);return false;}
function clickNS(e) {if (document.layers||(document.getElementById&&!document.all))if (e.which==2||e.which==3)(rien_a_faire);return false;}
if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else {document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

// fonctions pour scroller du texte ds un calque
/**********************************************************************************   
ScrollText 
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> 
*********************************************************************************/
/*****************

You set the width and height of the divs inside the style tag, you only have to
change the divScrollTextCont, Remember to set the clip the same as the width and height.
You can remove the divUp and divDown layers if you want. 
This script should also work if you make the divScrollTextCont position:relative.
Then you should be able to place this inside a table or something. Just remember
that Netscape crash very easily with relative positioned divs and tables.

Updated with a fix for error if moving over layer before pageload.

****************/
//If you want it to move faster you can set this lower, it's the timeout:
var speed = 80

//Sets variables to keep track of what's happening
var loop, timer

//Object constructor
function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=BW.dom?document.getElementById(obj):bw.ie4?document.all[obj]:BW.ns4?eval(nest+'document.'+obj):0;
  	this.css=BW.dom?document.getElementById(obj).style:BW.ie4?document.all[obj].style:BW.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=BW.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=BW.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=10; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = BW.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(10,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}
//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(10,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function _scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function _noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}
//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('savoirplus')
	oScroll = new makeObj('divText','savoirplus')
	oScroll.moveIt(10,0)  // on a choisit que le contenu soit et reste à 10 pixels du bord du conteneur
	//oCont.css.visibility = "visible"
	scrolltextLoaded = true
}
//Call the init on page load if the browser is ok...
function _initScroll() {
	if (BW.bw) scrolltextInit()
}

bigSize='x-small';
smallSize='xx-small';
function _tailleTexte() {
	css=BW.dom?document.getElementById('divText').style:BW.ie4?document.all['divText'].style:BW.ns4?document.divText:0;
	oldSize=css.fontSize;	
	if(oldSize==smallSize) {
		css.fontSize = bigSize;
	}
	else {
		css.fontSize=smallSize;
	}
}

function _avertissement()
{
  // controle que le popup n'a pas deja ete affiché
  /*
  // LA FONCTION EST INACTIVEE : LES RESERVATIONS SONT OUVERTES A TOUS - modif du 29/12
  if (getCookie("popavertissement")==null) {
  	          avertissement=window.open('avertissement.htm',"popup","left=60,top=60,          HEIGHT=250,WIDTH=550,resizable,scrollbars");
	avertissement.focus();
    // Enregistre le cookie pour une durée de 3 minutes
    var pathname=location.pathname;
    var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
    var date_exp = new Date();
    //date_exp.setTime(date_exp.getTime()+(1*3600*1000)); // 1 heure
	date_exp.setTime(date_exp.getTime()+(3*60*1000)); // 3 MINUTES
    setCookie("popavertissement","ok",date_exp,myDomain);
	
  }
*/
}

function _windowResize(width, height)   {
	IE5=NN4=NN6=false
  if (document.all) 
    IE5=true;
  else if (document.getElementById) 
    NN6=true;
  else if (document.layers) 
    NN4=true;
  if (IE5) {self.resizeTo(width+10,height+31);}
  else if (NN6) {self.sizeToContent();}
  else {window.resizeTo(width,height+20);}
  self.focus()
} 

// merci à O.Hondermarck pour la fonction suivante (www.toutjavascript.com)
function _formatNb(valeur,decimal) {
// formate un nombre en vue de son affichage, avec 'decimal' chiffres après la virgule et un separateur pour les milliers
	separateur=' ';
	var deci=Math.round( Math.pow(10,decimal)*(valeur-Math.floor(valeur)) );
	var val=Math.abs(Math.floor(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.abs(Math.round(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) {
		if (deci>0) {
				if ((valeur-Math.floor(valeur))>=0.1){ // si le chiffre apres la virgule n'est pas 0
				deci=deci.toString();
				} else { // si le chiffre apres la virgule est 0
				deci="0"+deci.toString();
				}
		} else {
			deci="";
			for (var j=0;j<decimal;j++) deci+="0";
		}
		val_format=val_format+"."+deci.substring(0); 
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

// fonctions date
// merci à Olivier Hondermark toujavascript.com
function _don_date_jour()
	{var date_jour=new Date();
	date_jour=_don_date_format(date_jour);
	return date_jour;}
function _don_date_format(d1) {
	var m=new Array(13);
	m[1]="Janvier"; m[2]="Février";	m[3]="Mars"; m[4]="Avril"; m[5]="Mai"; m[6]="Juin";
 	m[7]="Juillet";	m[8]="Aout"; m[9]="Septembre"; m[10]="Octobre";	m[11]="Novembre"; m[12]="Décembre";
	var d=new Array(8);
	d[1]="Dimanche"; d[2]="Lundi"; d[3]="Mardi"; d[4]="Mercredi"; d[5]="Jeudi"; d[6]="Vendredi"; d[7]="Samedi";
	var mois=m[d1.getMonth()+1];
	var jour=d[d1.getDay()+1];
	var date=d1.getDate();
	var an=d1.getYear();
	if (an<200) an=1900+an;
	date=jour+" "+date+" "+mois+" "+an;
	return date;
	}