
var globalBlack = false;
var globalPopup = false;
var updater = null;
var popupClosed = true;

function ShowHide(psId)
{
	if(document.getElementById(psId).style.display == 'none') 
	{
		document.getElementById(psId).style.display='block';
	} 
	else 
	{
		document.getElementById(psId).style.display='none';
	}
}



function Show(psId)
{
	document.getElementById(psId).style.display='';
}

function Hide(psId)
{
	document.getElementById(psId).style.display='none';
}

function showConsole(sHideId1, sHideId2, sHideId3, sShowHide, sRegister1, sRegister2, sRegister3, sRegister4)
{
	Hide(sHideId1);
	Hide(sHideId2);
	Hide(sHideId3);
	ShowHide(sShowHide);
	RegisterByCookie(sRegister1);
	RegisterByCookie(sRegister2);
	RegisterByCookie(sRegister3);
	RegisterByCookie(sRegister4);
}

function popUpWinFullScreen (url, win) 
{
	var nLeft = 0;
	var nTop = 0;
	var nWidth = screen.availWidth - 10;
	var nHeight = screen.availHeight - 10;
	
	options = 'width=' + nWidth + ',height=' + nHeight + ',left=' + nLeft + ',top=' + nTop + ',resizable=yes,scrollbars=yes';
	return window.open(url, win, options);
}

function popUpWinMedium (url, win) 
{
	var nWidth = 700;
	var nHeight = 500;
	var nLeft = (screen.width-nWidth)/2;
	var nTop = (screen.height-nHeight)/2;
	
	
	options = 'width=' + nWidth + ',height=' + nHeight + ',left=' + nLeft + ',top=' + nTop + ',resizable=yes,scrollbars=yes';
	window.open(url, win, options);
}

function popUpWinCustom (url, win, pnWidth, pnHeight) 
{
	var nLeft = (screen.width-pnWidth)/2;
	var nTop = (screen.height-pnHeight)/2;
	
	
	options = 'width=' + pnWidth + ',height=' + pnHeight + ',left=' + nLeft + ',top=' + nTop + ',resizable=yes,scrollbars=yes';
	window.open(url, win, options);
}

var gMenuTimer;
var gMenuTimerSearch;
var gsLastOpened = "";
var gnTime = 500;
function ShowMenu (psId, pbShow) 
{
	clearTimeout(gMenuTimer);
	clearTimeout(gMenuTimerSearch);
	if (pbShow == true)
	{
//		alert("show "+gsLastOpened);
		if (gsLastOpened != psId)
		{
//			alert("LastOpened : "+gsLastOpened);
			if (gsLastOpened != "")
				document.getElementById(gsLastOpened).style.display = 'none';
		}
		document.getElementById(psId).style.display = '';
		gsLastOpened = psId;
		
		if (document.getElementById('layer_search') != undefined)
				document.getElementById('layer_search').style.display = 'none';
	}
	else	
	{
//		alert("hide");
		gMenuTimer = setTimeout("document.getElementById('"+psId+"').style.display = 'none'", gnTime);
		if (document.getElementById('layer_search') != undefined)
			gMenuTimerSearch = setTimeout("document.getElementById('layer_search').style.display = ''", gnTime);
	}
}



function FillPicker (psDataField, psDataValue, psViewField, psViewValue)
{
	window.opener.document.getElementById(psDataField).value = psDataValue;
	window.opener.document.getElementById(psViewField).innerHTML = psViewValue;
	self.close();
}
/*
function FillPicker (psDataField, psDataValue, psViewField, psViewValue)
{
	top.document.getElementById(psDataField).value = psDataValue;
	top.document.getElementById(psViewField).innerHTML = psViewValue;
	//document.getElementById('gal').style.display = 'none';
}
*/
function FillMultiPicker (psDataField, psDataValue, psViewField, psViewValue)
{
	window.opener.document.getElementById(psDataField).value += psDataValue;
	window.opener.document.getElementById(psViewField).innerHTML += psViewValue;
	self.close();
}

function FillRte (psRteId, psPicturePath)
{
	window.opener.rteCommand(psRteId, 'InsertImage', psPicturePath)
	self.close();
}

function FillRteLink (psRteId, psLink)
{
	
	window.opener.addHTML(psRteId, psLink)
	self.close();
}

function FillColorPicker(psId, psIdSquare, psValue)
{
	document.getElementById(psId).value = psValue;
	document.getElementById(psIdSquare).style.background = psValue;
}

function FillColorPickerRealTime(psId, psIdSquare, psValue)
{
	document.getElementById(psId).value = psValue;
	document.getElementById(psIdSquare).style.background = psValue;
}

function EditToColor(psId, psIdSquare)
{
	var sValue = document.getElementById(psId).value;
	if (sValue != "")
	{
		document.getElementById(psIdSquare).style.background = sValue;
	}
}

function FillSelector (psDivId, psDataField, psDataValue, psViewField, psViewValue)
{
	document.getElementById(psDataField).value = psDataValue;
	document.getElementById(psViewField).value = psViewValue;
	//document.getElementById(psViewField).innerHTML = psViewValue;
	document.getElementById(psDivId).style.display='none';
}


/********************************************/
/* Fonctions de gestion des messages return */
/********************************************/

function CloseMessageReturn(psId)
{
	document.getElementById(psId).style.display = 'none';
}

function ShowMinus(psId, pnOpacity)
{
	try
	{
		document.getElementById(psId).style.opacity = pnOpacity;
		document.getElementById(psId).style.filter = "alpha(opacity:"+pnOpacity*100+")";
	}
	catch (ex)
	{
	}
}

function HideMessageReturn(psId, pnTime)
{
//	setTimeout("CloseMessageReturn('"+psId+"')", pnTime);
	try
	{
		var i = 1;
		var nTimer = pnTime;
		for (i = 1 ; i>=0 ; i=i-0.1)
		{
			nTimer = nTimer + 100;
			setTimeout("ShowMinus('"+psId+"', "+i+")", nTimer);
		}
		nTimer = nTimer + 100;
		setTimeout("CloseMessageReturn('"+psId+"')", nTimer);
	}
	catch (ex)
	{
	}
}

function UpdateDate(psField, psFieldYYYY, psFieldMM, psFieldDD)
{
	var Year = document.getElementById(psFieldYYYY).value;
	var Month = document.getElementById(psFieldMM).value;
	var Day = document.getElementById(psFieldDD).value;

	document.getElementById(psField).value = Year + "-" + Month + "-" + Day;
}

function product_zoom_show(psDivId)
{
	document.getElementById("product_div_desc").style.display = 'none';
	document.getElementById("product_div_benefits").style.display = 'none';
	document.getElementById("product_div_composition").style.display = 'none';
	document.getElementById("product_div_application").style.display = 'none';
	
	document.getElementById(psDivId).style.display = '';

}

function newsletterChangeAction(pbValue, psElementId, psActionTrue, psActionFalse)
{
	if (pbValue)
		document.getElementById(psElementId).value = psActionTrue;
	else
		document.getElementById(psElementId).value = psActionFalse;
}

function waitForm()
{
	document.getElementById('form_back').style.visibility = 'visible';
	document.getElementById('form_wait').style.visibility = 'visible';
}

function WriteCookie(psName, psValue)
{
	var argv = WriteCookie.arguments;
	var argc = WriteCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie=psName+"="+escape(psValue)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieValue(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function ReadCookie(psName)
{
	var arg=psName+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieValue(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

function RegisterByCookie(psDiv)
{
	if (document.getElementById(psDiv).style.display == 'none')
		WriteCookie(psDiv, 0);
	else
		WriteCookie(psDiv, 1);
}
/*
var gasCheckbox = new Array();
var gnIndiceCheckbox = 0;
function addSelectionCheckbox(psCheckBoxId)
{
//	alert("Ajout " + psCheckBoxId);
	gasCheckbox[gnIndiceCheckbox] = psCheckBoxId;
	gnIndiceCheckbox++;
}

function checkAll()
{
	if ()
	for (nIndice = 0; nIndice < gnIndiceCheckbox; nIndice++)
	{
		var sId = gasCheckbox[nIndice];
//		alert("->" + sId);
		document.getElementById(sId).checked = true;
	}
}*/

function changeClass(psDivId, psClass)
{
	document.getElementById(psDivId).className = psClass;	
}


function counter(psHourId, psMinuteId, psSecondId)
{
	setTimeout('counter("'+psHourId+'", "'+psMinuteId+'", "'+psSecondId+'")', 1000);
	
	var nIncrement = -1;
	var nHour 	= parseInt(document.getElementById(psHourId).innerHTML);
	var nMinute = parseInt(document.getElementById(psMinuteId).innerHTML);
	var nSecond = parseInt(document.getElementById(psSecondId).innerHTML);
	
	var nNewHour 	= nHour;
	var nNewMinute 	= nMinute;
	var nNewSecond 	= nSecond;
	
	if (nSecond > 0)
	{
		nNewSecond = nSecond - 1;
	}
	else
	{
		nNewSecond = 59;
		if (nMinute > 0)
		{
			nNewMinute = nMinute - 1;
		}
		else
		{
			nNewMinute = 59;
			if (nHour > 0)
			{
				nNewHour = nHour -1;
			}
			else
			{
				nNewHour = 0;
				nNewMinute = 0;
				nNewSecond = 0;
			}
		}
	}

	if (nNewHour 	<= 9) nNewHour 	= "0"+nNewHour;
	if (nNewMinute 	<= 9) nNewMinute = "0"+nNewMinute;
	if (nNewSecond 	<= 9) nNewSecond = "0"+nNewSecond;
	
	document.getElementById(psHourId).innerHTML = nNewHour;
	document.getElementById(psMinuteId).innerHTML = nNewMinute;
	document.getElementById(psSecondId).innerHTML = nNewSecond;

	
}


function blink(psId, pnInterval)
{
	setTimeout('blink("'+psId+'", '+pnInterval+')', pnInterval);
	
	if (document.getElementById(psId).style.display == 'none')
		document.getElementById(psId).style.display = '';
	else
		document.getElementById(psId).style.display = 'none';
}


function screenSwitch(psIdHide, psIdShow, psUrl, pbReturn)
{	
	if (!pbReturn)
	{
		displayScreen(psUrl, psIdHide, psIdShow);		
	}
	else
	{
		destroyScreen(psIdHide);	
	}
	
	// show
	Effect.Appear(psIdShow, { duration: 1.0, from: 0.0, to: 1.0});	
	//hide
	Effect.Appear(psIdHide, { duration: 0.5, from: 1.0, to: 0.0});
}


function blackScreen()
{
	/*$('blackScreen_container').style.top = 'Opx';
	$('blackScreen_container').style.left = 'Opx';*/
//	$('blackScreen_container').style.width = '10O%';
	//$('blackScreen_container').style.height = '10O%';
	$('blackScreen_container').style.backgroundColor = '#000';
	
	Effect.Appear('blackScreen_container', { duration: 1.0, from: 0.0, to: 0.75});	
	
	$('body').style.overflow = 'hidden';
	setTimeout('changeBlackScreenStatus(true)', 1000);
	
	popupClosed = false;
	
}


function whiteScreen(bForce)
{
	if ((globalBlack || globalPopup) && updater != null)
	{
		updater.stop();
		updater = null;	
	}	
	
	if (globalBlack || bForce)
	{
		Effect.Fade('blackScreen_container');			
		changeBlackScreenStatus(false);
	}	
	
	
	if (globalPopup || bForce)
	{
		Effect.Fade('ajax_container');
		changePopupStatus(false);
		popupClosed = true;
	}
}


function displayAjaxPopup(psId, psTitle)
{
	$('ajax_container').style.top = '250px';
	$('ajax_container').style.left = '50%';
	$('ajax_container').style.width = '540px';
	$('ajax_container').style.height = '250px';
	$('ajax_container').style.backgroundColor = '#fff';
	$('ajax_container').style.marginLeft = '-270px';
	$('ajax_container').style.zIndex = '10';
	
	setTimeout('changePopupStatus(true)', 1000);
	
	$('ajax_container_title').innerHTML = psTitle;
	
	Effect.Appear('ajax_container', { duration: 1.0, from: 0.0, to: 1.0});	
	
	popupClosed = false;
}


function changeBlackScreenStatus(pbStatus)
{
	globalBlack = pbStatus;
}


function changePopupStatus(pbStatus)
{
	globalPopup = pbStatus;
}


function stopAjaxPopupLoader()
{
	$('ajax_container_loader').innerHTML = '';
}

function hideColumn(psTableId, pnIndice)
{
	var sCookie;
	sCookie = ReadCookie(psTableId);
	var sCookieFinal = sCookie+pnIndice+";";
	WriteCookie(psTableId, sCookieFinal);

	
	var allRows = document.getElementById(psTableId).rows;
	
	if (!allRows) return false;
	
	for (var i=0; i<allRows.length; i++) 
	{
		if (allRows[i].cells[pnIndice])
		{
			allRows[i].cells[pnIndice].style.display = 'none';
		}
	}
}


function showColumn(psTableId, pnIndice)
{
	var sCookie;
	sCookie = ReadCookie(psTableId);
	
	if (sCookie)
		sCookie = sCookie.replace(pnIndice+";", "");
		
	WriteCookie(psTableId, sCookie);
	
	
	var allRows = document.getElementById(psTableId).rows;
	if (!allRows) return false;

//	if (!allRows) alert('Tableau introuvable : '+psTableId);
	
	for (var i=0; i<allRows.length; i++) 
	{
		if (allRows[i].cells[pnIndice])
		{
			allRows[i].cells[pnIndice].style.display = '';
		}
	}
}

function addToBookmark(psLabel, psURL) 
{
	if ( navigator.appName != 'Microsoft Internet Explorer' )
	{ 
		window.sidebar.addPanel(psLabel, psURL,""); 
	} 
	else 
	{ 
		window.external.AddFavorite(psURL, psLabel); 
	} 
}

var bStatus = true;

function checkBoxAll(psFormId) 
{
    
    var checkboxes = [];
    checkboxes = $$('input').each
    (
        function(e)
        { 
            if(e.type == 'checkbox') 
                checkboxes.push(e);
        }
    );
    
    checkboxes.each(function(e){ e.checked = bStatus });
    
    bStatus = !bStatus;
}

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){ // 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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

