// JavaScript Document
//fonction de création de popup en calque div
// string url : url de la page a ouvrir en popup
// int width : largeur du contenu de la popup
// int height : hauteur du contenu de la popup
// string css : feuille de style de l'exterieur de la popup

var zIndexKmzPopupParam=5000;
var nNbOfPopupParam=0;
var nNbOfPopupOpenParam=0;
function kmzPopupContact(aParam){
	
	//setParam
	this._sId=aParam['id'];	 
	this._sUrl=aParam['url'];
	this._sUrl_distante=aParam['url_distante'];
	this._sParam=aParam['param'];
	this._nWidth=aParam['width'];
	this._nHeight=aParam['height'];		
	this._nTop=aParam['top'];
	this._nLeft=aParam['left'];
	this._TitleColor=aParam['titleColor'];
	this._bgTitleColor=aParam['bgTitleColor'];
	this._Title=aParam['title'];
	this._padding=aParam['padding'];
	this._nTailleOmbre=aParam['tailleOmbre'];
	this._bAllowDuplicate=aParam['allowDuplicate'];
	this._sHtml=aParam['HTML'];
	this._bLock=aParam['lock'];
	this._sParent=aParam['parent'];
	this._sIcone=aParam['icone'];
	this._onLoad=aParam['onLoad'];
	 //valeur par defaut 
	 if(!this._sId)this._sId='_Popup_';	 
	if(!this._sUrl && !this._sHtml)this._sHtml="Chargement ...";
	if(!this._TitleColor)this._TitleColor='#ffffff';
	if(!this._bgTitleColor)this._bgTitleColor='#1b3f69';
	if(!this._Title)this._Title='Fen&ecirc;tre';
	 if(!this._padding)this._padding=15;
	if(!this._nTailleOmbre)this._nTailleOmbre=10;

	
	
	nNbOfPopupOpenParam++;
	
		//duplication
	if(this._bAllowDuplicate){
			nNbOfPopupParam++;
			this._sId=this._sId+nNbOfPopupParam;
	}
	
	
	//construction HTML modifiable
	var sHTMLBtnClose='<img src="img/close.gif" width="17" height="17" onclick="kmzClosePopupContact({id:\''+this._sId+'\'});" style="cursor:pointer;">';
	
	var sHTMLBtnReduce='&nbsp;';
	if(!this._bLock){
	var sHTMLBtnReduce='<img src="img/reduce.gif" width="17" height="17" onclick="kmzReducePopupContact({id:\''+this._sId+'\'});" style="cursor:pointer;">';
	}
	
	var sStyleDrag="";
	if(!this._bLock){
		sStyleDrag="cursor:pointer";
	}
	

	var sHTMLHeader=""
	if(this._sIcone){			
	sHTMLHeader='<div style="background-image:url(\'img/fd-titre-popup.jpg\');background-color:'+this._bgTitleColor+';width:'+(this._nWidth+(this._padding*2)+2)+'px"><table cellpadding="0" cellspacing="0" border="0" style="height:30px;" width="'+(this._nWidth+(this._padding*2)+2)+'"><tr><td width="'+this._padding+'" style="padding:2px;padding-left:5px;"><img src="'+this._sIcone+'" ></td><td  valign="middle"><div style="font-weight:bold;color:'+this._TitleColor+';'+sStyleDrag+';width:100%";"  >&nbsp;&nbsp;'+this._Title+'</div></td><td  width="50" align="right">'+sHTMLBtnReduce+'&nbsp;'+sHTMLBtnClose+'</td><td width="5">&nbsp;</td></tr></table></div>';
	}else{
		sHTMLHeader='<div style="background-image:url(\'img/fd-titre-popup.jpg\');background-color:'+this._bgTitleColor+';width:'+(this._nWidth+(this._padding*2)+2)+'px"><table cellpadding="0" cellspacing="0" border="0" style="height:30px;" width="'+(this._nWidth+(this._padding*2)+2)+'"><tr><td width="'+this._padding+'">&nbsp;</td><td  valign="middle"><div style="font-weight:bold;color:'+this._TitleColor+';'+sStyleDrag+';width:100%";"  >'+this._Title+'</div></td><td  width="50" align="right">'+sHTMLBtnReduce+'&nbsp;'+sHTMLBtnClose+'</td><td width="5">&nbsp;</td></tr></table></div>';
	}
	
	var sHTMLBody='<div id="'+this._sId+'DivContent"><table cellpadding="0" cellspacing="0" border="0" style=";background-repeat:repeat-x;background-color:#4c5b74;height:'+this._nHeight+'px;border-right:1px solid #dddddd;border-left:1px solid #dddddd;border-bottom:1px solid #dddddd;" width="'+(this._nWidth+(this._padding*2)+2)+'"><tr><td width="'+this._padding+'">&nbsp;</td><td  width="'+(this._nWidth)+'" valign="top"><div style="display:block;overflow:auto;height:'+this._nHeight+'px;width:'+(this._nWidth+this._padding)+';" id="'+this._sId+'PopupContentHtml">&nbsp;Chargement en cours</div></td></td></tr></table></div>';
	
	
	
	var eBody=document.getElementsByTagName('body')[0];
	
	if(!document.getElementById('rootKMZPopup')){
		var eParentRoot = document.createElement("div");
		eParentRoot.id='rootKMZPopup';	
		eBody.appendChild(eParentRoot);
	}
	
	if(this._sParent){
		var eParent=$(this._sParent+"DivDragNDrop");
	}else{	
		var eParent=document.getElementById('rootKMZPopup');
	}
	
		
	

	
	if(!document.getElementById(this._sId+"DivParent")){
			new Insertion.After(eParent,"<div id=\""+this._sId+"DivParent\" >&nbsp;</div>");
		}else{
			nNbOfPopupOpenParam--;
		}
	
	
		
	var sPopup='<span id="'+this._sId+'DivDragNDrop" style="'+sStyleDrag+';marign-top:0px;">'+sHTMLHeader+'</span>'+sHTMLBody;
	
	//on applique l'effet d'ombre
	$(this._sId+"DivParent").innerHTML='<table cellpadding="0" border="0" cellspacing="0">'
	+'<tr><td><img src="img/shadowTopPopupAngleLeft.png" width="'+this._nTailleOmbre+'" height="'+this._nTailleOmbre+'" class="png"/></td><td><img src="img/shadowTopPopup.png" width="'+(this._nWidth+(this._padding*2)+2)+'" height="'+this._nTailleOmbre+'" class="png"/></td><td><img src="img/shadowTopPopupAngleRight.png" width="'+this._nTailleOmbre+'" height="'+this._nTailleOmbre+'" class="png"/></td></tr>'
	+'<tr><td><img  id="'+this._sId+'imgOmbreLeft" src="img/shadowLeftPopup.png" height="'+(this._nHeight+(this._padding*1)+2+14)+'" width="'+this._nTailleOmbre+'" class="png"/></td><td style="vertical-align:top">'+sPopup+'</td><td><img id="'+this._sId+'imgOmbreRight" src="img/shadowRightPopup.png" height="'+(this._nHeight+(this._padding*1)+2+14)+'" width="'+this._nTailleOmbre+'" class="png"/></td></tr>'
	+'<tr><td ><img src="img/shadowBottomPopupAngleLeft.png" width="'+this._nTailleOmbre+'" height="'+this._nTailleOmbre+'" class="png"/></td><td ><img src="img/shadowBottomPopup.png" width="'+(this._nWidth+(this._padding*2)+2)+'" height="'+this._nTailleOmbre+'" class="png"/></td><td style="height:'+this._nTailleOmbre+'px;"><img src="img/shadowBottomPopupAngleRight.png" width="'+this._nTailleOmbre+'" height="'+this._nTailleOmbre+'" class="png"/></td></tr></table>';

	

	
	if(!this._bLock){
			new Draggable($(this._sId+"DivParent"),{handle:this._sId+"DivDragNDrop",snap:[30,15],starteffect:function(element){zIndexKmzPopupParam++;
																										  element.style.zIndex=zIndexKmzPopupParam;},endeffect:function(element){
															
															zIndexKmzPopupParam++;
																										  element.style.zIndex=zIndexKmzPopupParam;
																										  var sTop=element.style.top;var nTop=parseInt(sTop.replace('px',''));	
																										  if(nTop<10){
																											  element.style.top="10px";
																										  }
																										  
																										 /* var sLeft=element.style.left;var nLeft=parseInt(sLeft.replace('px',''));	
																										  if(nLeft<10){
																											  element.style.left="10px";
																										  }*/
																										  }});
	
	}
	var aPos=Position.realOffset(document.body);
	
	zIndexKmzPopupParam++;
	
	$(this._sId+"DivParent").style.zIndex=zIndexKmzPopupParam;
	$(this._sId+"DivParent").style.position='absolute';
	 if (window.innerWidth || window.innerHeight){ 
		docwidth = window.innerWidth; 
		docheight = window.innerHeight; 
	} 
		//IE Mozilla 
	if (document.body.clientWidth || document.body.clientHeight){ 
		docwidth = document.body.clientWidth; 
		docheight = document.body.clientHeight; 
	} 

	if(!this._sParent){		
		$(this._sId+"DivParent").style.top=(aPos[1]+(25*nNbOfPopupOpenParam))+'px';
	
		$(this._sId+"DivParent").style.left=(aPos[0]+((docwidth/2)-(this._nWidth/2))+25*nNbOfPopupOpenParam)+'px';

	}
	if(this._nLeft){
		$(this._sId+"DivParent").style.left=(this._nLeft)+'px';		
	}
	if(this._nTop){
		$(this._sId+"DivParent").style.top=(this._nTop)+'px';
	}
	
	$(this._sId+"DivParent").style.verticalAlign='top';
	
	if(this._sUrl){		
	
	var ajax=new Ajax.Request(
							  	this._sUrl,
								{ 	asynchronous:true ,
									method:'get',
									parameters:this._sParam,
									onSuccess:	function(t){	
													var sChaine=t.responseText;														
													$(this._sId+'PopupContentHtml').innerHTML=sChaine+"";
													//$(this._sId+'PopupContentHtml').style.overflow='visible';
														if(typeof this._onLoad == 'function'){
															var func=this._onLoad;												
															func();
														}
													
												}
								}								
							);
	}
	if(this._sHtml){
		$(this._sId+'PopupContentHtml').innerHTML=this._sHtml;
	}
	if(	this._sUrl_distante){
		$(this._sId+'PopupContentHtml').innerHTML='<iframe frameborder="0" src="'+this._sUrl_distante+'" width="'+this._nWidth+'" height="'+this._nHeight+'"  />';
	}
	

	
}


// JavaScript Document
//fonction de fermeture de popup en calque div
// string id : id de la popup


function kmzClosePopupContact(aParam){	
	//setParam

	this._sId=aParam['id'];
	$(this._sId+"DivParent").remove();
	nNbOfPopupOpenParam--;	
}

function kmzReducePopupContact(aParam){	
	//setParam
	this._sId=aParam['id'];
	if($(this._sId+"DivContent").style.display=='none'){
		$(this._sId+"DivContent").style.display='block';
		var sHauteur=$(this._sId+'PopupContentHtml').style.height;
		nHeight=parseInt(sHauteur.replace('px',''));		
		$(this._sId+"imgOmbreLeft").height=nHeight+30+15+1;
		$(this._sId+"imgOmbreRight").height=nHeight+30+15+1;
	}else{
		$(this._sId+"DivContent").style.display='none';
		$(this._sId+"imgOmbreLeft").height=30;
		$(this._sId+"imgOmbreRight").height=30;
	}	
}



