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

	var yScroll;

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

	arrayPageScroll = new Array('',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;
		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;
}

// dimension et positionnement du faux popup
function sizePopup(opaque,popup) { 
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	// taille div opaque
	divO = document.getElementById(opaque);
	divO.style.height = (arrayPageSize[1] + 'px');
	opaqueWidth = divO.style.width;
	
	// taille div popup
	divP = document.getElementById(popup);	
	boxHeight = divP.style.height;
	boxWidth = divP.style.width;
	ch1 = parseFloat(arrayPageScroll[1]);
	ch2 = parseFloat(arrayPageSize[3]);
	ch3 = parseFloat(boxHeight);
	//ch4 = parseFloat(arrayPageSize[0]);
	ch4 = parseFloat(opaqueWidth);
	ch5 = parseFloat(boxWidth);
	ca1 = parseFloat(ch2 - 35 - ch3);
	ca2 = parseFloat(ca1 / 2);
	ca3 = parseFloat(ch1 + ca2);
	ca4 = parseFloat(ch4 - 20 - ch5);
	ca5 = parseFloat(ca4 / 2);
	divP.style.top = ca3 + 'px';
	divP.style.left = ca5 + 'px';
}

 
// cacher la popup
function cacherPopup(opaque,popup) { 
	document.getElementById(opaque).className='undisplay';
	document.getElementById(popup).className='undisplay';
}

// voir la popup
function voirPopup(opaque,popup) { 
	sizePopup(opaque,popup);
	document.getElementById(opaque).className='display';
	document.getElementById(popup).className='display';
}

// fermer popup
function fermerPopup(){
	document.getElementById("divPopup").innerHTML = "";
	document.getElementById("divPopup").className='undisplay';
}

// afficher une popup
function afficherPopup(url,page){
	
    var xhr=null;
	var adr=url+"popup/popup.php?page="+page;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { alert_affichage(xhr); };
    
    //on appelle le fichier reponse.txt
    xhr.open("GET", adr, true);
    xhr.send(null);
}
function alert_affichage(xhr)
{
    if (xhr.readyState==4)
    {
    	var docXML= xhr.responseXML;
    	var itemB = docXML.getElementsByTagName("bloc");
		bloc = itemB.item(0).firstChild.data;
		
		document.getElementById("divPopup").innerHTML = bloc;
		
		document.getElementById("divPopup").className='display';
		
		voirPopup("divOpaque","laPopup");
    }
}