function initPage(messageToPrintAfterDisplayPage) {
	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 setFrameHeight() {
	if (document.getElementById("frame")) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 100) {
			var headerHeight = (document.getElementById("header"))?document.getElementById("header").clientHeight:0;
			var footerHeight = (document.getElementById("footer"))?document.getElementById("footer").clientHeight:0;
			document.getElementById("frame").style.height = (windowHeight - headerHeight - footerHeight) + "px";
			if (document.getElementById("menu")) {
				document.getElementById("menu").style.height = (windowHeight - headerHeight - footerHeight) + "px";
			}
		}
	}
}

function showHideNavigation(divId) {
	if (document.getElementById(divId)) {
		if (document.getElementById("img_" + divId).src.substring(document.getElementById("img_" + divId).src.length - 19) == "arrow_collapsed.gif") {
			document.getElementById("child_" + divId).style.display = "block";
			document.getElementById("img_" + divId).src = "images/arrow_expanded.gif";
		} else {
			document.getElementById("child_" + divId).style.display = "none";
			document.getElementById("img_" + divId).src = "images/arrow_collapsed.gif";
		}
	}
}

function clickOnMultiSelectCheckbox(checkbox) {
	var elements = document.getElementsByName(checkbox.id);
	var defaultCheck = checkbox.checked;
	for (i = 0 ; i < elements.length ; i++) {
		elements[i].checked = defaultCheck;
	}
}

function getSelectedCheckboxValues(checkboxName) {
	var elements = document.getElementsByName(checkboxName);
	var values = new Array();
	for (i = 0 ; i < elements.length ; i++) {
		if (elements[i].checked)
			values[values.length] = elements[i].value;
	}
	return values;
}

function getSelectedComboboxValue(comboboxName) {
	var elements = document.getElementsByName(comboboxName);
	for (m = 0; m < elements[0].options.length; m++){
		if (elements[0].options[m].selected) {
			return elements[0].options[m].value;
		}
	}
	return "";
}

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 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 refreshPanier() {
	document.getElementById("panier").innerHTML = getHTML("controller?form-name=Id&action-name=panier.DisplayMiniPanier");
}

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);
}

function openMenuSpan(elt, id) {
	var myVerticalSlide = new Fx.Slide("MenuUL" + id);
	if (elt.alt == "Ouvrir") {
		elt.src = "images/interface/puceMoins.png";
		elt.alt = "Fermer";
		$("MenuUL" + id).style.display = 'block';
	} else {
		elt.src = "images/interface/pucePlus.png";
		elt.alt = "Ouvrir";
		$("MenuUL" + id).style.display = 'none';
	}
}