// foonctions utiles pour ajouter un filtre lors d'un overlib, et gérer le masquage des selects en conséquence
// Affiche ou masque le filtre alpha avant overlib
function showFiltreBlock()
{
	
	if(document.getElementById('filtre'))
	{
		gestion_affichage_select('global', 'hidden')
		document.getElementById('filtre').style.display='block';
		/*if(document.getElementById && document.all)
			document.getElementById('filtre').style.height = (document.body.offsetHeight) +'px';
		else
			document.getElementById('filtre').style.height = (document.body.scrollHeight) +'px';*/
		var arrPageSizes2 = GetPageSize2();
		//alert(document.body.clientHeight+" - "+window.innerHeight+" - "+document.body.offsetHeight+" - "+document.body.scrollHeight);
		document.getElementById('filtre').style.height = arrPageSizes2[1] +'px';
		if(document.body.scrollWidth < 940)
			document.getElementById('filtre').style.width = '940px';
		else
			document.getElementById('filtre').style.width = document.body.scrollWidth +'px';
	}
}
function hideFiltreBlock()
{
	if(document.getElementById('filtre'))
	{
		gestion_affichage_select('global', 'visible')
		document.getElementById('filtre').style.display='none';
	}
}
function gestion_affichage_select(X_conteneur, X_etat)
{
	if(document.getElementById(X_conteneur))
	{
		ListeObj = document.getElementById(X_conteneur).getElementsByTagName('select');
		for(i=0; i<ListeObj.length; i++)
		{
			ListeObj[i].style.visibility = X_etat;
		}
	}
}
window.onresize = function()
{	
	// si prototype n'est pas inclus
	if(typeof(window.hasPrototype)=='undefined' || !hasPrototype)
	{	
		if(document.getElementById('filtre').style.display == 'block')
		{
			showFiltreBlock();
			OLplaceLayer();
		}
	}
	else if(hasPrototype)
	{
		resizeFiltreBasic();
	}	
}

function getPageSize()
{
    var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{  
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
    var windowWidth, windowHeight;
	if (self.innerHeight)
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
	
    var pageHeight, pageWidth;
    if(yScroll < windowHeight)
		pageHeight = windowHeight;
	else
		pageHeight = yScroll;
    if(xScroll < windowWidth)
		pageWidth = windowWidth;
    else
		pageWidth = xScroll;
    return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
}

function resizeFiltreBasic()
{
	if($('filtre').style.display!='none')
	{
		showFiltreBasic();
		OLplaceLayer();
	}
}

function getIntMargin(value)
{	
	return parseInt(value.replace(/([0-9]+).*/,"$1"));	
}

function showFiltreBasic()
{
	if(typeof(window.hasPrototype)=='undefined' || !hasPrototype)
	{
		showFiltreBlock();
	}
	else if(hasPrototype)
	{	
		var pageSize              = getPageSize();
		conteneur_dimensions      = Element.getDimensions(document.body);
		var body_margintop        = getIntMargin(Element.getStyle(document.body,"margin-top"));			
		var body_marginbottom     = getIntMargin(Element.getStyle(document.body,"margin-bottom"));		
		var hauteur_conteneur     = conteneur_dimensions.height + body_margintop + body_marginbottom;
		$('filtre').style.display = "block";
		if (pageSize.windowHeight < hauteur_conteneur)
			$('filtre').style.height= (hauteur_conteneur + "px");
		else
			$('filtre').style.height = (pageSize.windowHeight + 'px');
		
		$('filtre').style.width= (pageSize.windowWidth + 'px');	
	}
}
function GetPageSize2() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
function hideFiltreBasic()
{
	if(typeof(window.hasPrototype)=='undefined' || !hasPrototype)
	{
		hideFiltreBlock();
	}
	else if(hasPrototype)
	{
		gestion_affichage_select_basic('conteneur', 'visible');
		$('filtre').style.display='none';
	}
}
function gestion_affichage_select_basic(X_conteneur, X_etat)
{	
	if($(X_conteneur))
	{
		ListeObj = $(X_conteneur).getElementsByTagName('select');		
		for(i=0; i<ListeObj.length; i++)
		{
			ListeObj[i].style.visibility = X_etat;
		}
	}
}

function overlibContact(titre,message)
{
	var buffer = '';
	buffer+='<div class="contact" style="padding:5px">';
	buffer+='	<form>';
	buffer+='		<fieldset>';
	buffer+=			message;
	buffer+='			<p class="bouton" style="margin:10px 0 10px 0;text-align:center;width:100%;">';
	buffer+='				<input value="OK" onClick="hideFiltreBasic();return cClick();" type="button" />';
	buffer+='			</p>';
	buffer+='		</fieldset>';
	buffer+='	</form>';
	buffer+='</div>';
	showFiltreBasic();
	overlib(buffer,CAPTION,titre,MIDX,0,MIDY,0,STICKY,WIDTH,200);
}

function overlibMessage(titre,message,width,height)
{	
	showFiltreBasic();	
	var buffer = '<div id="popup_traitement" class="popup_'+width+height+'">'+"\n";
	buffer += '	<a href="javascript:void(0);" class="overlibclose" onclick="hideFiltreBasic();cClick();" title="">FERMER</a>'+"\n";
	buffer += '	<h3 class="popup_traitement_h3">'+titre+'</h3>'+"\n";
	buffer += '	<div class="popup_traitement_div"><p class="popup_traitement_texte">'+message+'</p></div>'+"\n";
	buffer += '</div>'+"\n";
	overlib(buffer, STICKY, BACKGROUND, "bg_overlib_"+width+height+".gif", MIDX,0,MIDY,0, WIDTH, width, HEIGHT, height);		
	//gestion_affichage_select_basic('conteneur', 'hidden');
}

function overlibErreur_newsletter(titre,message)
{	
	//showFiltreBasic();
	/*var buffer = ''+"\n";
	//buffer += '	<br/><div align="left" style="padding-left:5px;"><font color="#FF0000"><strong>'+titre+'</strong></font><hr color="#FF0000"/></div>'+"\n";
	buffer += ''+message+' '+"\n";
	buffer += ''+"\n";*/
	var buffer = message;
	overlib(buffer, STICKY, BACKGROUND, "images/dista_alerte2.gif", 0,0,0,0, WIDTH, 162, HEIGHT, 168);		
	//gestion_affichage_select_basic('conteneur', 'hidden');
}

function overlib_bloc(src,width,height, name, frameborder,extension)
{	
	//showFiltreBasic();
	largeur = parseInt(width)-10;
	hauteur = parseInt(height)-10;
	buffer  = '<iframe src="'+src+'" width="'+largeur+'" height="'+hauteur+'"';
	buffer += (name!=null?' name="'+name+'" id="'+name+'"':'');
	buffer += (frameborder!=null?' frameborder="'+frameborder+'"':'')
	buffer += ' scrolling="auto" allowtransparency="true">';
	buffer += '<div>[iframe not supported]</div></iframe>';
	overlib(buffer, STICKY, BACKGROUND, extension+"images/fond_"+width+height+".gif", MIDX,0,MIDY,0, WIDTH, width, HEIGHT, height);		
	//gestion_affichage_select_basic('conteneur', 'hidden');
}
