// Función que abre o cierra un nodo de menu
function toggle(node) {
	// Recuperamos el nodo de la fila con el menu hijo
	var nodoFila = node.parentNode.parentNode.nextSibling;
	// Recuperamos el Div con el menu hijo
	var nextDIV = nodoFila.firstChild.firstChild;
		
	while(nextDIV.nodeName != "DIV") {
		nextDIV = nextDIV.nextSibling;
	}
	if (nextDIV.style.display == 'none') {
		if (node.childNodes.length > 0) {
			if (node.childNodes.item(0).nodeName == "IMG") {
				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "minus.gif";
			}
		}
		nextDIV.style.display = 'block';
	}
	else {
		if (node.childNodes.length > 0) {
			if (node.childNodes.item(0).nodeName == "IMG") {
					node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "plus.gif";
			}
		}
		nextDIV.style.display = 'none';
	}
}

// Función que recupera el directorio de imagenes
function getImgDirectory(source) {
		return source.substring(0, source.lastIndexOf('/') + 1);
}

var URLParams = new Object() ;
var existeParam_S =false;
var existeParam_M =false;

var aParams = document.location.search.substr(1).split('&');
for (i=0 ; i < aParams.length ; i++)
{
	var aParam = aParams[i].split('=') ;
	URLParams[aParam[0]] = aParam[1] ;
	if (aParam[0] == 'S') existeParam_S=true;
	if (aParam[0] == 'M') existeParam_M=true;
}

function InitMenu(){
	//ponemos el menu seleccionado con otro estilo
	if (existeParam_S) {
		toggle(document.getElementById("M_P" + URLParams['S']));
		document.getElementById("M_P" + URLParams['S']).className ="menuPadreSel";
	}
	
	if (existeParam_M) {
		document.getElementById("M" + URLParams['M']).className ="MenuSel";
	}
}
