//------------------------------------------------------------------------------------//
// PROGRAMME : ajax_afficher_div_popup.js
// DEscriptION : Afficher une requete ajax type lightbox
// HISTORIQUE DES VERSIONS :
// V1.0 - 03/10/2008 - Mickaël - Création du programme
//------------------------------------------------------------------------------------//

//Fonction JS

// FONCTION : centerPopup(element)
// DESCRIPTION : centre dans la fenetre l'element
// PARAMETRE EN ENTREE :
// element : nom du div
function centerPopup(element) {
	 var height=document.getElementById(element).offsetHeight; //hauteur de l'élément à positionner
	 var width=document.getElementById(element).offsetWidth; //largeur de l'élément à positionner
	 myParent=document.getElementById(element).parentNode;
	 var pHeight=myParent.offsetHeight; //Hauteur de l'élément parent
	 var pWidth=myParent.offsetWidth; //Largeur de l'élément parent
	 var sTop = document.documentElement.scrollTop;
	// var sLeft=myParent.scrollLeft;//Longueur de défilement de l'élément parent
	 var largsite = 1000;
	 // ma façon, celle qui fonctionne le moins mal ...
	 var posY=sTop+75;
	 var posX=(pWidth/2)-(width/2);

	 // vrai calcul
	// var posY=(pHeight/2)-(height)+sTop;//Calcul de la position en Y
	 //var posX=(pWidth/3)-(width)+sLeft;//Calcul de la position en X
	 document.getElementById(element).style.top=posY+"px";
	 document.getElementById(element).style.left=posX+"px";
	 //document.getElementById(element).style.display= "block";
	 return true;
}

function hauteur_page(){
	document.getElementById('div_de_trans').style.height = parseInt(document.documentElement.scrollHeight)+"px";
}

function transparaitre(p,sens,id_div){
	var div_trans=document.getElementById("div_de_trans");
	var div_affiche=document.getElementById(id_div);
	if(sens=="moins"){
		div_trans.className="div_trans_transparence_"+p;
		if(p!=0){
			window.setTimeout("transparaitre("+(p-1)+",\"moins\",'"+id_div+"')",30);
		}else{
			div_trans.style.display="none";
		}
	}
	if(sens=="plus"){
		div_trans.className="div_trans_transparence_"+p;
		if(p!=9){
			window.setTimeout("transparaitre("+(p+1)+",\"plus\",'"+id_div+"')",30);
		}else{
			centerPopup(id_div);
			div_affiche.style.display="block";
		}
	}
}

function affiche_div_trans(id_div){
	hauteur_page();
	var div_trans=document.getElementById("div_de_trans");
	var div_affiche=document.getElementById(id_div);
	if(div_trans.style.display=="none"){
		div_trans.style.display="block";
		transparaitre(3,"plus",id_div);
	}else{
		div_affiche.style.display="none";
		transparaitre(9,"moins",id_div);
	}
}

function affiche_div(id_div){
	affiche_div_trans(id_div);
}
