﻿
/***********************/
/****** POPUPS *********/
/***********************/
function PLAlert(stringMssg,NoEscap,title){
	if(!title || title=="")title='Attention'
	if(PLpopUp('small',title,stringMssg,NoEscap)){
		if(!NoEscap){
			PLg("ThePopUpDivContent").innerHTML='<table width="100%" cellpadding="0" cellspacing="20" border="0" width="100%"><tr><td width="25%">&nbsp;</td><td width="50%" id="OkButtonTd"></td><td width="25%">&nbsp;</td></tr></table>'
			AddButton('OkButtonTd',true,null,'Ok','buttonsB','PLpopUpClose()')
		}
	}
}

function PLpopUpWait(Mssg,subMssg){
	if(PLpopUp('small',Mssg,subMssg,true,true)){
		removeGlobalEvent(document,"keydown",PLpopUpEscapeClose)
		CreateProgressBarre('ThePopUpDivContent',20)
	}
	//if(PLg("PLpopUpCloseButton"))PLg("PLpopUpCloseButton").innerHTML=""
	//if(PLg("PLpopUpTitle"))PLg("PLpopUpTitle").innerHTML = Mssg
	//if(PLg("PLpopUpSubTitle"))PLg("PLpopUpSubTitle").innerHTML = subMssg
	//PLpopUpAddShade(PLg("ThePopUpDiv"))
}

var _progresseBarreTimer
var SquareContainer
function CreateProgressBarre(target,nbSquares,occurence){
	if(occurence==null){
		if(typeof _progresseBarreTimer=='number')clearTimeout(_progresseBarreTimer)
		SquareContainer = null;
		SquareContainer = document.createElement("DIV")
		if(isIE){
			SquareContainer.style.height = 21;
			SquareContainer.style.width = parseInt(19*nbSquares,10)+4;
		}
		else{
			SquareContainer.style.height = 19;
			SquareContainer.style.width = parseInt(19*nbSquares,10)+2;
		}
		SquareContainer.style.position='relative'
		SquareContainer.style.border='1px solid black'
		PLg(target).innerHTML=""
		PLg(target).style.textAlign='center'
		PLg(target).appendChild(SquareContainer)
		occurence=0
	}
	
	SquareContainer.innerHTML=""
	TheSquares=""
	for(i=0;i<occurence;i++){
		Square = document.createElement("DIV")
		Square.style.width=15;
		Square.innerHTML='<img src="/p2/p.gif" width="15" height="15">'
		Square.className='prgrssBarre'
		Square.style.margin = 2
		Square.style.position='relative'
		Square.style.styleFloat = 'left'
		Square.style.cssFloat = 'left'
		Square.id='Square_'+i
		SquareContainer.appendChild(Square)
	}
	if(occurence<nbSquares)occurence++
	else occurence=0
	_progresseBarreTimer = setTimeout("CreateProgressBarre('',"+nbSquares+","+occurence+")",100)
}



var _PLpopUpSize
function PLpopUp(size,title,subtitle,NoEscap,quick){
	if(_PLDisplayMessageTimer!=null){
		clearTimeout(_PLDisplayMessageTimer);
		_PLDisplayMessageTimer=null;
	}
	removeGlobalEvent(document,"keydown",attachEnterEventToDoLoginMemberButton)

	if(!PLg("ThePopUpDiv")){
		hideInputs4IE(1)
		CreateGraphicObject({
			Otype:'DIV',Otarget:'body',
			id:"ThePopUpBackgroundDiv",
			'style.left':0,'style.top':0,'style.width':'99%','style.height':getPageSize().height,'style.opacity':0
		})
		if(typeof quick !='boolean' || !quick)FadeInObject("ThePopUpBackgroundDiv")
		else{SetOpacity(PLg("ThePopUpBackgroundDiv"),70)}
		CreateGraphicObject({Otype:'DIV',Otarget:'body',id:"ThePopUpDiv",'style.opacity':0})
		if(typeof quick !='boolean' || !quick)FadeInObject("ThePopUpDiv")
		else{SetOpacity(PLg("ThePopUpDiv"),100)}
	}
	var ThePopUpBackgroundDiv = PLg("ThePopUpBackgroundDiv")
	var ThePopUpDiv = PLg("ThePopUpDiv")

	_PLpopUpSize = size
	if(!title || title == "undefined")title="";
	if(!subtitle || subtitle == "undefined")subtitle="";
	ThePopUpBackgroundDiv.M_title=title;
	ThePopUpBackgroundDiv.M_subtitle=subtitle;
		
		if(ThePopUpBackgroundDiv.M_title=="" || ThePopUpBackgroundDiv.M_title=="undefined")ThePopUpBackgroundDiv.M_title=""
		if(ThePopUpBackgroundDiv.M_subtitle=="" || ThePopUpBackgroundDiv.M_subtitle=="undefined")ThePopUpBackgroundDiv.M_subtitle=""
		
		ThePopUpDiv.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td id="PLpopUpTitle" width="95%">'+ThePopUpBackgroundDiv.M_title+'</td><td align="right" width="5%" id="PLpopUpCloseButton" valign="top"></td></tr><tr><td colspan="2" id="PLpopUpSubTitle">'+ThePopUpBackgroundDiv.M_subtitle+'</td></tr></table><br><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td id="ThePopUpDivContent"></td></tr></table>'
		
		//PLg("ThePopUpDivContent").innerHTML="&nbsp;"
		if(!NoEscap){
			AddButton('PLpopUpCloseButton',true,null,'  X  ','buttonClose','PLpopUpClose()')
			setGlobalEvent(document,"keydown",PLpopUpEscapeClose)
		}

	PLpopUpResize()
	PLpopUpAddShade()
	window.setTimeout("PLpopUpResize()",10)
	window.setTimeout("PLpopUpResize()",100)
	window.setTimeout("PLpopUpResize()",1000)
	
	setGlobalEvent(window,"resize",PLpopUpResize)
	setGlobalEvent(window,"scroll",PLpopUpResize)

	return true
}

function PLpopUpResize(){
	if(PLg('ThePopUpBackgroundDiv')){
		if(typeof(window.innerWidth)=='number'){PLg('ThePopUpBackgroundDiv').style.width=GetWindowSize(16).width}
		else{PLg('ThePopUpBackgroundDiv').style.width='100%'}
	}
	
	if(isNaN(_PLpopUpSize)){
		if(isIE){_PLpopUpSize = (_PLpopUpSize=='large') ? 970 : 450;}
		else{ _PLpopUpSize = (_PLpopUpSize=='large') ? 914 : 430;}
	}
	
	if(PLg('ThePopUpDiv')){
		with(PLg('ThePopUpDiv')){
			style.width=_PLpopUpSize
			style.left = (GetWindowSize(16).width/2)-offsetWidth/2
			if(offsetHeight<GetWindowSize().height){
				style.top = (GetWindowSize().height/2) - offsetHeight/2 + parseInt(document.body.scrollTop,10)
			}
			else{
				style.top = (GetWindowSize().height/2) - offsetHeight/2
			}
			if(parseInt(style.top,10)<10)style.top=10
		}
		PLpopUpResizeShade()
	}
}

function PLpopUpEscapeClose(e){
	var TheEvent=(e)? e.keyCode : event.keyCode;
	if(TheEvent==27){
		PLpopUpClose()
		removeGlobalEvent(document,"keydown",PLpopUpEscapeClose)
	}
}

/* APPEL DE CONTENU EXTERNE HORS DOCUMENT */
function PagePopup(ref,title,subtitle,size){
	if(typeof size == 'undefined')var size = 'large'
	if(typeof ref == 'object')ref=ref.href
	Rref=appendUrlAttribute(ref,'ispopup',1)

	if(size=='large'){ 
		var FrameWidth=920;var FrameHeight=500;
	}
	else{ 
		if(isIE){ var FrameWidth=380; var FrameHeight=300; }
		else {var FrameWidth=430; var FrameHeight=300; }
	}
	PLpopUp(size,title,subtitle)
	PLg("ThePopUpDivContent").innerHTML='<iframe src="'+Rref+'" style="border:0;borderStyle:none;width:'+FrameWidth+'px;height:'+FrameHeight+'px;"></iframe>'
}


/* APPEL DE CONTENU EXTERNE DANS LE DOCUMENT */
function PLExternalpopUp(size,name,title,subtitle,url,nocache,NoEscap){
	if(!nocache)nocache=false
	if(!NoEscap)NoEscap=false
	PLpopUp(size,title,subtitle,NoEscap)
	PLg("ThePopUpDivContent").innerHTML='<div id="PopupWaitDivMssg">Appel en cours...</div>'
	window.setTimeout("PLExternalpopUpInit('"+name+"','"+url+"',"+nocache+")",300)
}

var _ExternalpopUpCache=[]
function PLExternalpopUpInit(name,url,nocache){
	if(nocache){
		PLg("ThePopUpDivContent").innerHTML=PLExternalpopUpCall(url,name)
	}
	else{
		eval('TheCache = _ExternalpopUpCache.'+name)
		if(typeof(TheCache)=='undefined'){
			TheCache = escape(PLExternalpopUpCall(url,name))
			eval('_ExternalpopUpCache.'+name+'="'+TheCache+'"')
		}
		else{
			PLg("ThePopUpDivContent").innerHTML= unescape(TheCache);
			try{eval(name+'Init()')}catch(e){}
		}
	}
	PLpopUpResize()
}

function PLExternalpopUpCall(url,name){
try{
	var requestData = "&page="+CurrentPage;
	var RequestUrl=url
	var TheCode = makeRequest(RequestUrl,requestData,'return')
	PLg("ThePopUpDivContent").innerHTML=TheCode
	var IsJS2init=false
	var LesScripts = PLg("ThePopUpDivContent").getElementsByTagName('input')
	for(var i=0,j=LesScripts.length;i<j;i++){
		if(LesScripts[i].type=='hidden' && LesScripts[i].name=='scriptSource'){
			var NewScript = document.createElement('script'); 
			NewScript.setAttribute('type', 'text/javascript');
			var d = new Date().getTime()
			NewScript.setAttribute('src', LesScripts[i].value+'?r='+d);
			document.getElementsByTagName('head')[0].appendChild(NewScript);
			IsJS2init=true
		}
	}
	if(IsJS2init){
	    // IE
	    NewScript.onreadystatechange = function(){
	        if (/complete|loaded/.test(NewScript.readyState)) {
				try{eval(name+'Init()')}catch(e){PLExternalpopUpCallLaunch(name)}
	        }
	    }
	    // FF
	    NewScript.onload = function(){try{eval(name+'Init()')}catch(e){PLExternalpopUpCallLaunch(name)}}
		
		// Opera & Safari
		if(/WebKit|Khtml/i.test(navigator.userAgent) || /Opera/i.test(navigator.userAgent)) {
	        //try{window.setTimeout("eval("+name+"Init())",500)}catch(e){}
			PLExternalpopUpCallLaunch(name)
	    }
	}
	return TheCode
}
catch(e){}
}

function PLExternalpopUpCallLaunch(name){
	try{eval(name+'Init()');}
	catch(e){window.setTimeout("PLExternalpopUpCallLaunch("+name+")",500)}
}

var _ThePopupShadeElements = ["TheTopRightPopShade","TheRightPopShade","TheBottomCornerPopShade","TheBottomPopShade","TheBottomBottomPopShade"]
function PLpopUpAddShade(TheBox){
if(typeof TheBox != 'object'){
	if(PLg("ThePopUpDiv"))var TheBox = PLg("ThePopUpDiv")
	else return
}

	for(var i=0,j=_ThePopupShadeElements.length;i<j;i++){
		if(!PLg(_ThePopupShadeElements[i])){
			CreateGraphicObject({
				Otarget:'body',Otype:'DIV',
				id:_ThePopupShadeElements[i],'className':'empty',
				'style.position':'absolute','style.zIndex':100001,
				'style.background':"url(/p2/"+_ThePopupShadeElements[i]+".png)"
			})
			var NewElement = PLg(_ThePopupShadeElements[i])
			if(isIE6){
				NewElement.style.filter= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/p2/"+_ThePopupShadeElements[i]+".png, sizingMethod='crop')"
				NewElement.style.background='none'
			}
		}
		else{var NewElement=PLg(_ThePopupShadeElements[i])}
	}
	PLpopUpResizeShade()
}
function PLpopUpResizeShade(TheBox){
if(typeof TheBox != 'object'){
	if(PLg("ThePopUpDiv"))var TheBox = PLg("ThePopUpDiv")
	else return
}
	for(var i=0,j=_ThePopupShadeElements.length;i<j;i++){
		switch(_ThePopupShadeElements[i]){
			case 'TheTopRightPopShade' :
				if(!PLg('TheTopRightPopShade'))return;
				SetObjectCoords(
					PLg('TheTopRightPopShade'),
					parseInt(TheBox.offsetTop,10),
					(parseInt(TheBox.offsetLeft,10)+parseInt(TheBox.offsetWidth,10)),
					11,11
				)
			break;
			case 'TheRightPopShade' :
				if(!PLg('TheRightPopShade'))return;
				SetObjectCoords(
					PLg('TheRightPopShade'),
					(parseInt(TheBox.offsetTop,10)+11),
					(parseInt(TheBox.offsetLeft,10)+parseInt(TheBox.offsetWidth,10)),
					11,(parseInt(TheBox.offsetHeight,10)-11)
				)
			break;
			case 'TheBottomCornerPopShade' :
				if(!PLg('TheBottomCornerPopShade'))return;
				SetObjectCoords(
					PLg('TheBottomCornerPopShade'),
					(parseInt(TheBox.offsetTop,10)+parseInt(TheBox.offsetHeight,10)),
					(parseInt(TheBox.offsetLeft,10)+parseInt(TheBox.offsetWidth,10)),
					11,11
				)
			break;
			case 'TheBottomPopShade' :
				if(!PLg('TheBottomPopShade'))return;
				SetObjectCoords(
					PLg('TheBottomPopShade'),
					(parseInt(TheBox.offsetTop,10)+parseInt(TheBox.offsetHeight,10)),
					(parseInt(TheBox.offsetLeft,10)+11),
					(parseInt(TheBox.offsetWidth,10)-11),11
				)
			break;
			case 'TheBottomBottomPopShade' :
				if(!PLg('TheBottomBottomPopShade'))return;
				SetObjectCoords(
					PLg('TheBottomBottomPopShade'),
					(parseInt(TheBox.offsetTop,10)+parseInt(TheBox.offsetHeight,10)),
					parseInt(TheBox.offsetLeft,10),
					11,11
				)
			break;
		}
	}
}

function PLpopUpClearShade(){
	for(var i=0;i<_ThePopupShadeElements.length;i++){
		RemoveElement(_ThePopupShadeElements[i],true)
	}
}

function PLpopUpClose(){
if(PLg("ThePopUpDiv")){
	PLpopUpClearShade()
	RemoveElement(PLg("ThePopUpDiv"))
	RemoveElement(PLg("ThePopUpBackgroundDiv"))
	hideInputs4IE(0)
}
else if(parent.document && document.location != parent.document.location){
	parent.PLpopUpClose()
}
removeGlobalEvent(document,"keydown",PLpopUpEscapeClose)
removeGlobalEvent(document,"keydown",attachEnterEventToDoLoginMemberButton)
}

// Masque/affiche inputs pour calques modaux
function hideInputs4IE(arg){
if(isIE6){
	var Selects=document.getElementsByTagName("select")
	if(arg){
		for(var i=0,ii=Selects.length;i<ii;i++){
			Selects[i].style.visibility='hidden'
		}
	}
	else{
		if(Selects.length>0){
			for(var i=0,ii=Selects.length;i<ii;i++){
				Selects[i].style.visibility='visible'
			}
		}
	}
}
}

