// fonctions pour la récupération d'un coin d'un div
fDomOffset = function( oObj, sProp )
{
 // oObj : [Object] - Objet dont on désire le positionnement
 // sProp : [String] - Propriété désirée : offsetLeft - offsetTop
 var iVal = 0;
 // On boucle tant que l'on n'est pas à la racine du document
 while (oObj && oObj.tagName != 'BODY') {
  eval('iVal += oObj.' + sProp + ';');
  oObj = oObj.offsetParent;
 }
 return iVal;
}

function whatIsNavigator()
{
	if(navigator.appName=='Microsoft Internet Explorer')
		return 'IE';
	else
		if(navigator.appName=='Netscape'){
			if (navigator.vendor=="") { // Mozilla
				return 'FOX';
			}else return 'NAN';
	}else return 'NAN';
} 

function getObjInnerText (obj) { 
return (obj.innerText) ? obj.innerText 
: (obj.textContent) ? obj.textContent 
: ""; 
} 

function containTexte(div,sel)
{
	var j=0;
	for (j=0;j<div.childNodes.length;j++)
	{
		chaine = div.childNodes[j].nodeValue;
			if(chaine != null && chaine.match(sel))
				return j;
	}
	return 0;
}

// fonction qui récupère la sélection javascript
function getSel()
{
 var txt = null;
 if (document.getSelection)
 {
 txt = document.getSelection();
 }
 else if (document.selection)
 {
 txt = document.selection.createRange().text;
 }
 else if (window.getSelection)
 {
 txt = window.getSelection();
 }
 return txt;
}

// fonction qui teste a chaque drag de la légende si la div légende se trouve au dessus d'une combo... si oui alors on l'a cache (bug de IE)
var fSwapSelectDiv;
function fSwapSelect()
{
 oObj = document.getElementById(fSwapSelectDiv); 
 var Top_Element  = fDomOffset(oObj, 'offsetTop');
 Left_Element  = fDomOffset(oObj, 'offsetLeft');
 Largeur_Element  = oObj.offsetWidth;
 Hauteur_Element  = oObj.offsetHeight;
 oSelects = document.getElementsByTagName('SELECT');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   Top_Select = fDomOffset(oSlt, 'offsetTop');
   Left_Select = fDomOffset(oSlt, 'offsetLeft');
   Largeur_Select = oSlt.offsetWidth;
   Hauteur_Select = oSlt.offsetHeight;
   isLeft = false;
   if ((Left_Element > (Left_Select - Largeur_Element)) && (Left_Element < (Left_Select + Largeur_Select))) {
    isLeft = true;
   }
   isTop = false;
   if ((Top_Element > (Top_Select - Hauteur_Element)) && (Top_Element < (Top_Select + Hauteur_Select))) {
    isTop = true;
   }
   if (isLeft && isTop) {
    sVis = (oObj.style.visibility == 'hidden') ? 'visible' : 'hidden';
    if (oSlt.style.visibility != sVis) {oSlt.style.visibility = sVis;}
   } else {
    if (oSlt.style.visibility != 'visible') {oSlt.style.visibility = 'visible';}
   }
  }
 }
} 

//cache tous les object de la page
function fHideObject()
{
 oSelects = document.getElementsByTagName('object');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   oSlt.hide();
   
  }
 }
 
} 

//affiche tous les select de la page
function fShowObject()
{
 oSelects = document.getElementsByTagName('object');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   oSlt.show();
   
  }
 }
 
} 

//cache tous les select de la page
function fHideSelect()
{
 oSelects = document.getElementsByTagName('select');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   oSlt.hide();
   
  }
 }
 
} 

//affiche tous les select de la page
function fShowSelect()
{
 oSelects = document.getElementsByTagName('select');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   oSlt.show();
   
  }
 }
 
} 

//affiche tous les select de la page
function fToggleSelect()
{
 oSelects = document.getElementsByTagName('select');
 if (oSelects.length > 0) {
  for (i = 0; i < oSelects.length; i++) {
   oSlt = oSelects[i];
   oSlt.toggle();
   
  }
 }
 
} 
// retourne la largeur de la fenêtre du navigateur
function largeur_fenetre()
{
 if( typeof( window.innerWidth ) == 'number' ) {
	myWidth = window.innerWidth;
 } 
 else if( document.documentElement && document.documentElement.clientWidth  ) {
	myWidth = document.documentElement.clientWidth;
 }
 else if( document.body &&  document.body.clientWidth  ) {
	myWidth = document.body.clientWidth; 
 }
 return myWidth;
} 

// retourne la hauteur de la fenêtre du navigateur
function hauteur_fenetre()
{
 if( typeof( window.innerHeight ) == 'number' ) {
	myHeight = window.innerHeight;
 }
 else if( document.documentElement && document.documentElement.clientHeight  ) {
	myHeight = document.documentElement.clientHeight;
 }
 else if( document.body && document.body.clientHeight ) {
	myHeight = document.body.clientHeight;
 }
 return myHeight;
}

function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' ) {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  } else if( document.body &&  document.body.scrollLeft  ) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement &&  document.documentElement.scrollLeft  ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body &&  document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement &&  document.documentElement.scrollTop  ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return  scrOfY ;
}


//centre un div passer en paramètre juste en largeur
function centrerDivLargeur(sId,largeur)
{
	var width=document.getElementById(sId).offsetWidth;//largeur de l'élément à positionner
	if (largeur)
		width = largeur;
	var pWidth=largeur_fenetre();//Largeur de l'élément parent
	var posX=(pWidth/2)-(width/2);
	if (posX < 0)
		posX = 0;
	document.getElementById(sId).style.top='0px';
	document.getElementById(sId).style.left=posX+"px";
}

// permet de garantir que l'overlay est bien a sa place.
function moveWindow()
{
	
	var widNav = largeur_fenetre() + getScrollX(); var widGlobal = $('allpage').getWidth();
	var heiNav = hauteur_fenetre() +getScrollY(); var heiGlobal = $('allpage').getHeight();
	var wid; var hei;
	if (widNav > widGlobal) wid = widNav; else wid = widGlobal;
	if (heiNav > heiGlobal) hei = heiNav; else hei = heiGlobal;
	var margin = wid - 763;
	if (margin < 0) margin=0;
	wid = wid + margin;
	
	$('overlay').setStyle({
		'margin-left': '-'+margin+'px',
		width: wid+'px',
		height: hei+'px'
	});
}
//centre un div passer en paramètre
function centrerDiv(sId,largeur,hauteur)
{
	var height=document.getElementById(sId).offsetHeight;//hauteur de l'élément à positionner
	if (hauteur)
		height = hauteur;
	var width=document.getElementById(sId).offsetWidth;//largeur de l'élément à positionner
	if (largeur)
		width = largeur;
	var pHeight=hauteur_fenetre();//Hauteur de l'élément parent
	var pWidth=largeur_fenetre();//Largeur de l'élément parent
	var posY=(pHeight/2)-(height/2);
	if (posY <0 ) posY = 0;
	var posX=(pWidth/2)-(width/2);
	if (posX <0 ) posX = 0;
	document.getElementById(sId).style.top=posY+"px";
	document.getElementById(sId).style.left=posX+"px";
}

//centre un div par rapport à un autre div
function centrerDivByDiv(sId, sIdCentrage, width,height)
{
	var height=height;//hauteur de l'élément à positionner
	var width=width;//largeur de l'élément à positionner
	var pHeight=document.getElementById(sIdCentrage).offsetHeight;//hauteur de l'élément à positionner
	var pWidth=document.getElementById(sIdCentrage).offsetWidth;//largeur de l'élément à positionner
	var top = document.getElementById(sIdCentrage).style.top;
	top = top.replace('px','');
	top = parseInt(top);
	var left = document.getElementById(sIdCentrage).style.left;
	left = left.replace('px','');
	left = parseInt(left);
	var posY=(pHeight/2)-(height/2) + top ;
	var posX=(pWidth/2)-(width/2) + left;
	document.getElementById(sId).style.top=posY+"px";
	document.getElementById(sId).style.left=posX+"px";
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
