function show(ID) {
	if(document.getElementById(ID))
		document.getElementById(ID).style.display = "block";
}

function mask(ID) {
	if(document.getElementById(ID))
		document.getElementById(ID).style.display = "none";
}

function toggle_view(ID) {
	if(document.getElementById(ID)) {
		if(document.getElementById(ID).style.display == "none")
			document.getElementById(ID).style.display = "block";
		else
			document.getElementById(ID).style.display = "none";
	}
}





function placeMenu(IDmenu, elementToPlace) {
	if(document.getElementById(elementToPlace) && document.getElementById(IDmenu)) {
		var a   = new Object();
		var aPos= new Object();
		var bPos= new Object();

		args = placeMenu.arguments;

		aPos = getSize(document.getElementById(IDmenu));
		bPos = getSize(document.getElementById(elementToPlace));

		//var align	= (args[2]!=null ? args[2] : "left");
		var offsetX	=  0		+ (args[2]!=null ? args[2] : 0);
		var offsetY	= bPos.h	+ (args[3]!=null ? args[3] : 0);
		//offsetY ++;
		var align	=			  (args[4]!=null ? args[4] : "left");
		
		if(align=="right")
			offsetX -= aPos.w - bPos.w;

		a = getPosition(document.getElementById(elementToPlace));
		document.getElementById(IDmenu).style.left = eval(a.x) + offsetX;
		document.getElementById(IDmenu).style.top = eval(a.y) + offsetY;
	}
}


// Retourne la position de l'objet envoyé en paramètre
function getPosition(element) {
	var elem=element, tagname="", x=0, y=0;
  
	while ((typeof(elem)=="object") && (typeof(elem.tagName)!="undefined")) {
		y+=elem.offsetTop;
		x+=elem.offsetLeft;
		tagname=elem.tagName.toUpperCase();

		if(tagname=="BODY")
			elem=0;

		if(typeof(elem)=="object")
			if (typeof(elem.offsetParent)=="object")
				elem=elem.offsetParent;
	}

	position = new Object();
	position.x = x;
	position.y = y;
	return position;
}




// Retourne la taille de l'objet envoyé en paramètre
function getSize(element) {
	var elem=element, /*tagname="", */w=0, h=0;

//	while ((typeof(elem)=="object") && (typeof(elem.tagName)!="undefined")) {
//		alert(elem.offsetWidth);

		w+=elem.offsetWidth;
		h+=elem.offsetHeight;
//		tagname=elem.tagName.toUpperCase();
/*
		if(tagname=="BODY")
			elem=0;

		if(typeof(elem)=="object")
			if (typeof(elem.offsetParent)=="object")
				elem=elem.offsetParent;
*/
//	}

	position = new Object();
	position.w = w;
	position.h = h;
	return position;
}





function getWindowHeight() {
	var windowHeight = 0;
	if(typeof(window.innerHeight)=='number')
		windowHeight = window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		windowHeight = document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)
		windowHeight = document.body.clientHeight;
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if(typeof(window.innerWidth)=='number')
		windowWidth = window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		windowWidth = document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)
		windowWidth = document.body.clientWidth;
	return windowWidth;
}

function getDocumentHeight() {
	return getWindowHeight();
}
function getDocumentWidth()	{
	return getWindowWidth();
}

















function toggle_MR() {
	ID = "menu_right";
	if(document.getElementById(ID)) {
		if(document.getElementById(ID).style.display == "none") {
			document.getElementById(ID).style.display = "block";
			document.getElementById('msgMR').innerHTML = "MASQUER";
		}
		else {
			document.getElementById(ID).style.display = "none";
			document.getElementById('msgMR').innerHTML = "AFFICHER";
		}
	}
}










/* FONCTIONS STRING */

function setDocumentFromFile(val, ctlDest) {
	// récupère le basename et supprime l'extension de val, et le place dans ctlDest
	if(val.lastIndexOf('\\') != 0)
		val = val.substring(val.lastIndexOf('\\')+1);
	if(val.lastIndexOf('/') != 0)
		val = val.substring(val.lastIndexOf('/')+1);
	
	if(val.lastIndexOf('.') != 0)
		val = val.substring(0, val.lastIndexOf('.'));
	
	document.getElementById(ctlDest).value = val;
}
