// JavaScript Document
var nPopupId=0;
var aPopupDiv=new Array();
var aPilePopupDiv=new Array();
var oldPopupFirstPlan='';

function popupDiv(sId,sTitre,width,height,bscroll,sUrl,sParam){	
	var nBody=document.getElementsByTagName('body')[0];
	if(document.getElementById(sId)){	
		nBody.removeChild(getElem(sId));
		aPopupDiv.pop();
	} 
	aPopupDiv.push(sId);
	
	if(	getElem(oldPopupFirstPlan)){
		getElem(oldPopupFirstPlan).style.zIndex=900;
	}
	oldPopupFirstPlan=sId;
	var nPlan=aPopupDiv.length;		
	popup = document.createElement("div");
	popup.id=sId;
	popup.style.zIndex=1000;
	

	popup.style.position='absolute';	
	
	popup.style.width = (width+15)+'px';
	popup.style.height = (height+15)+'px';	 
	nBody.appendChild(popup);	
	popup.className="popup";	
	/*popup.style.marginLeft="-25px";
	popup.style.marginTop="-250px"; 
popup.style.left="50%";
		popup.style.top="50%"; 	*/
	popup.style.top=(Math.round((screen.height/2)-((height+200)/2))+(nPlan*30))+"px";
	popup.style.left=(Math.round((screen.width/2)-(width/2))+(nPlan*15))+"px";
	

			
	getElem(sId).innerHTML="<table id=\"tableauPopup"+sId+"\" style='height:"+(height+30)+"px' width='"+(width+20)+"px' cellpadding='0' cellspacing='0' border='0'>"
	+"<tr>"
		+"<td width='7' style='vertical-align:bottom' align='right'>"
			+"<img src='img/ombre-haut.png' class='png' width='7'/>"
			+"<img src='img/ombre-gauche.png' class='png' height='"+(height+62)+"' width='7' id=\"ombreleftPopup"+sId+"\"/>"
		+"</td>"
		+"<td  style='vertical-align:top'  align='left'><div class='popup'>"
			+"<div onclick=\"getElem(oldPopupFirstPlan).style.zIndex=900;getElem('"+sId+"').style.zIndex=1000;oldPopupFirstPlan='"+sId+"'\" id='headerPopup"+sId+"'			style='cursor:pointer;padding:5px;background-color:#000000;color:#ffffff;border:#ffffff 1px solid;'>"
			+"<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='20'></td>"
			+"<td><strong>"+sTitre+"</strong>&nbsp;</td>"
			+"<td width='25' align='right'>"
			+"<img src='img/reduce.gif' width='17' height='17' onclick=\"if(getElem('contentPopup"+sId+"').style.display!='none'){this.src='img/restore.gif';getElem('"+sId+"').style.height='25px';getElem('contentPopup"+sId+"').style.height='0px';getElem('contentPopup"+sId+"').style.display='none';getElem('ombreleftPopup"+sId+"').style.height='22px';getElem('tableauPopup"+sId+"').style.height='15px';}else{this.src='img/reduce.gif';getElem('contentPopup"+sId+"').style.display='block';getElem('ombreleftPopup"+sId+"').style.height='"+(height+62)+"px';getElem('tableauPopup"+sId+"').style.height='"+(height+30)+"px';getElem('contentPopup"+sId+"').style.height='"+height+"px';getElem('"+sId+"').style.height='"+(height+30)+"';}\"     style='cursor:pointer;' alt='' />"
			+"</td><td width='25' align='right'>"
			+"<img src='img/close.gif' width='17' height='17' onclick=\"closePopupDiv('"+sId+"');\"     style='cursor:pointer;' alt='' />"
			+"</td></tr></table>"
			+"</div>"
			+"<div id='contentPopup"+sId+"' style='background-color:#000000;opacity:0.8;border:1px #ffffff solid;filter:alpha(opacity=80);padding:20px;height:"+(height)+"px;overflow:auto;'>&nbsp;</div></div></td></tr>"
			+"<tr><td width='7' style='height:7px;vertical-align:top' align='right'><img src='img/ombre-angle.png' class='png' width='7' height='7'/></td><td><img src='img/ombre-bas.png' class='png'  height='7' width='"+width+"'/><img src='img/ombre-droite.png' class='png' height='7'/></td></tr>"
			+"</table><br /><br /><br />";				
		var frame=0;
		getElem(sId).style.display='none';
		chargeHTML('GET',sUrl,sParam,'contentPopup'+sId,false,'',function(){ getElem(sId).style.display='block';new Draggable($(sId),{handle:"headerPopup"+sId})});
		//new Draggable($(sId),{handle:"headerPopup"+sId,snap:[30,15]});
		//charge le contenu	
		//chargeHTML('GET',sUrl,sParam,'contentPopup'+sId,false,'',function(){
					
		/*new Effect.Appear(sId, {duration:1, fps:25, from:0.0, to:1.0,beforeStart:function(){getElem(sId).style.display='none'},afterUpdate:function(){frame++;if(frame==1){getElem(sId).style.display='block'}}});								 								  
		*/
		
	
	
	
}



function closePopupDiv(sId){
	var nBody=document.getElementsByTagName('body')[0];
	var found=0;
	
	if(aPopupDiv[(aPopupDiv.length-1)]==sId){
		for(var i=0;i<aPopupDiv.length;i++){
			if(aPopupDiv[i]==sId){
				found=1;
			}
			if(found==1){
				aPopupDiv[i]=aPopupDiv[(i-1)];
			}else{
				aPopupDiv[i]=aPopupDiv[i];
			}		
		}
			aPopupDiv.pop();
			
	} else {
		for(var i=0;i<aPopupDiv.length;i++){
			if(aPopupDiv[i]==sId){
				found=1;
				aPopupDiv[i]=-1;
			}
				
		}		
	}	
	
	while(aPopupDiv[(aPopupDiv.length-1)]==-1){
		aPopupDiv.pop();
	}
	
	nBody.removeChild(getElem(sId));
	var test;
	for(var i=0;i<aPopupDiv.length;i++){
			test+=aPopupDiv[i]+",";
				
	}		
	

}



