//////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION: Ce fichier dépend de "ajax.js" et "tools.js" s'assurer que les paths 
//            ci-bas sont valides.
//////////////////////////////////////////////////////////////////////////////////////////
document.write("<script type='text/javascript' src='includes/ajax.js'> <\/script>");
document.write("<script type='text/javascript' src='includes/tools.js'> <\/script>");

////////////////////////////////////////////////////////////////////////
//////// GESTION TOOLTIPS //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
var DELAY_BEFORE_HIDDING_TIP = 600; // En millisecondes
var TOOLTIP_ID_PREFIX = "sdiTipDiv";
var TOOLTIP_POINTER_ID__TOP_LEFT = "sdiTipPointerTopLeft"; 
var TOOLTIP_POINTER_ID__TOP_RIGHT = "sdiTipPointerTopRight"; 
var TOOLTIP_POINTER_ID__BOTTOM_LEFT = "sdiTipPointerBottomLeft"; 
var TOOLTIP_POINTER_ID__BOTTOM_RIGHT = "sdiTipPointerBottomRight";

var TOOLTIP_SHADOW_WIDTH = 2;  
var TOOLTIP_SHADOW_STARTING_AT = 2; // Détermine si l'ombrage sera plus ou moins foncé 

var offsetFromCursorX=12; //Customize x offset of tooltip
var offsetFromCursorY=10; //Customize y offset of tooltip

var offsetDivFromPointerX=10; //Customize x offset of tooltip DIV relative to pointer image
var offsetDivFromPointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

//document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="'+TOOLTIP_POINTER_ID__TOP_LEFT+'" class="sdiTooltipPointer" src="images/sdiHtml/tooltips/arrow_topLeft.gif"/>');
document.write('<img id="'+TOOLTIP_POINTER_ID__TOP_RIGHT+'" class="sdiTooltipPointer" src="images/sdiHtml/tooltips/arrow_topRight.gif"/>');
document.write('<img id="'+TOOLTIP_POINTER_ID__BOTTOM_LEFT+'" class="sdiTooltipPointer" src="images/sdiHtml/tooltips/arrow_bottomLeft.gif"/>');
document.write('<img id="'+TOOLTIP_POINTER_ID__BOTTOM_RIGHT+'" class="sdiTooltipPointer" src="images/sdiHtml/tooltips/arrow_bottomRight.gif"/>');

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enableTip=false;
var enabledTipId=null;
// Bornes du tooltip affiché pour détection du "mouseout"
var tipLeftX=null;
var tipRightX=null;
var tipTopY=null;
var tipBottomY=null;

var delayedEnabledTipId=null;
var bHideTipOnMouseOutCancelled=false;
var bShowTipOnMouseOverCancelled=false;
var bHideTipOnMouseOut=false;
var bIsHoveringTip=false;

// Mis à jour lors du mouvement de la souris
var curX=null;
var curY=null;
var rightEdge=null;
var bottomEdge=null;
var leftEdge=null;
var winWidth=null;
var winHeight=null;

//---------------------------------------------------------------
//--- Patch IE --------------------------------------------------
//---------------------------------------------------------------
function ieTrueBody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

//---------------------------------------------------------------
//--- Appelé lorsque la souris est déplacée, elle cache ou ------
//--- affiche un tip selon la "commande" en attente.       ------ 
//---------------------------------------------------------------
function manageTipOnMouseMove(e)
{	
	//-- CACHER le tip s'il y a lieu ------------------------------------
	if (enabledTipId!=null && bHideTipOnMouseOut && !bIsHoveringTip)
	{
		hideTip();
		return;
	}	

	//--- MISE À JOUR du pointeur de la souris et cie ----------------	
	if ((e && e!=null) || (!ns6 && event && event!=null))
	{		
		curX=(ns6)?e.pageX : event.clientX+ieTrueBody().scrollLeft;
		curY=(ns6)?e.pageY : event.clientY+ieTrueBody().scrollTop;
		// Déterminer à quelle distance se trouve la souris du coin de la fenêtre
		winWidth=ie&&!window.opera? ieTrueBody().clientWidth : window.innerWidth-20
		winHeight=ie&&!window.opera? ieTrueBody().clientHeight : window.innerHeight-20
		
		rightEdge=ie&&!window.opera? winWidth-event.clientX-offsetFromCursorX : winWidth-e.clientX-offsetFromCursorX
		bottomEdge=ie&&!window.opera? winHeight-event.clientY-offsetFromCursorY : winHeight-e.clientY-offsetFromCursorY
		
		leftEdge=(offsetFromCursorX<0)? offsetFromCursorX*(-1) : -1000;
		
		//-- Vérifier si pointeur au-dessus du tip -----
		if (enabledTipId!=null)
			bIsHoveringTip = (curX>=tipLeftX && curX<=tipRightX && curY>=tipTopY && curY<=tipBottomY);
	}

	//-- AFFICHER le tip s'il y a lieu ----------------------------------
	if (enableTip && enabledTipId!=null)
	{
		// S'assurer que les anciens pointeurs et ombrage sont bien cachés
		hideTipPointers();
		sdiRemoveShadow(document.sdiTooltipShadows);
	
		bHideTipOnMouseOut=false;
		bIsHoveringTip=false;
		var isPointerLeft=true;
		var isPointerTop=true;		
	
		var oTip    = document.getElementById(enabledTipId);
		var oPointer= document.getElementById(TOOLTIP_POINTER_ID__TOP_LEFT);
				
		var nonDefaultPos=false;		
		//document.write("winWidth="+winWidth+"  winHeight="+winHeight+"  rightEdge="+rightEdge+"   bottomEdge="+bottomEdge+"   oTip.offsetWidth="+oTip.offsetWidth+"  oTip.offsetHeight="+oTip.offsetHeight);
		
		//-- Afficher tip à GAUCHE du pointeur (pas assez d'espace À DROITE de la souris pour afficher le tip)
		if (rightEdge<oTip.offsetWidth)
		{
			// Déplacer le tip à gauche pour l'équivalent de sa largeur
			oTip.style.left=curX-oTip.offsetWidth+"px";
			nonDefaultPos=true;
			isPointerLeft=false;
		}		
		//-- Afficher tip COMPLÈTEMENT à GAUCHE de la fenêtre ---
		else if (curX<leftEdge)
			oTip.style.left="5px";
			
		//-- Afficher tip à DROITE de la souris	---------			
		else
		{
			// Positionner le tip horizontalement à la hauteur de la souris
			oTip.style.left = curX+offsetFromCursorX-offsetDivFromPointerX+"px";
			//oPointer.style.left = curX+offsetFromCursorX+"px";
		}

		
		//-- Afficher tip à en HAUT de la souris (pas assez d'espace dans la fenêtre, EN-DESSOUS la souris pour afficher le tip)
		if (bottomEdge<oTip.offsetHeight)
		{
			oTip.style.top=(curY-oTip.offsetHeight-offsetFromCursorY-offsetDivFromPointerY+1)+"px";
			oTip.style.filter=""; // Enlever ombrage car en conflit avec pointeur
			nonDefaultPos=true;
			isPointerTop=false;
		}
		//-- Afficher tip en BAS de la souris ------
		else
		{
			oTip.style.top=curY+offsetFromCursorY+offsetDivFromPointerY+"px";
			//oPointer.style.top=curY+offsetFromCursorY+"px";
		}

		oTip.style.visibility="visible";
		//oTip.style.display="inline"; //#### AJOUT DU BLANC EN BAS DU DOCUMENT		
		
		//--- Positionner Pointeur de la bulle ----------------		
		var pointerId;
		var pointerLeft;
		var pointerTop;
		var displayShadowAbove=false;
		// Haut gauche
		if (isPointerTop && isPointerLeft)
		{
			pointerId   = TOOLTIP_POINTER_ID__TOP_LEFT;
			pointerLeft = curX+offsetFromCursorX+"px";
			pointerTop  = curY+offsetFromCursorY+"px";
		}
		// Haut droit			
		else if (isPointerTop && !isPointerLeft)
		{
			pointerId   = TOOLTIP_POINTER_ID__TOP_RIGHT;
			var offsetX = ie?offsetFromCursorX+20: offsetFromCursorX+12;			
			pointerLeft = (curX-offsetX)+"px";
			pointerTop  = curY+offsetFromCursorY+"px";			
		}
		// Bas gauche
		else if(!isPointerTop && isPointerLeft)
		{
			pointerId   = TOOLTIP_POINTER_ID__BOTTOM_LEFT;
			pointerLeft = curX+offsetFromCursorX+"px";
			pointerTop  = (curY-offsetFromCursorY-offsetDivFromPointerY)+"px";
			displayShadowAbove=true;
		}
		// Bas droite
		else if(!isPointerTop &&! isPointerLeft)
		{
			pointerId   = TOOLTIP_POINTER_ID__BOTTOM_RIGHT;
			var offsetX = ie?offsetFromCursorX+20: offsetFromCursorX+12;			
			pointerLeft = (curX-offsetX)+"px";
			pointerTop  = curY+offsetFromCursorY+"px";
			pointerTop  = (curY-offsetFromCursorY-offsetDivFromPointerY)+"px";
			displayShadowAbove=true;
		}
			
		oPointer=document.getElementById(pointerId);
		oPointer.style.left=pointerLeft;
		oPointer.style.top=pointerTop;
		//oPointer.style.visibility="visible";
		oPointer.style.display="inline";
		
		//-- Zone occupée par le tootip ---
		tipLeftX  = parseInt(oTip.style.left);
		tipRightX = tipLeftX + oTip.offsetWidth;
		tipTopY   = parseInt(oTip.style.top);
		tipBottomY= tipTopY + oTip.offsetHeight;
		
		//-- Afficher ombrage ----
		document.sdiTooltipShadows = sdiDisplayShadow(oTip, TOOLTIP_SHADOW_WIDTH, TOOLTIP_SHADOW_STARTING_AT, displayShadowAbove);
		
		//alert("tipLeftX="+tipLeftX+"  tipRightX="+tipRightX+"  tipTopY="+tipTopY+"  tipBottomY="+tipBottomY+"\r\n SourisX="+curX+" SourisY="+curY);
		
		// Afficher le tip qu'un seule fois
		enableTip=false; 
		
		// Cacher les combobox sous (dessus) le tip (bug IE)
		restoreOverlayingCombos(document.tooltipHiddenCombos);
		document.tooltipHiddenCombos = hideOverlayingCombos(oTip);
	}
}

//---------------------------------------------------------------
//--- Cacher les 4 versions de pointeurs de bulle ---------------
//---------------------------------------------------------------
function hideTipPointers()
{
	document.getElementById(TOOLTIP_POINTER_ID__TOP_LEFT).style.display="none";  // .visibility="hidden";
	document.getElementById(TOOLTIP_POINTER_ID__TOP_RIGHT).style.display="none";  // .visibility="hidden";
	document.getElementById(TOOLTIP_POINTER_ID__BOTTOM_LEFT).style.display="none";  // .visibility="hidden";
	document.getElementById(TOOLTIP_POINTER_ID__BOTTOM_RIGHT).style.display="none";  // .visibility="hidden";
}

//---------------------------------------------------------------
//--- Cacher immédiatement le tip affiché s'il y en a un --------
//---------------------------------------------------------------
function hideTip()
{
	if (enabledTipId!=null)
	{
		var oTip = document.getElementById(enabledTipId);
		//oTip.style.display="none";  // .visibility="hidden";
		oTip.style.visibility="hidden";		
		oTip.style.left="-1000px";		
		// Restaurer combobox (Bug IE)
		restoreOverlayingCombos(document.tooltipHiddenCombos);		
	}	
	enableTip=false;
	enabledTipId=null;
	bHideTipOnMouseOut=false
	bIsHoveringTip=false;
	
	// Zone occupée par le pointeur
	tipLeftX=null;
	tipRightX=null;
	tipTopY=null;
	tipBottomY=null;			

	hideTipPointers();	
	sdiRemoveShadow(document.sdiTooltipShadows);
}


//---------------------------------------------------------------
//--- Signale que le tip devra être caché dans 1 seconde     ----
//--- Si par ce temps, la souris ne se trouve pas sur le tip ----
//--- lui-même où que celui-ci n'a pas été réaffiché.        ----
//---------------------------------------------------------------
function hideTipOnMouseOut()
{	
	bHideTipOnMouseOutCancelled=false;
	window.setTimeout("bHideTipOnMouseOut=!bHideTipOnMouseOutCancelled; manageTipOnMouseMove()", DELAY_BEFORE_HIDDING_TIP);
}

//-----------------------------------------------------------------
//--- Affiche le tip spécifié. Le tip doit être un <DIV> existant -
//--- dans la page.
//-----------------------------------------------------------------
function showTip(tipId)
{	
	// Si le tip n'existe pas, ignorer
	if (document.getElementById(tipId)==null)
		return;
		
	if (enabledTipId!=null && enabledTipId!=tipId)
		hideTip(); // Cacher ancien tip
	enableTip=true;
	enabledTipId=tipId;
	bHideTipOnMouseOut=false
	bIsHoveringTip=false;
	bHideTipOnMouseOutCancelled=true;
	
	document.onmousemove=manageTipOnMouseMove;
}

//---------------------------------------------------------------
//--- Le tip sera affiché dans X millisecondes
//---------------------------------------------------------------
function showTipOnMouseOver(tipId, delayBeforeShowingTip)
{
	bShowTipOnMouseOverCancelled=false;
	delayedEnabledTipId=tipId;
	window.setTimeout("if (!bShowTipOnMouseOverCancelled){showTip(delayedEnabledTipId); manageTipOnMouseMove();}", delayBeforeShowingTip);
}

document.onmousemove=manageTipOnMouseMove

////////////////////////////////////////////////////////////////////////////
//////// FIN TOOLTIPS //////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
//////// POPUPS (alerts) /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////


//----------------------------------------------------------------
//-- Permet d'établir un format d'alert (html) contenant des    --
//-- expresssion régulières (placeholder) qui seront remplacées --
//-- lors de la génération des alerte.                          --
//-- Les placeholders sont: "{title}" et "{body}"                --
//----------------------------------------------------------------
function sdiSetErrorTemplate(htmlTemplate)
{
	document.sdiErrorTemplate = htmlTemplate;
}
function sdiSetWarningTemplate(htmlTemplate)
{
	document.sdiWarningTemplate = htmlTemplate;
}
function sdiSetConfirmTemplate(htmlTemplate)
{
	document.sdiConfirmTemplate = htmlTemplate;
}
function sdiSetUrlPopupTemplate(htmlTemplate)
{
	document.sdiUrlPopupTemplate = htmlTemplate;
}

//-----------------------------------------------------------------------
//-- Affiche un popup comme le ferait alert() mais en html.          ----
//-----------------------------------------------------------------------
function sdiError(htmlTitle, htmlContent, onOkJs, width, styleClass)
{
	// Générer le div du popup
	var popupId = sdiGenPopupWithTemplate(null, htmlTitle, htmlContent, onOkJs, null, 
	                                      document.sdiErrorTemplate, width, styleClass)
	// Afficher le popup
	sdiShowPopup(popupId, true);
}

//-----------------------------------------------------------------------
//-- Affiche un popup comme le ferait alert() mais en html.          ----
//-----------------------------------------------------------------------
function sdiWarning(htmlTitle, htmlContent, onOkJs, width, styleClass)
{
	// Générer le div du popup
	var popupId = sdiGenPopupWithTemplate(null, htmlTitle, htmlContent, onOkJs, null, 
	                                      document.sdiWarningTemplate, width, styleClass)
	// Afficher le popup
	sdiShowPopup(popupId, true);
}

//-----------------------------------------------------------------------
//-- Affiche un popup comme le ferait confirm() mais en html.        ----
//-----------------------------------------------------------------------
function sdiConfirm(htmlTitle, htmlContent, onOkJs, onCancelJs, width, styleClass)
{
	// Générer le div du popup
	var popupId = sdiGenPopupWithTemplate(null, htmlTitle, htmlContent, onOkJs, onCancelJs,
	                                      document.sdiConfirmTemplate, width, styleClass);
	// Afficher le popup
	sdiShowPopup(popupId, true);
}

//-----------------------------------------------------------------------
//-- Affiche un popup contenant une page web (url)  ---------------------
//-----------------------------------------------------------------------
function sdiUrlPopup(url, width, height, htmlTitle)
{	
	var DEFAULT_WIDTH=500;
	var DEFAULT_HEIGHT=-100;
	//var popupId = removeSpecialCharacters(url);	
	var	popupId = getUniqueId();

	// Vérifier s'il n'existe pas déjà
	var oDiv = top.document.getElementById(popupId);
	if (oDiv==null)
	{
		//-- Largeur --------
		if (!width || width==null || !width>0)
			width=DEFAULT_WIDTH; // Largeur d'un alert standard		
		if (width<1)
	   		width = getWindowWidth() + width;
		//-- Hauteur --------
		if (!height || height==null || !height>0)
			height=DEFAULT_HEIGHT;
		if (height<1)
	   		height = getWindowHeight() + height;
		
	    // Préparer contenu selon template
		var content = document.sdiUrlPopupTemplate;
		content = replaceInString(content, "{url}", url, true);
		content = replaceInString(content, "{totalWidth}", width, false);						
		content = replaceInString(content, "{iframeWidth}", width-2, false);
		content = replaceInString(content, "{iframeHeight}", height-30, false);
		content = replaceInString(content, "{popupId}", popupId, false);
				
	    // Générer popup (div)
		sdiGenPopup(popupId, content, width, height, "_");
	}

	// Afficher le popup
	sdiShowPopup(popupId, true);
}


//-----------------------------------------------------------------------
//-- Cré dynamiquement un popup (contenu seulement, pas d'url) comme ----
//-- le ferait le tag <sdi:popup>.                                   ----
//-----------------------------------------------------------------------
function sdiGenPopupWithTemplate(popupId, htmlTitle, htmlContent, onOkJs, onCancelJs,
                                 htmlTemplate, width, height, styleClass)
{	
	// Si id non-spécifié, cré id avec titre et contenu ex: "MONTITREMONCONTENU"
	if (isEmpty(popupId))
		popupId = removeSpecialCharacters(htmlTitle+htmlContent);

	// Vérifier s'il n'existe pas déjà
	var oDiv = top.document.getElementById(popupId);
	if (oDiv==null)
	{				
	    // Préparer contenu selon template
		var content = htmlTemplate;
		content = replaceInString(content, "{title}", htmlTitle, true);
		content = replaceInString(content, "{body}", htmlContent, true);						
		content = replaceInString(content, "{onOkJs}", isEmpty(onOkJs)?'':onOkJs, true);
		content = replaceInString(content, "{onCancelJs}", isEmpty(onCancelJs)?'':onCancelJs, true);
	    // Générer popup (div)
		sdiGenPopup(popupId, content, width, height, styleClass);
	}			
	return popupId;
}

//-----------------------------------------------------------------------
//-- Cré dynamiquement un popup (contenu seulement, pas d'url) comme ----
//-- le ferait le tag <sdi:popup>.                                   ----
//-----------------------------------------------------------------------
function sdiGenPopup(popupId, htmlContent, width, height, styleClass)
{		
	var DEFAULT_WIDTH=325;	
	
	if (isEmpty(popupId))
		popupId = getUniqueId();

	// Vérifier s'il n'existe pas déjà
	var oDiv = top.document.getElementById(popupId);
	if (oDiv==null)
	{
		var oDiv = top.document.createElement("DIV");	
		oDiv.id = popupId;
		//-- Largeur --------
		if (!width || width==null || !width>0)
			width=DEFAULT_WIDTH; // Largeur d'un alert standard		
		if (width<1)
	   		width = getWindowWidth() + width;
	   	oDiv.style.width = width+"px";
		//-- Hauteur --------
		if (height && height!=null && height<1)
	   		height = getWindowHeight() + height;
		if (height && height!=null && height>0)
			oDiv.style.height = height+"px";
		
		// Classes CSS
		if (isEmpty(styleClass))
			styleClass="popup"; // Défaut
		styleClass = "sdiPopupDiv " + styleClass; // Classe de base
		oDiv.className=styleClass;
		// Signature identifiant que le div en est un de popup (pour sdiHidePopup())
		oDiv.setAttribute("isSdiPopupDiv", "true");
		
		oDiv.innerHTML = htmlContent;

		top.document.body.appendChild(oDiv);
	}
	return popupId;
}

//-----------------------------------------------------------------------
//-- Affiche un popup généré par le tag <sdi:popup> ---------------------
//-----------------------------------------------------------------------
function sdiShowPopup(popupId, bFadeBg, width, height)
{		
	var oPopup = top.document.getElementById(popupId);
//	var oIframe = document.getElementById(popupId+"_iframe");
	// Ajuster la grandeur de la iFrame
//	if (oIframe && oIframe!=null)
//	{
//		resizeIframeToFit(oIframe, width);				
//		oPopup.style.width = (oIframe.width)+"px";
//		oPopup.style.height = (oIframe.height)+"px";	
//	}
	//-- Forcer largeur si spécifiée ---
	if (width && width>0)	
		oPopup.style.width=width+"px";
	if (height && height>0)	
		oPopup.style.height=height+"px";					
	
	//--- Positionner popup -----------------		
	sdiCenterPopup(oPopup);
		
    //--- Générer ombrage --------------
	top.document.sdiPopupShadowDivs = sdiDisplayShadow(oPopup, 4, 1);
	
	//-- Désactive le reste de la fenêtre en y superposant un div ----
	var oFade = top.document.createElement("DIV");
	oFade.style.width = getWindowWidth()+"px";
	var winHeight = getWindowHeight();
	oFade.style.height = (winHeight>document.body.scrollHeight?winHeight:document.body.scrollHeight)+"px";
	oFade.style.left = "0px";
	oFade.style.top = "0px";	
	oFade.style.position = "absolute";
	oFade.style.zIndex = 90;	
	//-- Appliquer une couleur et une semi-transparence ---
	if (bFadeBg)
	{
		oFade.className="sdiPopupFadedBg";
		disableIeCombos(oPopup);
	}
	top.document.body.appendChild(oFade);
	top.document.sdiPopupBgFadeDiv = oFade;

	//-- Cacher les combobox sous (dessus) le tip (bug IE) ----
	restoreOverlayingCombos(top.document.popupHiddenCombos);
	top.document.popupHiddenCombos = hideOverlayingCombos(oPopup);

	oFade.style.visibility="visible";
	oPopup.style.visibility="visible";
}

//--------------------------------------------
//--- Positionner popup ----------------------
//--------------------------------------------
function sdiCenterPopup(oPopup)
{
	
	var iLeft = getIntValue(((getWindowWidth()-oPopup.offsetWidth)/2)+"");
	// 1er tier vertical
	var iVisibleTop = getVisibleTop();
	var iTop = getIntValue((iVisibleTop+(getWindowHeight()-oPopup.offsetHeight)/3)+"");
	oPopup.style.left = iLeft+"px";
	oPopup.style.top = iTop+"px";
}

//-----------------------------------------------------------------------
//-- Cache un popup généré par le tag <sdi:popup> -----------------------
//-----------------------------------------------------------------------
function sdiHidePopup(popupId)
{	
	
	oPopup = top.document.getElementById(popupId);
	
	oPopup.style.left="-1000px";
	oPopup.style.top="-1000px";	
	oPopup.style.visibility="hidden";
		
	//-- Supprimer ombrages ---
	sdiRemoveShadow(top.document.sdiPopupShadowDivs);
				
	//-- Supprimer filtre par-dessus la fenêtre ---
	top.document.body.removeChild(document.sdiPopupBgFadeDiv);		
	
	//-- Restaurer les combos sur IE ---
	restoreOverlayingCombos(document.popupHiddenCombos);		
	enableIeCombos();
}

//-----------------------------------------------------------------------
//-- Cache un popup généré par le tag <sdi:popup> -----------------------
//### NE FONCTIONNE PAS AVEC DES IFRAME
//-----------------------------------------------------------------------
function sdiHidePopupFromInside(oElement)	
{	
	var oOriginalElement = oElement;
	//-- Boucler sur les parents ------------	
	while(oElement && oElement!=null && (!oElement.getAttribute || oElement.getAttribute("isSdiPopupDiv")==null))
		oElement = oElement.parentNode;

	//-- Div du popup parent trouvé -----------
	if (oElement && oElement.getAttribute && oElement.getAttribute("isSdiPopupDiv")!=null)
		sdiHidePopup(oElement.id);
}

//--------------------------------------------------------------------------
//-- Génère un ombrage en bas (ou en haut) et à droite de l'objet spécifié -
//--------------------------------------------------------------------------
function sdiDisplayShadow(oElement, iShadowWidth, iShadowDarknessStartingAt, isShadowAboveElement)
{
	var MAX_WIDTH=4;
	if (!iShadowDarknessStartingAt || iShadowDarknessStartingAt<1 || iShadowDarknessStartingAt>MAX_WIDTH)
		iShadowDarknessStartingAt=1; // Défaut

	var iTop = getDistanceFromPageTop(oElement);
	var iLeft = getDistanceFromPageLeft(oElement);
	//-- Générer ombrages du BAS ou du HAUT ---------
	var oShadows = new Array(iShadowWidth*2);
	for (var i=0; i<iShadowWidth; i++)
	{
		oShadows[i] = document.createElement("DIV");
		oShadows[i].style.width = oElement.offsetWidth+"px";
		oShadows[i].style.height = "1px";		
		oShadows[i].style.left = (iLeft+i+1)+"px";
		if (isShadowAboveElement)	
			oShadows[i].style.top = (iTop - i -1)+"px";
		else
			oShadows[i].style.top = (iTop + oElement.offsetHeight + i)+"px";
		oShadows[i].className="sdiPopupShadowDiv"+(iShadowDarknessStartingAt+i);
		document.body.appendChild(oShadows[i]);
	}
	//-- Générer ombrages de DROITE -----------------
	for (var i=0; i<iShadowWidth; i++)
	{
		var index = iShadowWidth+i;
		oShadows[index] = document.createElement("DIV");
		oShadows[index].style.width = "1px";
		oShadows[index].style.height = (oElement.offsetHeight-1)+"px";
		oShadows[index].style.left = (iLeft + oElement.offsetWidth + i)+"px";
		if (isShadowAboveElement)
			oShadows[index].style.top = (iTop-i)+"px";
		else
			oShadows[index].style.top = (iTop+i+1)+"px";	
		oShadows[index].className="sdiPopupShadowDiv"+(iShadowDarknessStartingAt + i);
		oShadows[index].style.visibility="visible";
		document.body.appendChild(oShadows[index]);
	}
	return oShadows
}

//-----------------------------------------------------------------
//-- Supprime l'ombrage généré. -----------------------------------
//-----------------------------------------------------------------
function sdiRemoveShadow(oShadowDivs)
{
	if (oShadowDivs && oShadowDivs!=null)
	{
		for (var i=0; i<oShadowDivs.length; i++)
		{
			// Éviter de planter si noeud n'existe pas(plus)
			try
			{ 
				document.body.removeChild(oShadowDivs[i]); 	
			}
			catch(e){}
		}	
	}	
}

//----------------------------------------------------------------
//-- Applique un style au combos pour comme si le filtre les
//-- recouvrait.
//-- Les combos se trouvant inclus dans le noeud oExclusionContainerElement
//-- ne seront pas désactivée (ex: popup à faire afficher par-dessus).
//----------------------------------------------------------------
function disableIeCombos(oExclusionContainerElement)
{
	// IE seulement
	if (document.all)
	{
		//#NOTE# Il serait bon de rendre récursif dans les iFrame
		var aCombos = document.getElementsByTagName("select");		
		for(i=0; i <aCombos.length; i++)
		{ 			
			var oCombo = aCombos[i];		
			// Ignorer les combos inclus dans l'élément d'exclusion	
			if (!isNodeAncestor(oExclusionContainerElement, oCombo))
				aCombos[i].className=aCombos[i].className+" sdiPopupFadedBg_ieCombos";
		}
	}
}

//----------------------------------------------------------------
//-- Retirer le style au combos.
//----------------------------------------------------------------
function enableIeCombos()
{
	//-- IE seulement -------------
	if (document.all)
	{
		var aCombos = document.getElementsByTagName("select");		
		for(i=0; i <aCombos.length; i++) 
			aCombos[i].className = removeStyleClass(aCombos[i].className, "sdiPopupFadedBg_ieCombos");
	}
}



//////////////////////////////////////////////////////////////////////
//////// FIN POPUPS //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------
//-- Initialise le champ numérique en retirant le 0 non-significatif
//-- s'il y a lieu.
//-----------------------------------------------------------------------
function initSpinnerVal(fieldId)
{
	var oField = document.getElementById(fieldId);
	var val = oField.value;
	if (endsWith(val, '.0'))	
		oField.value = val.substring(0, val.length-2);
}

//-----------------------------------------------------------------------
//-- Modifie la valeur du contrôle associé à un spinner 
//-- Pour <spinner>
//-----------------------------------------------------------------------
function changeSpinnerVal(fieldId, operator, iStep, sMinVal, sMaxVal, sInitVal)
{			
	var field = document.getElementById(fieldId);
	var iNewVal;	
	//-- Si le controle ne contient pas un chiffre -----------
	if (!field || field.value=='' || isNaN(field.value))
		iNewVal = parseInt(sInitVal);
	else
		iNewVal = eval(parseInt(field.value)+operator+iStep);
		
	//--- Valeur maximale atteinte -------------------
	if (!isNaN(sMaxVal) && iNewVal > parseInt(sMaxVal))
		iNewVal = parseInt(sMaxVal);
	//--- Valeur minimale atteinte -------------------
	else if (!isNaN(sMinVal) && iNewVal < parseInt(sMinVal))
		iNewVal = parseInt(sMinVal);

	field.value = iNewVal;
	//-- Exécuter traitement "onchange" du textbox -----
	field.value = iNewVal;
	if (field.fireEvent)
		field.fireEvent('onchange'); // IE
	else if (field.onchange)
		field.onchange();  // Autres browsers ##		
}

//-----------------------------------------------------------------------
//-- Valide le nombre de caractères dans un textarea et met à jour 
//-- son compteur.
//-- Pour <charsCountdown>
//-----------------------------------------------------------------------
function countdownChars(oTextarea, counterId, maxLength)
{		
	var len = getRealTextLength(oTextarea.value);

	//--- Longueur maximale dépassée -------------
	if (len > maxLength)
	{
		var txt = oTextarea.value;
		//-- Tronquer ------------------------
		while (len > maxLength)
	 	{ 	
			txt = txt.substr(0, txt.length-1);
			len = getRealTextLength(txt);
		}
		if (txt != oTextarea.value)
			oTextarea.value = txt;
	}

	//--- Mettre à jour le compteur ------------
	var remainingChars = maxLength - len;
	var oCounterDiv = document.getElementById(counterId);
	if (oCounterDiv!=null)
		oCounterDiv.innerHTML = ""+remainingChars;
		
	//-- Mettre en rouge s'il reste moins de 20 carcatères ---
	if (remainingChars <= 20)
		oCounterDiv.className = "charsCountdown_lastChars";
	else
		oCounterDiv.className = "charsCountdown";
}

//-----------------------------------------------------------------------
//-- Compter les sauts de ligne comme étant 2 caractères car stocké
//-- comme ça dans la BD: "\r\n"
//-----------------------------------------------------------------------
function getRealTextLength(text)
{
	var lines = text.split("\n");
	return text.length + (lines.length-1);
}

//-----------------------------------------------------------------------
//-- Agrandit une boîte minimisée [+]  ----------------------------------
//-----------------------------------------------------------------------
function expandSdiCollapsable(collapsableContentDivId, minimizedTitleDivId, minimizedTitleSpanId, 
		                      expandedTitleSpanId, changeStatusUrl, customJs)
{
	var oTitleDive = document.getElementById(minimizedTitleDivId);	
	if (oTitleDive.style.display=="none")
		return false; // Ne rien faire, déjà maximisé
	
	//-- Cacher titre minimisé -------------------
	oTitleDive.style.display="none";	
	
	//-- Transférer titre ---------------------
	var oExpandedTitle = document.getElementById(expandedTitleSpanId);	
	var oMinimizedTitle = document.getElementById(minimizedTitleSpanId);
	oExpandedTitle.innerHTML = oMinimizedTitle.innerHTML;
	oMinimizedTitle.innerHTML = "";

	//-- Afficher contenu boîte ------------------
	document.getElementById(collapsableContentDivId).style.display="";
	
	//-- Enregistrer nouveau statut dans la session ----
	if (changeStatusUrl!=null && changeStatusUrl!='')
		createHiddenIFrame(changeStatusUrl);
		
	// Exécuter le code custom "onMaximize" si spécifié
	if (customJs!=null && customJs!="")
		eval(customJs);

	return false; // Pour bloquer l'effet du href=""
}

//-----------------------------------------------------------------------
//-- Minimise une boîte agrandie [-]  -----------------------------------
//-----------------------------------------------------------------------
function minimizeSdiCollapsable(collapsableContentDivId, minimizedTitleDivId, minimizedTitleSpanId, 
		                        expandedTitleSpanId, changeStatusUrl, customJs)
{	
	var oContentDiv = document.getElementById(collapsableContentDivId);
	if (oContentDiv.style.display=="none")
		return false; // Ne rien faire, déjà minimisé
	
	//-- Cacher contenu boîte ------------------
	oContentDiv.style.display="none";
	
	//-- Transférer titre ---------------------
	var oExpandedTitle = document.getElementById(expandedTitleSpanId);	
	var oMinimizedTitle = document.getElementById(minimizedTitleSpanId);
	oMinimizedTitle.innerHTML = oExpandedTitle.innerHTML;	
	oExpandedTitle.innerHTML = "";
	
	//-- Afficher titre minimisé -------------------
	document.getElementById(minimizedTitleDivId).style.display="";	
	
	//-- Enregistrer nouveau statut dans la session ----
	if (changeStatusUrl!=null && changeStatusUrl!='')
		createHiddenIFrame(changeStatusUrl);
		
	// Exécuter le code custom "onMinimize" si spécifié
	if (customJs!=null && customJs!="")
		eval(customJs);				

	return false; // Pour bloquer l'effet du href=""
}

//-------------------------------------------------------------------------
//-- Génère des sauts de page
//-------------------------------------------------------------------------
function insertPageBreaks(maxPrintableHeight)
{
	// Extraire toutes les tables avec id="noBreak_999" dans l'odre où elles apparaissent dans la page
	var aNoBreakElements = getElementsByIdStartingWith(document, "sdiNoBreakDiv_", "div", false);
	var posLastBreak=0;
	var oPreviousElement=null;	
	for (var i=0; aNoBreakElements!=null && i<aNoBreakElements.length; i++)
	{
		var oElement = aNoBreakElements[i];
		var elementTopDistance = getDistanceFromPageTop(oElement);
		var elementHeight = oElement.offsetHeight;
		//-- L'Élément EXCÈDE la page -------------------------
		
		if ((elementTopDistance + elementHeight) - posLastBreak > maxPrintableHeight)
		{
//			var remainingSpaceOnPage = maxPrintableHeight - (elementTopDistance-posLastBreak);
//			//-- Créer une image dans un Div pour combler les bas de la page (fuck up avec IE6) ---
//			var oDiv=document.createElement("div");			
//			var oImg=document.createElement("img");
//			oImg.src="images/pixel.gif";
//			oImg.height = 10;// remainingSpaceOnPage;
//			oImg.width = "30";
//			oDiv.appendChild(oImg);
//			oDiv.style.pageBreakAfter="always";			
//			// Insérer l'image dans le document	
//			oElement.parentNode.insertBefore(oDiv, oElement);
			
			if (oPreviousElement!=null)
				oPreviousElement.style.pageBreakAfter="always";

			posLastBreak = elementTopDistance;
		}
		//-- L'élément N'excède PAS la page --------------------
		else if (oPreviousElement!=null)
				oPreviousElement.style.pageBreakAfter="auto";

		oPreviousElement = oElement;
	}
}