/*
	____________________________________________________________________
	
	Menus.js

	· Funciones gestión de menus Web (menu principal)
	____________________________________________________________________

*/


// ____________________________________

function InStr(n, s1, s2)
{
    // Devuelve la posición de la primera ocurrencia de s2 en s1
    // Si se especifica n, se empezará a comprobar desde esa posición
    // Sino se especifica, los dos parámetros serán las cadenas

    var numargs=InStr.arguments.length;
    
    if(numargs < 3)
        return n.indexOf(s1)+1;
    else
        return s1.indexOf(s2, n)+1;
}


// ____________________________________



// para menu web
var timerMenuWeb;
var timerMenuWebTodos;

// para menu utils
var timerMenuUtils;
var timerMenuUtilsTodos;

// para todos
var kIntervalo;
kIntervalo = 800;


/*

	Parámetro vRuta:
	
	Hay que indicar la ruta: 


		"<idMenu último>|<idMenu superior>|<idMenu superior>|<...>|0"
		
	es decir, los Ids del registro de Menus desde la última rama hasta el menu padre (el de antes del "0")

*/

function mostrarSubMenuIntervalo(vRuta, vToken)
{
    
    if (InStr(vToken,"Web") != 0) {
        timerMenuWeb = setInterval("mostrarSubMenu('" + vRuta + "','" + vToken + "')", kIntervalo);

    }

    if (InStr(vToken,"Utils") != 0) {
        timerMenuUtils = setInterval("mostrarSubMenu('" + vRuta + "','" + vToken + "')", kIntervalo);
    }

}

// 
function mostrarSubMenu(vRuta, vToken)
{

	var arrRuta= vRuta.split("|");
	var ix;
	var uB;
	
	ocultarSubMenusTodos(vToken);
	
	uB= arrRuta.length-1;
	
	for(ix=uB; ix>=0 ; ix--) {

		if (arrRuta[ix] != "0") {	
		
			if (document.getElementById(vToken + arrRuta[ix])) {
				if (document.getElementById(vToken + arrRuta[ix]).style.display == "none") {
					document.getElementById(vToken + arrRuta[ix]).style.display = "";
				}
			}
		}
	}

	//cortarIntervaloSubMenu(vToken);

}




function cortarIntervaloSubMenu(vToken)
{

    if (InStr(vToken,"Web") != 0) {
		if (timerMenuWeb) {
            clearInterval(timerMenuWeb);
            timerMenuWeb = 0; 
        }
	}
    
    if (InStr(vToken,"Utils") != 0) {
        if (timerMenuUtils) {
            clearInterval(timerMenuUtils);
            timerMenuUtils = 0; 
        }
    }
	
}


function cortarIntervaloSubMenusTodos()
{

//    if (timerMenuWebTodos) {
        
        clearInterval(timerMenuWebTodos);
        timerMenuWebTodos = 0; 
//    }

//    if (timerMenuUtilsTodos) {
        
        clearInterval(timerMenuUtilsTodos);
        timerMenuUtilsTodos = 0; 
//    }
    
}


function ocultarSubMenusIntervalo(vToken)
{
	
    timerMenuWebTodos = setInterval("ocultarSubMenusTodos('MenuWeb')", kIntervalo);
    timerMenuUtilsTodos = setInterval("ocultarSubMenusTodos('MenuUtils')", kIntervalo);
}




function ocultarSubMenusTodos(vToken)
{

	var ix;
	var uB;

    var ocultarDIV = document.getElementsByTagName("table");  //table
    
	uB= ocultarDIV.length-1;
	
    for (i=uB; i >= 0; i--) {
        
        if (ocultarDIV[i].id) {
			
//            if (InStr(ocultarDIV[i].id, vToken) != 0) {
//				document.getElementById(ocultarDIV[i].id).style.display = "none";
//            }

            
            if (InStr(ocultarDIV[i].id, 'MenuWeb') != 0) {
				document.getElementById(ocultarDIV[i].id).style.display = "none";
            }

            if (InStr(ocultarDIV[i].id, 'MenuUtils') != 0) {
				document.getElementById(ocultarDIV[i].id).style.display = "none";
            }


        }
    }	
	
	cortarIntervaloSubMenusTodos();
	
}

// Alterna entre mostrar y ocultar el elemento indicado por vIdMenu
function toggleSubMenu(vIdMenu)
{

    var oElem

    if (document.getElementById(vIdMenu)) {
        
        oElem = document.getElementById(vIdMenu);

        if (oElem.style.display == "") {
            oElem.style.display = "none"
        } else {
            oElem.style.display = ""
        }
    }
}







