var popupbox;
var popupbox_zone;
var popupbox_text;

var popupbox_width = 501;
var popupbox_height = 210;

var url_timeout = '';
var url_redirect = '';

function popLb_init(msg, swf, redirect, timeout)
{
	popupbox = $('popup_wait');
	popupbox_zone = $('popup_wait_cont');
	popupbox_text = $('popup_wait_text');
	popupbox_title = $('popup_wait_title');
	
	//Taille de la fenetre ...
	if(getFrameHeight() < (popupbox_height + 60)) popupbox_height = getFrameHeight() - 60;
	if(getFrameWidth() < (popupbox_width + 60)) popupbox_width = getFrameWidth() - 60;
	
	popupbox_text.innerHTML = msg;
	
	if(swf != '')
	{
		var flash = site_url + 'swf/' + swf;
	
		popupbox_text.innerHTML = '<div id="popup_wait_swf"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="wigze_swf" width="410px" height="300px"><param name="movie" value="' + flash + '" /><param name="quality" value="best" /><param name="wmode" value="transparent" /><embed src="' + flash + '" quality="best" wmode="transparent" width="410px" height="300px" name="wigze_swf" align="middle" allowFullScreen="false" type="application/x-shockwave-flash"  pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><div>' + msg;
		
		popupbox_title.style.display = 'none';
		popupbox_zone.style.background = "none";
		popupbox_zone.style.background = "url('')";
	}
	
	/***/
	
	if(redirect != '')
	{
		url_timeout = timeout;
		url_redirect = redirect;
	}
	
	/***/
	
	pop_ShowMap();
}


function pop_Update()
{
	if(popupbox.style.display != 'none')
	{
		if(document.all)
		{
			popupbox.style.top = getScrollHeight() + "px";
			popupbox.style.left = getScrollWidth() + "px";
		}
	
		/***/
		/*
		if(is_ie || is_opera)
		{
			popupbox.style.top = getScrollHeight() + "px";
			popupbox.style.left = getScrollWidth() + "px";
	
			popupbox.style.width = $('conteneur').offsetWidth + "px";
			popupbox.style.height = $('conteneur').offsetHeight + "px";
		}
		else
		{
			popupbox.style.top = "0px";
			popupbox.style.left = "0px";
	
			popupbox.style.width = $('conteneur').offsetWidth + "px";
			popupbox.style.height = $('conteneur').offsetHeight + "px";
		}
		*/
		/***/
	
		if(is_ie || is_opera)
		{
			popupbox_zone.style.left = ((getFrameWidth() - popupbox_zone.offsetWidth)/2) + "px";
			popupbox_zone.style.top = ((getFrameHeight() - popupbox_zone.offsetHeight)/2) + "px";
		}
		else
		{
			popupbox_zone.style.left = getScrollWidth() + ((getFrameWidth() - popupbox_zone.offsetWidth)/2) + "px";
			popupbox_zone.style.top = getScrollHeight() + ((getFrameHeight() - popupbox_zone.offsetHeight)/2) + "px";
		}

		/***/
			
		popupbox.style.display = 'block';
	}
}


function pop_ShowMap()
{
	if(document.all)
	{
		popupbox.style.top = getScrollHeight() + "px";
		popupbox.style.left = getScrollWidth() + "px";
	}
	
	/***/
	/*
	if(is_ie || is_opera)
	{
		popupbox.style.top = getScrollHeight() + "px";
		popupbox.style.left = getScrollWidth() + "px";
	
		popupbox.style.width = $('conteneur').offsetWidth + "px";
		popupbox.style.height = $('conteneur').offsetHeight + "px";
	}
	else
	{
		popupbox.style.top = "0px";
		popupbox.style.left = "0px";
	
		popupbox.style.width = $('conteneur').offsetWidth + "px";
		popupbox.style.height = $('conteneur').offsetHeight + "px";
	}
	*/
	/***/
	
	if(is_ie || is_opera)
	{
		popupbox_zone.style.left = ((getFrameWidth() - popupbox_width)/2) + "px";
		popupbox_zone.style.top = ((getFrameHeight() - popupbox_height)/2) + "px";
	}
	else
	{
		popupbox_zone.style.left = getScrollWidth() + ((getFrameWidth() - popupbox_width)/2) + "px";
		popupbox_zone.style.top = getScrollHeight() + ((getFrameHeight() - popupbox_height)/2) + "px";
	}
	
	/***/
	
	popLbOnShow();
}


function popLbOnShow()
{
	if(!is_ie6)
	{
		new Effect.Appear(popupbox, {duration: 0.5, queue: 'front'});
	}
	else
	{
		if(cacheInputSelect())
		{
			new Effect.Appear(popupbox, {duration: 0.5, queue: 'front'});
		}
	}
}


function popLbOnClose()
{
	if(!is_ie6)
	{
		new Effect.Fade(popupbox, {duration: 0.5, queue: 'front'});
			
		if(url_redirect != '')
		{
			window.setTimeout('document.location = "' + url_redirect + '";', url_timeout);
		}
	}
	else
	{
		if(decacheInputSelect())
		{
			new Effect.Fade(popupbox, {duration: 0.5, queue: 'front'});
			
			if(url_redirect != '')
			{
				window.setTimeout('document.location = "' + url_redirect + '";', url_timeout);
			}
		}
	}
}


function getFrameWidth()
{
	if (self.innerWidth)
	{
		return self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	else return;
}


function getFrameHeight()
{
	if (self.innerWidth)
	{
		return self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		return document.body.clientHeight;
	}
	
	else return;
}


function getScrollWidth()
{
	var w = window.pageXOffset ||
	document.body.scrollLeft ||
	document.documentElement.scrollLeft;
	
	return w ? w : 0;
}


function getScrollHeight()
{
	var h = window.pageYOffset ||
	document.body.scrollTop ||
	document.documentElement.scrollTop;
	
	return h ? h : 0;
}


function popLbAddLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		if(!is_ie)
		{
			window.onload = func;
		}
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}


function popLbAddResizeEvent(func)
{
	var oldonresize = window.onresize;
	if (typeof window.onresize != 'function')
	{
		window.onresize = func;
	}
	else
	{
		window.onresize = function()
		{
			oldonresize();
			func();
		}
	}
}


function popLbAddScrollEvent(func)
{
	var oldonscroll = window.onscroll;
	if (typeof window.onscroll != 'function')
	{
		window.onscroll = func;
	}
	else
	{
		window.onscroll = function()
		{
			oldonscroll();
			func();
		}
	}
}


function popLbAddLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		if(!is_ie)
		{
			window.onload = func;
		}
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			//func();
		}
	}
}


function popLbAddClickEvent(obj,func)
{
	var oldonclick = obj.onclick;
	if (typeof obj.onclick != 'function')
	{
		obj.onclick = func;
	}
	else
	{
		obj.onclick = function()
		{
			oldonclick();
			func();
		}
	}
}
