// Layer file.

function showLayer(url, title, urlredirect, width, height) {
	var val = false;
	if(val) {
		// Creation d'un div prenant toute la largeur + hauteur de couleur noir légérement transparent pour griser le fond.
		var ombre = document.createElement("div");
		ombre.setAttribute("id", "shadow_layer");
		ombre.className = "ombre";

		// Création d'un div prenant toute la largeur + hauteur qui va accueillir le calque
		var div_conteneur = document.createElement("div");
		div_conteneur.setAttribute("id", "layer_container");
		div_conteneur.className = "layer";

		// Création de la fenêtre
		var div = document.createElement("div");
		div.setAttribute("id", "conteneur");
		div.className = "layer_container";
		// Redimensionnement
		/*if(width) {
			div.style.width = width+"px";//((width!="")?width:"0")+"px";
		}*/
		/*else {
			div.style.width = "auto";
		}*/
		//div.style.height = ((height!="")?height:"200")+"px";
		// Placement au centre de la page
		//div.style.margin = "-"+parseInt(((height!="")?height:"200"))/2+"px 0px 0px -"+parseInt(((width!="")?width:"400"))/2+"px";
		div.setAttribute("id", "layer_div");
		// Creation du header qui contiendra le titre + la croix pour fermer
		var header = document.createElement("div");
		//header.style.width = "100%";
		var link_close = document.createElement("a");
		//link_close.setAttribute("style", "float:right;");
		link_close.setAttribute("href", "javascript:closeLayer();");
		link_close.innerHTML = "<b></b>";
		link_close.align = "right";
		link_close.setAttribute("class", "close");
		if(document.all) {
		link_close.setAttribute("className", "close");
		}
		//link_close.style.clear = "all";
		header.appendChild(link_close);
		var input = document.createElement("input");
		input.type = "hidden";
		input.value = urlredirect;
		input.id = "id_calque";
		header.appendChild(input);
		// Création du div qui contiendra la page appelée en ajax
		var content = document.createElement("div");
		//content.style.width = "100%";
		content.setAttribute("id", "layer_content");
		content.className="layer_content";
		//content.style.height = ((height!="")?height:"300")+"px";
		//content.style.overflowY = "auto";
		content.setAttribute("style", "overflow-y: auto;");
		content.innerHTML = "Loading please wait";
		div.appendChild(header);
		div.appendChild(content);
		div_conteneur.appendChild(div);
		document.getElementsByTagName("body").item(0).appendChild(ombre);
		document.getElementsByTagName("body").item(0).appendChild(div_conteneur);
		document.body.style.overflow='hidden';
		new Ajax.Request(url, {
			method: 'get',
			onComplete: function(transport) {
				document.getElementById("layer_content").innerHTML = transport.responseText;
	    }
		});
	}
	return !val;
}

function closeLayer() {
	var redirect = document.getElementById("id_calque").value;
	document.getElementsByTagName("body").item(0).removeChild(document.getElementById("shadow_layer"));
	document.getElementsByTagName("body").item(0).removeChild(document.getElementById("layer_container"));
	document.getElementsByTagName("body").item(0).style.overflow='';
	if(redirect!="") {
		window.location = redirect;
	}
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + 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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}