// Layer file.



function showLayer(url, titre, width, height, module) {



	// 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";

	if(!module){

  	// 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.setAttribute("id", "header_up");

  	var title = document.createElement("div");

  	title.className="je_participe";

  	title.innerHTML = titre; //a modifier en php ############################################

  	header.appendChild(title);

  	

  	

  	//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 = '<img border="0" src="img/btn_fermerupload_off.gif" onmouseover="this.src=\'img/btn_fermerupload_on.gif\'" onmouseout="this.src=\'img/btn_fermerupload_off.gif\'" />';

  	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 = module;

  	input.id = "id_module_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;");

  	var loading_txt = document.createElement("div");

  	loading_txt.className = "loading_txt"

  	loading_txt.innerHTML = "Loading, please wait...";

  	content.appendChild(loading_txt);



    var footer = document.createElement("div");

    footer.setAttribute("id", "footer_up");

  }else{

    var div=document.createElement("div");

    div.setAttribute("id", "div_pic");

    

    var div_conteneur=document.createElement("div");

    div_conteneur.setAttribute("id", "container_pic");

    

    var header=document.createElement("div");

    header.setAttribute("id", "header_pic");

    

    var content=document.createElement("div");

    content.setAttribute("id", "layer_content");

    

    var footer=document.createElement("div");

    footer.setAttribute("id", "footer_pic");

  }

	

	div.appendChild(header);

	div.appendChild(content);

	div.appendChild(footer);

	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.Updater( "layer_content",url, {

		method: 'get',
		evalScripts:true

		

	});

}



function closeLayer(bool) {

	document.getElementsByTagName("body").item(0).removeChild(document.getElementById("shadow_layer"));

	if(!bool){

	 document.getElementsByTagName("body").item(0).removeChild(document.getElementById("layer_container"));

	}else{

   document.getElementsByTagName("body").item(0).removeChild(document.getElementById("container_pic"));

  }

	document.getElementsByTagName("body").item(0).style.overflow='';

}



function refreshLayer(url) {

  new Ajax.Request(url, {

		method: 'get',

		onComplete: function(transport) {

			document.getElementById("layer_content").innerHTML = transport.responseText;

    }

	});

}



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;

}
