var popcgu;
var popcgu_zone;
var popcgu_title;
var popcgu_text;
var popcgu_close;
var popcgu_button;

var popcgu_read;

var popcgu_width = 687;
var popcgu_height = 412;

var rubrique_id = '';
var formulaire_id = '';

function popCGULb_init(title, rub_id, form_id)
{
	popcgu = $('popcgu_cont');
	popcgu_zone = $('popcgu_zone');
	popcgu_title = $('popcgu_title');
	popcgu_text = $('popcgu_text');
	popcgu_close = $('popcgu_close');
	popcgu_button = $('popcgu_button');
	
	rubrique_id = rub_id;
	formulaire_id = form_id;
	
	//Taille de la fenetre ...
	if(getFrameHeight() < (popcgu_height + 60)) popcgu_height = getFrameHeight() - 60;
	if(getFrameWidth() < (popcgu_width + 60)) popcgu_width = getFrameWidth() - 60;
	
	/***/
	
	popcgu_close.onclick = function()
	{
		popCGULbOnClose();
	};
	
	/***/
	
	if(title != '')
	{
		popcgu_title.innerHTML = title;
	}
	
	/***/
	
	var phpFile = site_url + 'ajax/popcgu.ajx.php';
	var params = '';
	
	if(rub_id != '')
	{
		params = '?rub_id=' + rub_id;
	}
	
	var aj = new Ajax.Updater(popcgu_text, phpFile + params, {
		onComplete: 
		function()
		{
			popcgu_read = $('read_cgu');
			popCGU_ShowMap();
		}
		});
}


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

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


function popCGU_ShowMap()
{	
	if(document.all)
	{
		popcgu.style.top = getScrollHeight() + "px";
		popcgu.style.left = getScrollWidth() + "px";
	}
	
	/***/
	
	if(is_ie || is_opera)
	{
		popcgu.style.top = getScrollHeight() + "px";
		popcgu.style.left = getScrollWidth() + "px";
	
		popcgu.style.width = $('dom_hack').offsetWidth + "px";
		popcgu.style.height = $('dom_hack').offsetHeight + "px";
	}
	else
	{
		popcgu.style.top = "0px";
		popcgu.style.left = "0px";
	
		popcgu.style.width = $('dom').offsetWidth + "px";
		popcgu.style.height = $('dom').offsetHeight + "px";
	}
		
	/***/
	
	if(is_ie || is_opera)
	{
		popcgu_zone.style.left = ((getFrameWidth() - popcgu_width)/2) + "px";
		popcgu_zone.style.top = ((getFrameHeight() - popcgu_height)/2) + "px";
	}
	else
	{
		popcgu_zone.style.left = getScrollWidth() + ((getFrameWidth() - popcgu_width)/2) + "px";
		popcgu_zone.style.top = getScrollHeight() + ((getFrameHeight() - popcgu_height)/2) + "px";
	}
	
	/***/
	
	popCGULbOnShow();
}


function popCGULbOnShow()
{
	if(!is_ie6)
	{
		new Effect.Appear(popcgu, {duration: 0.5, queue: 'front'});
	
		window.setTimeout('controlScrollIsset();', 250);
	}
	else
	{
		if(cacheInputSelect())
		{
			new Effect.Appear(popcgu, {duration: 0.5, queue: 'front'});
		
			window.setTimeout('controlScrollIsset();', 250);
		}
	}
}


function popCGULbOnClose()
{
	if(!is_ie6)
	{
		new Effect.Fade(popcgu, {duration: 0.5, queue: 'front'});
	}
	else
	{
		if(decacheInputSelect())
		{
			new Effect.Fade(popcgu, {duration: 0.5, queue: 'front'});
		}
	}
}


function controlReadY()
{
	if((getScrollTextHeight() + popcgu_text.offsetHeight) == popcgu_text.scrollHeight && popcgu_text.innerHTML != '')
	{
		popcgu_button.style.cursor = 'pointer';
		popcgu_button.style.background = 'no-repeat top left url(\'' + site_url + 'css/img/form/zone.button.valider.gif\')';
		
		if(rubrique_id != '')
		{
			popcgu_button.onclick = function()
			{
				$('input_cgu').innerHTML = '<input type="checkbox" name="us_cgv" id="us_cgv" class="input_checkbox" value="1" error="" checked="checked" required="true" />';
				
				/***/
				
				popcgu_button.style.cursor = 'default';
				
				popcgu_button.onclick = function(){ void(0); };
				
				window.setTimeout('FormRequired(\'' + formulaire_id + '\');', 50);
			};
		}
		else
		{
			popcgu_button.onclick = function()
			{
				$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="' + $('cgvbox_value').value + '" error="" cgvbox="true" required="true" />';
				
				popCGULbOnClose();
				
				/***/
				
				popcgu_button.style.cursor = 'default';
				
				popcgu_button.onclick = function(){ void(0); };
				
				window.setTimeout('popcgu_text.innerHTML = \'\';', 230);
				window.setTimeout('popcgu_button.style.background = \'no-repeat top left url(' + site_url + 'css/img/form/zone.button.valider.off.gif)\';', 230);
				window.setTimeout('FormRequired(\'' + formulaire_id + '\');', 250);
			};
		}
	}
	
	/***/
	
	popcgu_close.onclick = function()
	{
		if(formulaire_id == 'form_inscription')
		{
			$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="1" error="" cgvbox="true" required="true" />';
		}
		else
		{
			$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="' + $('cgvbox').value + '" error="" cgvbox="true" required="true" />';
		}
			
		popCGULbOnClose();
		
		/***/
			
		popcgu_button.style.cursor = 'default';
		
		popcgu_button.onclick = function(){ void(0); };
		
		window.setTimeout('popcgu_text.innerHTML = \'\';', 230);
		window.setTimeout('popcgu_button.style.background = \'no-repeat top left url(' + site_url + 'css/img/form/zone.button.valider.off.gif)\';', 230);
	}
}


function controlScrollIsset()
{
	if((getScrollTextHeight() + popcgu_text.offsetHeight) == popcgu_text.scrollHeight && popcgu_text.innerHTML != '')
	{
		popcgu_button.style.cursor = 'pointer';
		popcgu_button.style.background = 'no-repeat top left url(\'' + site_url + 'css/img/form/zone.button.valider.gif\')';
		
		if(rubrique_id != '')
		{
			popcgu_button.onclick = function()
			{
				$('input_cgu').innerHTML = '<input type="checkbox" name="us_cgv" id="us_cgv" class="input_checkbox" value="1" error="" checked="checked" required="true" />';
				
				/***/
				
				popcgu_button.style.cursor = 'default';
				
				popcgu_button.onclick = function(){ void(0); };
				
				window.setTimeout('FormRequired(\'' + formulaire_id + '\');', 50);
			};
		}
		else
		{
			popcgu_button.onclick = function()
			{
				$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="' + $('cgvbox_value').value + '" error="" cgvbox="true" required="true" />';
				
				popCGULbOnClose();
				
				/***/
				
				popcgu_button.style.cursor = 'default';
				
				popcgu_button.onclick = function(){ void(0); };
				
				window.setTimeout('popcgu_text.innerHTML = \'\';', 230);
				window.setTimeout('popcgu_button.style.background = \'no-repeat top left url(' + site_url + 'css/img/form/zone.button.valider.off.gif)\';', 230);
				window.setTimeout('FormRequired(\'' + formulaire_id + '\');', 250);
			};
		}
	}
	
	/***/
	
	popcgu_close.onclick = function()
	{
		if(formulaire_id == 'form_inscription')
		{
			$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="1" error="" cgvbox="true" required="true" />';
		}
		else
		{
			$('input_cgu').innerHTML = '<input type="hidden" id="cgvbox" value="' + $('cgvbox').value + '" error="" cgvbox="true" required="true" />';
		}
			
		popCGULbOnClose();
		
		/***/
				
		popcgu_button.style.cursor = 'default';
		
		popcgu_button.onclick = function(){ void(0); };
		
		window.setTimeout('popcgu_text.innerHTML = \'\';', 230);
		window.setTimeout('popcgu_button.style.background = \'no-repeat top left url(' + site_url + 'css/img/form/zone.button.valider.off.gif)\';', 230);
	}
}


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


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


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


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


function getScrollTextHeight()
{
	var h = popcgu_text.pageYOffset ||
	popcgu_text.scrollTop ||
	popcgu_text.scrollTop;
	
	return h ? h : 0;
}


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


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