function MENU_getElementsByClassName(container, tagname, classname) {
	if(typeof(classname) == 'undefined') classname = '*';
	var result = new Array();
	var subs = container.getElementsByTagName(tagname);
	for(var i=0;i<subs.length;i++) {
		if((classname == '*') || (subs[i].className == classname)) result.push(subs[i]);
	}
	return result;
}

function MENU_getChildrenByClassName(container, tagname, classname) {
	if(typeof(classname) == 'undefined') classname = '*';
	var result = new Array();
	var subs = container.childNodes
	for(var i=0;i<subs.length;i++) {
		if(isSameTagName(subs[i].tagName, tagname)) {
			if((classname == '*') || (subs[i].className == classname)) result.push(subs[i]);
		}
	}
	return result;
}

//find the left,top position of an object
function MENU_findPos(obj) {
	var obj0 = obj;
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop,curleft+obj0.offsetWidth,curtop+obj0.offsetHeight];
}

var lastmenu = null;
var lastref = null;

function montre(ref,targetid) {
	//alert(ref.className + ":" + ref.offsetWidth);
	
	//adjusts the ref's background image if necessary
	if(lastref && lastmenu) {
		lastref.style.backgroundImage="url(bordures/menu_inactive.gif)";
	}
	
	if(lastmenu) {
		lastmenu.style.display="none";
	}

	var d = document.getElementById(targetid);		
	if(d) {
		var t = document.getElementById('menutop');
		var dpos = MENU_findPos(ref);
		var tpos = MENU_findPos(t);
		d.style.width = (tpos[2]-dpos[0]).toString(10)+"px";
		//d.style.top = (dpos[1]+ref.offsetHeight).toString(10)+"px";
		//d.style.left = (dpos[0]).toString(10)+"px";
		d.style.display='block';
		lastmenu = d;
	}
	else {
		lastmenu = null;
	}
	
	//ref.style.backgroundImage="url(bordures/menu_selected.gif)";
	ref.style.backgroundImage="none";
	lastref = ref;
}

function out(ref) {
	if(lastmenu) return;
	ref.style.backgroundImage="url(bordures/menu_inactive.gif)";
	lastref = null;
}

function nil() {
}

function popupwin(url,w,h) {
	var newwindow = window.open(url,'name','height='+h+',width='+w+',scrollbars=yes,resizable=yes,menubar=no,location=no,directories=no,status=no');
	if (window.focus) {
		newwindow.focus();
	}
	return false; //won't follow href
}
