var lcEtat = "o";
var pcEtat = "o";
var rlcEtat = "f";
var rpcEtat = "f";

var beginLC = "o"
var beginPC = "o"

function initPage(messageToPrintAfterDisplayPage) {
	setFrameHeight();
	if (typeof(doOnLoadInPage) == 'function') {
		doOnLoadInPage();
	}
	if (messageToPrintAfterDisplayPage) {
		graphicalEnvironment.showMessage(false,messageToPrintAfterDisplayPage);
	}
}


function getWindowHeight() {
	var windowHeight = 0;
	if (self.innerWidth) {
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}


function getWindowWidth() {
	var windowWidth = 0;
	if (self.innerWidth) {
		windowWidth = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
	}
	return windowWidth;
}

function setAllComboboxVisible(isVisible) {
	var elements = document.getElementsByTagName("SELECT");
	for (i = 0 ; i < elements.length ; i++) {
		if (isVisible)
			elements[i].style.display = "inline";
		else
			elements[i].style.display = "none";
	}
}

function arrayContains(elements, value) {
	for (i = 0 ; i < elements.length ; i++) {
		if (elements[i] == value)
			return true;
	}
	return false;
}

function newXMLHTTPRequest() {
	var result = null;
	if (window.XMLHttpRequest) { // Non-IE browsers
		result = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		result = new ActiveXObject('Microsoft.XMLHTTP')
	}
	return result;
}

function ajaxCallAsynchronous(url, param, callback) {
	var req = newXMLHTTPRequest();
	var getResponse = function() {
		if (req.readyState == 4 && req.status == 200) {
			callback(req.responseText);
		}
	}
	req.onreadystatechange = getResponse;
	req.open("POST", url, true);
    req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.send(null);
}

function callAjaxContact(portal,id,div) {
	
	var type;
	
	var target ;
	
	if (div=='DivProductContact'){
		type="PF";
		if (rpcEtat=="f")decendreRPC();
		target = document.getElementById("DivAffichageProduct");
		
		}
	else {
		type="LC";
		//if (rlcEtat=="f")decendreRLC();
		target = document.getElementById("DivAffichageLocal");
				
		}
	
	var url = "/?eclip=show&RevampingURLParam=BO_CONTAINER,BO_PORTAL-"+ portal+",BO_MODE-PrintAjax,BO_ID-61,BO_CAT-"+ type +id ;
	
	
	
	AjaxRequest.get(
		{
			'url':"/?eclip=show&RevampingURLParam=BO_CONTAINER,BO_PORTAL-"+ portal+",BO_MODE-PrintAjax,BO_ID-61,BO_CAT-"+ type +id
			,'onLoading':function(req)	{ target.innerHTML = req.waitingMsg('Chargement en cours...') ;initRes(div);}
			,'onSuccess':function(req)	{ target.innerHTML = getHTML('/?eclip=show&RevampingURLParam=BO_CONTAINER,BO_PORTAL-'+ portal+',BO_MODE-PrintAjax,BO_ID-61,BO_CAT-'+ type +id);decendreResultat(div);  }
		}
	);
				
	if (div=='DivProductContact'){
		if (lcEtat=="o")remonterLC();
	}else {
		if (pcEtat=="o")remonterPC();
	}			
}
function initRes(div) {
	if (div=='DivProductContact' && beginPC=='o'){
		decendreRPC();		
		beginPC='n';
	}
	if (div=='DivLocalContact' && beginLC=='o'){
		decendreRLC();
		beginLC='n';
	}	
}

function decendreResultat(div) {
	if (div=='DivProductContact'){
		decendreRPC();		
	}else {
		decendreRLC();
	}	
}
/**
 * Function to get the text content of a url
 * This one gets the entire result provided by a http server when the url is entered in a navigator
 * Note that the url for http request is maximum of 2083 characters
 * To patch this limit, the param parameter is added to this function (this parameter is sent in the request in POST mode)
 *
 * @param {String} url Url to call
 * @param {String} param Parameters to be added to the http request (optional)
 * @return {String} Result of the request
 */
function getHTML(url,param) {
	var req = newXMLHTTPRequest();
    req.open("POST", url, false);
    req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if (param)
		req.send(param);
	else
		req.send(null);
	if (req.status == 200) {
		return req.responseText;
	} else {
		return "<div class='formContent'>XML Http request error.</div>";
	}
}

function closeGraphicalWindow(id) {
	eval("if (window.Frame_" + id.substring(id.indexOf("_",0) + 1) + ") { if (window.Frame_" + id.substring(id.indexOf("_",0) + 1) + ".closeDatasheetWithConfirmation) window.Frame_" + id.substring(id.indexOf("_",0) + 1) + ".closeDatasheetWithConfirmation(); else graphicalEnvironment.removeGraphicalWindow(\"" + id + "\"); } else graphicalEnvironment.removeGraphicalWindow(\"" + id + "\");");
}

function redirectIFrameForActions(url) {
	document.getElementById("iFrameForActions").src = url;
}

function saveInSession(name,value) {
	getHTML("saveInSession?name=" + name + "&value=" + value);
}

//V8.3 FDV "Refonte Graphique Part1" bnp med it/NJG
//ajout des fonctions mootools
function decendreLC() {
	lcEtat="o";
	document.getElementById('Local').style.cursor="default";
	document.getElementById('Local').style.background="#FFFFFF";
	
	var LCSlide = new Fx.Slide('LocalContact',{duration:1000});
	LCSlide.slideIn();
}

function remonterLC() {
	lcEtat="f";
	document.getElementById('Local').style.cursor="pointer";
	document.getElementById('Local').style.background="#D2E0E6";
	
	var LCSlide = new Fx.Slide('LocalContact',{duration:1000});
		LCSlide.slideOut();
	
	if(rlcEtat == "o") remonterRLC();
}

function decendrePC() {
	pcEtat="o";
	document.getElementById('Product').style.cursor="default";
	document.getElementById('Product').style.background="#FFFFFF";
	
	var LCSlide = new Fx.Slide('ProductContact',{duration:1000});
	LCSlide.slideIn();
}

function remonterPC() {
	pcEtat="f";
	document.getElementById('Product').style.cursor="pointer";
	document.getElementById('Product').style.background="#D2E0E6";
	
	var LCSlide = new Fx.Slide('ProductContact',{duration:1000});
	LCSlide.slideOut();
	
	if(rpcEtat == "o")remonterRPC();
}

function decendreRLC() {
	rlcEtat = "o";
	document.getElementById('LocalContactResult').style.display="block";
	var Slide = new Fx.Slide('LocalContactResult');
	Slide.slideIn();
}

function decendreRPC() {
	rpcEtat = "o";
	document.getElementById('ProductContactResult').style.display="block";
	var Slide = new Fx.Slide('ProductContactResult');
	Slide.slideIn();
}

function remonterRLC() {
	rlcEtat = "f";
	var Slide = new Fx.Slide('LocalContactResult',{duration:1000});
	Slide.slideOut();
}


function remonterRPC() {
	rpcEtat = "f";
	var Slide = new Fx.Slide('ProductContactResult',{duration:1000});
	Slide.slideOut();
}

function cacherRLC() {
	var Slide = new Fx.Slide('LocalContactResult');
	Slide.hide();
}

function cacherRPC() {
	var Slide = new Fx.Slide('ProductContactResult');
	Slide.hide();
}

function afficherLC(){
	if (lcEtat=="f")decendreLC();
	if (pcEtat=="o")remonterPC();
}

function afficherPC(){
	if (pcEtat=="f")decendrePC();
	if (lcEtat=="o")remonterLC();
}

//fin ajout des fonctions mootools
//V8.3 FDV "Refonte Graphique Part1" bnp med it/NJG


