// JavaScript Document
function DisplayDivPopup(sUrl)
{	
	var XHR = null;
	var ctlDivPopup = document.getElementById("DIV_Popup");
	
	sUrl += "&refreshParam=" + new Date().getTime();
	
	if(window.XMLHttpRequest) // Firefox
		XHR = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		XHR = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	
	// envoie de la requête, methode GET et de l'url
	XHR.open("GET", sUrl, true);

	// on guette les changements d'état de l'objet
	XHR.onreadystatechange = function() {

		// l'état est à 4, requête reçu !
		if(XHR.readyState == 4 && XHR.status == 200)  
		{
			// ecriture de la réponse
			ctlDivPopup.innerHTML = XHR.responseText;
			setTimeout("ShowDivPopup(true)", 100);
   		}
	}
		
	XHR.send(null);
		
	return true;	
}

function ShowDivOverlay(bVisible)
{
	var ctlDivOverlay = document.getElementById("DIV_Overlay");
	
	var arrayPageSize = getPageSize();
	
	if(bVisible)
		ctlDivOverlay.style.display = "block";
	else
		ctlDivOverlay.style.display = "none";
			
	//ctlDivOverlay.style.height = arrayPageSize[1] + 'px';
	//ctlDivOverlay.style.width = arrayPageSize[0] + 'px';
}

function ShowDivPopup(bVisible)
{
	var ctlDivPopup = document.getElementById("DIV_Popup");
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	ShowDivOverlay(bVisible);
	
	if(bVisible)
	{
		ctlDivPopup.style.display = "block";
	}
	else
	{
		ctlDivPopup.style.display = "none";
	}
	
	ctlDivPopup.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - ctlDivPopup.offsetHeight) / 2 ) + 'px');
	ctlDivPopup.style.left = (((arrayPageSize[0] - 20 - ctlDivPopup.offsetWidth) / 2) + 'px');	
	
	return true;	
}

function ClosePopup()
{
	var ctlDivPopup = document.getElementById("DIV_Popup");
	var ctlDivOverlay = document.getElementById("DIV_Overlay");
		
	ctlDivPopup.style.display = "none";
	
	ctlDivOverlay.style.display = "none";
	
	return true;
}	


// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		xScroll = self.pageXOffset;
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array(xScroll,yScroll);
	
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	
	return arrayPageSize;
}

