function init() {
	montre('');
}

function active_menu() {
	if (window.ACTIVE_OBJ) {
		var o_current = document.getElementById(window.ACTIVE_OBJ);
		var current = getAbsolutePos(o_current);
		var EX1 = current.x;
		var EX2 = o_current.offsetWidth + EX1;
		var EY1 = current.y;
		var EY2 = o_current.offsetHeight + EY1;
		if (EX1 < xMousePos && xMousePos < EX2 && EY1 < yMousePos && yMousePos < EY2) {
			return false;
		}
	}
	return true;
}

function montre(id) {
	for (var i = 0; i<=21; i++) {
		if (document.getElementById('smenu_adh'+i)) {
			document.getElementById('smenu_adh'+i).style.display='none';
		}
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
		if (document.getElementById('menu_adh'+i)) {
			document.getElementById('menu_adh'+i).style.backgroundColor=document.getElementById('menu_adh').style.backgroundColor;
		}
		if (document.getElementById('menu'+i)) {
			document.getElementById('menu'+i).style.backgroundColor=document.getElementById('menu').style.backgroundColor;
		}
	}
	if (id) {
		var d = document.getElementById(id);
		if (d) {
			d.style.display='block';
			window.ACTIVE_OBJ = id;
		}
	}
}
ACTIVE_OBJ = '';

function findObj_test_forcer(n, forcer) { 
	var p,i,x;
	// Voir si on n'a pas deja memoriser cet element
	if (memo_obj[n] && !forcer) {
		return memo_obj[n];
	}

	d = document; 
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p+1)].document; 
		n = n.substring(0,p);
	}
	if(!(x = d[n]) && d.all) {
		x = d.all[n]; 
	}
	for (i = 0; !x && i<d.forms.length; i++) {
		x = d.forms[i][n];
	}
	for(i=0; !x && d.layers && i<d.layers.length; i++) x = findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n); 

	// Memoriser l'element
	memo_obj[n] = x;

	return x;
}

function findObj(n) { 
	return findObj_test_forcer(n, false);
}

// findObj sans memorisation de l'objet - avec Ajax, les elements se deplacent dans DOM
function findObj_forcer(n) { 
	return findObj_test_forcer(n, true);
}

function changeclass(layer, myClass) { 
	objet = findObj(layer);
	if (!objet) return;
	objet.className = myClass;
}

function afficher_mois() {
	mois = findObj_forcer("selection-mois").mois.value;
	annee = findObj_forcer("selection-mois").annee.value;
	
	date = annee + "-" + mois + "-1";
	window.location.href='spip.php?page=agenda&date='+date;
}

function getAbsolutePos(el) {
 var SL = 0, ST = 0;
 var is_div = /^div$/i.test(el.tagName);
 if (is_div && el.scrollLeft)
  SL = el.scrollLeft;
 if (is_div && el.scrollTop)
  ST = el.scrollTop;
 var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
 if (el.offsetParent) {
  var tmp = getAbsolutePos(el.offsetParent);
  r.x += tmp.x;
  r.y += tmp.y;
 }
 return r;
};

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}
