// JavaScript Document
var nPopupId=0;
var aPopupDiv=new Array();
var aPilePopupDiv=new Array();
var oldPopupFirstPlan='';
var rand_popupdiv;
var nPopupFirstPlan=1000;
var popupLock='';
function popupDiv(sId,sTitre,width,height,bscroll,sUrl,sParam,onLoad,top,left,BGcolor,TitleColor,parent,hideReduce,hideClose,lock){
	
	var rand=Math.round(Math.random()*100000);	
	 rand_popupdiv=rand;
	if(!parent){
		var nBody=document.getElementsByTagName('body')[0];
		if(document.getElementById(sId)){	
			nBody.removeChild($(sId));
			aPopupDiv.pop();
		} 
		aPopupDiv.push(sId);
		sParent=false;
	}else{		
		if(!document.getElementById("parentPop"+sId)){	
			new Insertion.After(parent,"<span id=\"parentPop"+sId+"\"></span>");
		}
		var nBody=document.getElementById("parentPop"+sId);	
		
		if(document.getElementById(sId)){	
			nBody.removeChild($(sId));
			aPopupDiv.pop();
		} 
		aPopupDiv.push(sId);
		sParent="'parentPop"+sId+"'";
	}
	

	if(oldPopupFirstPlan){
	if(	$(oldPopupFirstPlan)){
		$(oldPopupFirstPlan).style.zIndex=900;
	}
	}
	oldPopupFirstPlan=sId;
	var nPlan=aPopupDiv.length;		
	popup = document.createElement("div");
	popup.id=sId;	
	popup.style.zIndex=nPopupFirstPlan;	
	popup.style.position='absolute';	
	


	 
	nBody.appendChild(popup);	
	//popup.className="popup";	
	if(!lock){
		if(top==''){
			top=30;
		}
		popup.style.top=(top+(nPlan*30))+"px";
		if(left==''){
			popup.style.left=(Math.round((screen.width/2)-(width/2))+(nPlan*15))+"px";
		}else{
			popup.style.left=left+"px";
		}
	}else{
		popup.style.marginTop="-"+((height+30)/2)+"px";
		popup.style.marginLeft=-(width+30)/2;
	}
	if(BGcolor==''){
		BGcolor='#264168';
	}
	if(TitleColor==''){
		TitleColor='#ffffff';
	}
	var sHeader="";
	if(BGcolor.indexOf('.')==-1){
		sHeaderFd="background-color:"+BGcolor+";background-image:url(\'img/bgTitlePopupv2.png\');";
	}else{
		sHeaderFd="background-image:url('"+BGcolor+"');";
	} 
	
	var sHTMLBtnReduce='<img src="img/reduce.gif" width="17" height="17" onclick="if($(\'contentPopup'+sId+'\').style.display==\'block\'){$(\'tableauPopup'+sId+'\').style.height=\'30px\';$(\'contentPopup'+sId+'\').style.display=\'none\';this.src=\'img/restore.gif\';$(\'ombreleftPopup'+sId+'\').style.height=\'25px\';}else{$(\'contentPopup'+sId+'\').style.display=\'block\';this.src=\'img/reduce.gif\';$(\'ombreleftPopup'+sId+'\').style.height=\''+(height+55)+'px\';}" style="cursor:pointer;">';
	
	
	
	var sHTMLBtnClose='<img src="img/close.gif" width="17" height="17" onclick="closePopupDiv(\''+sId+'\','+sParent+');" style="cursor:pointer;">';
	var sHTMLBtn="";
	if(!hideReduce){
		sHTMLBtn=sHTMLBtn+sHTMLBtnReduce
	}
	if(!hideClose){
		sHTMLBtn=sHTMLBtn+'&nbsp;&nbsp;&nbsp;'+sHTMLBtnClose;	
	}	
	
	
	if(!lock){
	
	var sHTMLHeader='<table cellpadding="0" cellspacing="0" border="0" style="'+sHeaderFd+';height:30px;" width="'+(width+30)+'"><tr><td width="15">&nbsp;</td><td  valign="middle"><div id="dragPopup'+sId+'" style="font-weight:bold;color:'+TitleColor+';cursor:pointer;width:100%";" onmousedown="nPopupFirstPlan++;;$(\''+sId+'\').style.zIndex=nPopupFirstPlan" >'+sTitre+'</div></td><td  width="50" align="right">'+sHTMLBtn+'</td><td width="5">&nbsp;</td></tr></table>';
	var sHTMLBody="";
	
	//ombres
	var sHTMLLeft="<img src='img/ombre-gauche.png' class='png' height='"+(height+55)+"' width='7' id=\"ombreleftPopup"+sId+"\"/>";
	var sHTMLBottom="<img src='img/ombre-bas.png' class='png' height='7' width='"+(width+25)+"' id=\"ombrebasPopup"+sId+"\"/>";
	
	var sHTMLPopup='<table cellpadding="0" cellspacing="0" border="0" id="tableauPopup'+sId+'" style="height:'+(height+30+15+15+2)+'px;" width="'+width+'" >';
		sHTMLPopup+='<tr>';
		sHTMLPopup+='<td valign="bottom" width="7">'+sHTMLLeft+'</td>'
		sHTMLPopup+='<td valign="top">'
		sHTMLPopup+='	<table cellpadding="0" cellspacing="0" border="0">'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td style="border-right:1px solid #dddddd;border-left:1px solid #dddddd;border-top:1px solid #dddddd;border-bottom:1px solid #dddddd;">'+sHTMLHeader+'</td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td valign="top"><div id="contentPopup'+sId+'" style="display:block;background-image:url(\'img/fdpopup.gif\');background-repeat:repeat-x;padding:15px;background-color:#ffffff;height:'+height+'px;width:'+width+'px;overflow:auto;border-right:1px solid #dddddd;border-left:1px solid #dddddd;border-bottom:1px solid #dddddd;">'+sHTMLBody+'</div></td>'
		sHTMLPopup+='	</tr>'	
		sHTMLPopup+='	</table>'
		sHTMLPopup+='	<td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td style="height:7px;"><img src="img/ombre-angle.png" class="png" width="7" height="7" /></td>'
		sHTMLPopup+='		<td style="height:7px;">'+sHTMLBottom+'</td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='</table>';
	}else{
		
			var sHTMLHeader='<table cellpadding="0" cellspacing="0" width="100%" border="0" style="height:23px;" width="'+(width+30)+'"><tr><td  valign="middle" width="50"></td><td   align="right" valign="middle">'+sHTMLBtn+'</td><td width="3"></td></tr></table>';
	var sHTMLBody="";
	
	//ombres
	var sHTMLLeft="<img src='img/ombre-gauche.png' class='png' height='"+(height+55)+"' width='7' id=\"ombreleftPopup"+sId+"\"/>";
	var sHTMLBottom="<img src='img/ombre-bas.png' class='png' height='7' width='"+(width+25)+"' id=\"ombrebasPopup"+sId+"\"/>";
	
	var sHTMLPopup='<table cellpadding="0" cellspacing="0" border="0" id="tableauPopup'+sId+'" style="height:'+(height+23+3+3)+'px;" width="'+width+'" >';
		sHTMLPopup+='<tr>';
		sHTMLPopup+='<td valign="bottom" width="7">'+sHTMLLeft+'</td>'
		sHTMLPopup+='<td valign="top" style="background-image:url(\'img/fdpopup.gif\');background-repeat:repeat-x;">'
		sHTMLPopup+='	<table cellpadding="0" cellspacing="0" border="0">'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td style="border-right:1px solid #dddddd;border-left:1px solid #dddddd;border-top:1px solid #dddddd;border-bottom:1px solid #dddddd;">'+sHTMLHeader+'</td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td valign="top" ><div id="contentPopup'+sId+'"  style="display:block;padding-left:3px;padding-right:3px;padding-bottom:3px;height:'+(height+29)+'px;width:'+(width+25)+'px;overflow:auto;border-right:1px solid #dddddd;border-left:1px solid #dddddd;border-bottom:1px solid #dddddd;">'+sHTMLBody+'</div></td>'
		sHTMLPopup+='	</tr>'	
		sHTMLPopup+='	</table>'
		sHTMLPopup+='	<td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='	<tr>'
		sHTMLPopup+='		<td style="height:7px;"><img src="img/ombre-angle.png" class="png" width="7" height="7" /></td>'
		sHTMLPopup+='		<td style="height:7px;">'+sHTMLBottom+'</td>'
		sHTMLPopup+='	</tr>'
		sHTMLPopup+='</table>';
		
		
	}
		
		

		$(sId).innerHTML=	sHTMLPopup;	
		var frame=0;
		$("contentPopup"+sId).innerHTML='Chargement, veuillez patienter ...';
		$(sId).style.display='none';
		$(sId).style.display='block';
		if(bscroll){
			$("contentPopup"+sId).style.overflow='auto';
		}else{
			$("contentPopup"+sId).style.overflow='hidden';
		}
		
//	onTest=function(){
		
	//}
	var ajax=new Ajax.Request(
							  	sUrl,
								{ 	asynchronous:true ,
									method:'GET',
									parameters:sParam,
									onSuccess:	function(t){
										
													$('contentPopup'+sId).innerHTML=t.responseText+'';
													var func=onLoad;												
													func();
												}
								}								
							);	
		//chargeHTML('GET',sUrl,sParam,'contentPopup'+sId,false,'',onLoad);
	
		
		if(!lock){
			new Draggable($(sId),{handle:"dragPopup"+sId,snap:[30,15]});
	}else{		
		/*grise = document.createElement("div");	
		grise.id="popupdiv_noclick"+rand;
		grise.style.position='absolute';
		//grise.style.backgroundImage="url('modules/popup/blank.gif')";
		grise.style.backgroundColor="#ffffff";			
		grise.style.height = '100px';	
		grise.style.width = '100px';	
		nBodyGrise=document.getElementsByTagName('body')[0];		
		nBodyGrise.appendChild(grise);
		popupLock=sId;
		grise.style.zIndex=popup.style.zIndex-1;
		
		if (document.layers) document.captureEvents(Event.MOUSEMOVE); 
		if (document.layers || document.all) document.onmousemove = popupdiv_mousemove; 
		if (document.addEventListener) document.addEventListener('mousemove', popupdiv_mousemove, true); */
		
	}		
		
	
	
	
}



function closePopupDiv(sId,parent){
	if(!parent){
		var nBody=document.getElementsByTagName('body')[0];
	}else{
		var nBody=document.getElementById(parent);
	}
	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($(sId));
	var test;
	for(var i=0;i<aPopupDiv.length;i++){
			test+=aPopupDiv[i]+",";
				
	}		
	

}

function popupdiv_mousemove(evt){
var element=document.getElementById("popupdiv_noclick"+rand_popupdiv);
	if (document.layers) { 
		x=evt.x; 
		y=evt.y; 
	} 
	if (document.all) { 
	x=event.clientX; 
	y=event.clientY; 
	} else { 
		if (document.getElementById) { 
			x=evt.clientX;
			y=evt.clientY; 
		}
	}
	element.style.left = (x-50)+"px" ; 
	element.style.top  =(y-25)+"px" ;
	
	
}

function popupdiv_getLeft(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord gauche de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else 
        return (MyObject.offsetLeft);
    } 
function popupdiv_getTop(MyObject)
//Fonction permettant de connaître la position d'un objet
//par rapport au bord haut de la page.
//Cet objet peut être à l'intérieur d'un autre objet.
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }




