// Surveillance de l'emplacement des divs pour les recentrer en cas de scroll de la page parente.

TLList = ''; // Variable globale - Liste des ToolLayers ouverts dans la page

//Ajout d'un ToolLayer à la liste
function addToTLList(TLID){
	TLList += '##' + TLID;
}
// Suppression d'un ToolLayer de la liste
function deleteFromTLList(TLID){
	TLList = TLList.replace('##' + TLID, '');
}
// Recentrage des ToolLayers dans l'espace affiché de la page (varie en fonction du scrolling)
function RecenterToolLayer(){
	var s = '';
	var liste = TLList.split("##");
	for(i in liste){
		if(liste[i] != ''){
			tempTL = document.getElementById(liste[i]);
			if(tempTL){
				var tempTLHeight = tempTL.style.height; //renvoit une chaine finie par 'px' -> à supprimer
				tempTLHeight = tempTLHeight.substring(0, tempTLHeight.length -2);  //suppression de la chaine px
				if (navigator.appName == "Microsoft Internet Explorer"){
					tempTL.style.top = document.body.scrollTop + (tempTLHeight / 2);
				}
				else{
					tempTL.style.top = window.pageYOffset + (tempTLHeight / 2);
				}
			}
		}
	}
	setTimeout('RecenterToolLayer()', 100);
}
RecenterToolLayer();


function ShowToolLayer(TLID){
	TL = document.getElementById(TLID);
	if(TL){
		TL.style.zIndex = 2;
		TL.style.visibility = 'visible';
		TL.style.display = 'block';
	}
}

function HideToolLayer(TLID){
	TL = document.getElementById(TLID);
	if(TL){
		TL.style.zIndex = 0;
		TL.style.visibility = 'hidden';
		TL.style.display = 'none';
	}
	deleteFromTLList(TLID);
}

function ToolLayer(TLID, TLHeight, TLWidth, TLTitle, HeaderHeight, FooterHeight, ContentURL){
	//this._visibilityConfig = 'display:none; z-index:0; visibility: hidden; '; 
	//display:block; z-index:1; visibility: visible; 
	
	var TL = document.getElementById(TLID);
	if(!TL){
		var posY;
		var posX;
		if (navigator.appName == "Microsoft Internet Explorer"){
			posY = document.body.scrollTop + (TLHeight / 2); //(screen.availHeight - TLHeight) / 2
			posX = (screen.availWidth - TLWidth) / 2; //document.body.scrollLeft + (TLWidth / 2);
		}
		else{
			posY = (window.pageYOffset - TLHeight) / 2;
			posX = (screen.availWidth - TLWidth) / 2; // (window.pageXOffset - TLWidth) / 2;
		}
		var TLDebut = '<div '
				+ 'id="' + TLID + '" '
				+ 'style="'
				+ 'border:3px solid #001C5B;'
				+ 'position:absolute; z-index:0; visibility:hidden; display:none; padding:0px; overflow:hidden;'
				+ 'top:' + posY + 'px; left:' + posX + 'px; '
				+ 'height:' + TLHeight + 'px; width:' + TLWidth + 'px;'
				+ '">';
		var TLHeader = '<table border="0" cellspacing="0" cellpadding="0" class="bgBleuFonce" '
				 + 'style="width:100%; height:' + HeaderHeight + 'px; border-bottom:2px solid #FFFFFF;">'
					+ '<tr>'
						+ '<td align="left" valign="middle" class="bgBleuFonce" style="padding:5px; height:' + HeaderHeight + 'px;">'
							+ '<b>' + TLTitle + '</b>'
						+ '</td>'
						+ '<td align="right" valign="top" class="bgBleuFonce" style="padding:5px; height:' + HeaderHeight + 'px;">'
							+ '<a href="javascript:HideToolLayer(\'' + TLID + '\');" style="background-color:none;"><img src="images/btFermer.gif" width="16" height="16" border="0" style="background-color:none;" /></a>'
						+ '</td>'
					+ '</tr>'
				+ '</table>';
	var TLContent = '<iframe scrolling="auto" frameborder="0" src="' + ContentURL + '" class="bgF0F0F0" '
				  + 'style="width:100%; height:' + (TLHeight - HeaderHeight - FooterHeight) + 'px;"></iframe>';
	var TLFooter = '<table border="0" cellspacing="0" cellpadding="0" class="bg5E73B0" style="width:100%; height:'+ FooterHeight + 'px; border-top:2px solid #FFFFFF;">'
					+ '<tr>'
						+ '<td class="bgBleuFonce" style="height:'+ FooterHeight + 'px;">&nbsp;</td>'
					+ '</tr>'
				+ '</table>';
	var TLFin = '</div>';
	document.body.innerHTML += (TLDebut + TLHeader + TLContent + TLFooter + TLFin);
	addToTLList(TLID); // Ajout de la nouvelle ToolLayer à la liste
	}
	ShowToolLayer(TLID);
}

