

/*
* +-------------------------------------+
* Number.prototype.nombreFormate
* +-------------------------------------+
* Params (facultatifs):
* - Int decimales: nombre de decimales (exemple: 2)
* - String signe: le signe precedent les decimales (exemple: "," ou ".")
* - String separateurMilliers: comme son nom l'indique
* Returns:
* - String chaine formatee
*/
 Number.prototype.nombreFormate = function (decimales, signe, separateurMilliers) {
 var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
 if (decimales == undefined) decimales = 2;
 if (signe == undefined) signe = '.';
 if (separateurMilliers == undefined) separateurMilliers = ' ';

 function separeMilliers (sNombre) {
 var sRetour = "";
 while (sNombre.length % 3 != 0) {
 sNombre = "0"+sNombre;
 }
 for (i = 0; i < sNombre.length; i += 3) {
 if (i == sNombre.length-1) separateurMilliers = '';
 sRetour += sNombre.substr(i, 3)+separateurMilliers;
 }
 while (sRetour.substr(0, 1) == "0") {
 sRetour = sRetour.substr(1);
 }
 return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
 }
 if (_sNombre.indexOf('.') == -1) {
 for (i = 0; i < decimales; i++) {
 _sDecimales += "0";
 }
 _sRetour = separeMilliers(_sNombre)+signe+_sDecimales;
 } else {
 var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
 if (sDecimalesTmp.length > decimales) {
 var nDecimalesManquantes = sDecimalesTmp.length - decimales;
 var nDiv = 1;
 for (i = 0; i < nDecimalesManquantes; i++) {
 nDiv *= 10;
 }
 _sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
 }
 _sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
 }
 return _sRetour;
 }

  // vérifie si la touche envoyée est un chiffre
  function isNumberKey(evt)
  {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 37 || charCode == 39)) {
        return false;
    }
    return true;
  }
  
  // ouverture popup
  function openPP(urlPP, largPP, hautPP)
  {        
    var xx = ((screen.width - largPP) / 2);
    var yy = ((screen.height - hautPP) / 2);
    
    this.open(urlPP, 'script', 
                 'top='+yy+', left='+xx+', height='+hautPP+',width='+largPP+', toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');     
  }

  
  // maj vignette ampoule visibilité rubrique
  function rubrique_update_visible_vignette(nom, statut, chemin)
  {     
     if (statut == 0)
       MM_findObj(nom).src = chemin + "images/light_24_off.gif";
     else if (statut == 1)
       MM_findObj(nom).src = chemin + "images/light_24_on.gif";     
  }

  // maj d'une image
  function update_picture(nom, image)
  {     
    MM_findObj(nom).src = image;
  }
  

  // Gere les formulaires de recherche
  function rechercher(rechercher_depuis,recherche_order_by)
  {
  	if (recherche_order_by=='' || recherche_order_by=="undefined")
  	{ 
  		document.formulaire.recherche_order_by.value='';
  	}
  	else
  	{
  		document.formulaire.recherche_order_by.value=recherche_order_by;
  	}
  	document.formulaire.rechercher_depuis.value=rechercher_depuis;	
  	document.formulaire.submit();
  }

  // Gere les formulaires de recherche
  function rechercherBackOffice(rechercher_depuis, recherche_order_by, nomForm)
  {
  	if (recherche_order_by=='' || recherche_order_by=="undefined")
  	{ 
  		document.forms[nomForm].recherche_order_by.value = '';
  	}
  	else
  	{
  		document.forms[nomForm].recherche_order_by.value = recherche_order_by;
  	}
  	
  	
  	document.forms[nomForm].rechercher_depuis.value=rechercher_depuis;	
  	document.forms[nomForm].submit();
  }
  
  // focus sur le champs login du formulaire de connexion
  function LoginFocus() 
	{
		document.formulaire.login.select();
		document.formulaire.login.focus();
	}

	
  // GENERAL : sélection de tous les checkbox  
  function checkAllCB(form, namePrefix, checkAll)
  {
    if (typeof checkAll == "undefined") checkAll = true;
    for (i = 0; i < form.elements.length; i++)
    {
      e = form.elements[i];
      if (e.type == 'checkbox'){
	      if (e.name.slice(0, namePrefix.length) == namePrefix)
	      {
	        e.checked = checkAll;
	      }
      }
    }
  }

  
  // met a jour le contenu d'un div
  function SetDiv(ID,Content) {  
      document.getElementById(ID).innerHTML = Content;
      return;
   }
   

  // DREAMWEAVER
  
  function MM_showHideLayers() { //v3.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
      if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
      obj.visibility=v; }
  }  
  
  function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
      document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  }
  MM_reloadPage(true);
  
  function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }
  
  function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }
  
    // méthode dw de recherche d'obj à partir de son id/nom
  function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
  }
  
  function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }
  
  // GENERAL : submit touche enter
  function submitenter(myfield,e)
  {
    var keycode;
    if (window.event)
    keycode = window.event.keyCode;
    else if (e)
    keycode = e.which;
    else
    return true;
  
    if (keycode == 13)
    {
      myfield.form.submit();
      return false;
    }
      else
      return true;
  }
  
  

  function masquerElement ( tblElement )
  {

		for (var i=0; i < tblElement.length; ++i)
		{
			//var item = tblChampSelect[i];
			document.getElementById(tblElement[i]).style.visibility = "hidden";
			document.getElementById(tblElement[i]).style.display    = "none";
		}
		
  }
  
  // Fonction de stockage des scripts à charger
  FuncOL = new Array();
	function StkFunc(Obj)
	{
		FuncOL[FuncOL.length] = Obj;
	}
				
	// Execution des scripts au chargement de la page
	window.onload = function() 
	{
		for(i=0; i<FuncOL.length; i++)
			{FuncOL[i]();}
	}
	
	
// OVERTRAIL
var OverTrailHeight, OverTrailWidth;
function OverTrail(html,width,height,padding) {
	OverTrailWidth = width+padding*2+2;
	OverTrailHeight = height+padding*2+2;
	ObjTrail = document.getElementById("overtrail");
	ObjTrail.style.width = (document.all?OverTrailWidth:width)+"px";
	ObjTrail.style.padding = padding+"px";
	ObjTrail.innerHTML = html;
	document.onmousemove = FollowMouse;
}
function OverTrail_Img(imagename,width,height) { OverTrail('<img src="' + imagename + '" border="0">',width,height,10); }
function OverTrail_Txt(html,width,height) { OverTrail(html,width,height,5); }
function HideTrail() {
	document.getElementById("overtrail").style.visibility="hidden";
	document.onmousemove="";
}

function FollowMouse(e)
{
   // we don't use "this" because this method is assign to an event of document
   // and so is dereferenced
   if(e == undefined)
   {
     e = event;
   }

  // gecko, konqueror,
   if ( e.pageX != undefined)
   { 
     x = e.pageX;
     y = e.pageY;
    }
    
    // ie4 ?
    else if(event != undefined && event.x != undefined && event.clientX == undefined)
    { 
      x = event.x;
      y = event.y;
    }
    
    // IE6,  IE7, IE5.5
    else if(e.clientX != undefined )
    { 
      if(document.documentElement)
      {
        x = e.clientX + ( document.documentElement.scrollLeft || document.body.scrollLeft);
        y = e.clientY + ( document.documentElement.scrollTop || document.body.scrollTop);
      }
      else
      {
        x = e.clientX + document.body.scrollLeft;
        y = e.clientY + document.body.scrollTop;
      }
    /*}else if(event != undefined && event.x != undefined){ // IE6,  IE7, IE5.5
        tooltip.x = event.x + ( document.documentElement.scrollLeft || document.body.scrollLeft);
        tooltip.y = event.y + ( document.documentElement.scrollTop || document.body.scrollTop);
    */
    }
    else
    {
      x = 0;
      y = 0;
    }
    
  x += 15;
  y += 15;  
  
  // debordement bas de page
  // seb : vérifier ici les valeurs de xmax et ymax sous ie
	xmax=document.all? document.body.clientWidth+document.body.scrollLeft : window.innerWidth+window.pageXOffset-15;
	ymax=document.all? document.body.clientHeight+document.body.scrollTop : window.innerHeight+window.pageYOffset-15;
    
  if (x+OverTrailWidth>xmax) x=x-OverTrailWidth-30;
	if (y+OverTrailHeight>ymax) y=y-OverTrailHeight-15;  
    
	document.getElementById("overtrail").style.left=x+"px";
	document.getElementById("overtrail").style.top=y+"px";
	document.getElementById("overtrail").style.visibility="visible";
    
}








/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * enables highlight and marking of rows in data tables
 *
 */
function PMA_markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'ligneInpaire' != rows[i].className.substr(0,12) && 'lignePaire' != rows[i].className.substr(0,10) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}

// infobulle
var xOffset=6
var yOffset=5

var affiche = false; // La variable i nous dit si le bloc est visible ou non
var w3c=document.getElementById && !document.all;
var ie=document.all;

if (ie||w3c) {
var laBulle
}

function ietruebody(){ // retourne le bon corps...
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function deplacer(e) {
if(affiche){
var curX = (w3c) ? e.pageX : event.x + ietruebody().scrollLeft;
var curY = (w3c) ? e.pageY : event.y + ietruebody().scrollTop;

var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
var winheight = ie && !window.opera ? ietruebody().clientHeight : window.innerHeight - 20;

var rightedge = ie && !window.opera ? winwidth - event.clientX - xOffset : winwidth - e.clientX - xOffset;
var bottomedge = ie && !window.opera ? winheight - event.clientY - yOffset : winheight - e.clientY - yOffset;

var leftedge = (xOffset < 0) ? xOffset*(-1) : -1000

// modifier la largeur de l'objet s'il est trop grand...
if(laBulle.offsetWidth > winwidth / 2){
// laBulle.style.width = winwidth / 2
}

// si la largeur horizontale n'est pas assez grande pour l'info bulle
if(rightedge < laBulle.offsetWidth){
// bouge la position horizontale de sa largeur à gauche
laBulle.style.left = curX - laBulle.offsetWidth + "px"
} else {
if(curX < leftedge){
laBulle.style.left = "5px"
} else{
// la position horizontale de la souris
laBulle.style.left = curX + xOffset + "px"
}
}

// même chose avec la verticale
if(bottomedge < laBulle.offsetHeight){
laBulle.style.top = curY - laBulle.offsetHeight - yOffset + "px"
} else {
laBulle.style.top = curY + yOffset + "px"
}
}
}
function showTooltip(text) {
if (w3c||ie){
laBulle = document.all ? document.all["infoBulle"] : document.getElementById ? document.getElementById("infoBulle") : ""
laBulle.innerHTML = text; // fixe le texte dans l'infobulle
laBulle.style.visibility = "visible"; // Si il est cachée (la verif n'est qu'une securité) on le rend visible.
affiche = true;
}
}
function hideTooltip() {
if (w3c||ie){
affiche = false
laBulle.style.visibility="hidden" // avoid the IE6 cache optimisation with hidden blocks
laBulle.style.top = '-100000px'
laBulle.style.backgroundColor = ''
laBulle.style.width = ''
}
}

document.onmousemove = deplacer; // des que la souris bouge, on appelle la fonction move pour mettre a jour la position de la bulle.


