var estilo_Nivel0 = new Array("MEN_nivel_0_OUT", "MEN_nivel_0_OVER", "MEN_nivel_0_ACTIVO", "MEN_nivel_0_OUT2", "MEN_nivel_0_OVER2");
var estilo_Nivel1 = new Array("MEN_nivel_1_OUT", "MEN_nivel_1_OVER", "MEN_nivel_1_ACTIVO", "MEN_nivel_1_OUT2", "MEN_nivel_1_OVER2");
var estilo_Nivel2 = new Array("MEN_nivel_2_OUT", "MEN_nivel_2_OVER", "MEN_nivel_2_ACTIVO", "MEN_nivel_2_OUT2", "MEN_nivel_2_OVER2");
var estilo_Nivel3 = new Array("MEN_nivel_3_OUT", "MEN_nivel_3_OVER", "MEN_nivel_3_ACTIVO", "MEN_nivel_3_OUT2", "MEN_nivel_3_OVER2");
var estilo_Nivel4 = new Array("MEN_nivel_4_OUT", "MEN_nivel_4_OVER", "MEN_nivel_4_ACTIVO", "MEN_nivel_4_OUT2", "MEN_nivel_4_OVER2");
var estilo_Nivel5 = new Array("MEN_nivel_5_OUT", "MEN_nivel_5_OVER", "MEN_nivel_5_ACTIVO", "MEN_nivel_5_OUT2", "MEN_nivel_5_OVER2");
var estilo_Nivel6 = new Array("MEN_nivel_6_OUT", "MEN_nivel_6_OVER", "MEN_nivel_6_ACTIVO", "MEN_nivel_6_OUT2", "MEN_nivel_6_OVER2");
var estilo_Nivel7 = new Array("MEN_nivel_7_OUT", "MEN_nivel_7_OVER", "MEN_nivel_7_ACTIVO", "MEN_nivel_7_OUT2", "MEN_nivel_7_OVER2");

var gruposEstilo = new Array(estilo_Nivel0, estilo_Nivel1, estilo_Nivel2, estilo_Nivel3, estilo_Nivel4, estilo_Nivel5, estilo_Nivel6, estilo_Nivel7);


function getNextSibling(startBrother) {
    endBrother = startBrother.nextSibling;
    while (endBrother.nodeType != 1) {
        endBrother = endBrother.nextSibling;
    }
    return endBrother;
}

function cambiarDisplay(div_seleccionado, id_contenedor) {
    if (!document.getElementById) return false;
    var nivel = div_seleccionado.className.substring(11, 10)
    var fila = document.getElementById(id_contenedor);
    var hermano = getNextSibling(div_seleccionado.firstChild);
    if (fila != null) {
        if (fila.style.display != "none") {
            fila.style.display = "none"; //ocultar div
            //alert(1)	        
            Eventos(div_seleccionado, 0);
            hermano.className = 'MEN_desplegar_' + nivel + '_OFF';
            div_seleccionado.onmouseout = function() {
                Eventos(div_seleccionado, 0);
            }
            div_seleccionado.onmouseover = function() {
                Eventos(div_seleccionado, 1);

            }
            alargar(false);
        } else {
            //alert(2)
            fila.style.display = ""; //mostrar div
            Eventos(div_seleccionado, 2);
            hermano.className = 'MEN_desplegar_' + nivel + '_ON';
            //Reducir, Contenedor
            div_seleccionado.onmouseout = function() {
                Eventos(div_seleccionado, 2)
            }

            div_seleccionado.onmouseover = function() {
                Eventos(div_seleccionado, 2)
            }
            alargar(true);
        }

    }
    else {
        Eventos(div_seleccionado, 4)
        div_seleccionado.onmouseout = function() {
            Eventos(div_seleccionado, 4)
        }
        div_seleccionado.onmouseover = function() {
            Eventos(div_seleccionado, 4)
        }

    }
}


function Eventos(div_seleccionado, estado) {

    var nivel = div_seleccionado.className.substring(11, 10)
    var vineta_estado = gruposEstilo[nivel][estado].substring(12);
    //alert("nivel --> "+nivel+"  Estado --> "+estado+"  Viñeta Estado --> "+vineta_estado)
    if (vineta_estado == "OVER2") { vineta_estado = "OVER" };
    if (vineta_estado == "OUT2") { vineta_estado = "OUT" };
    div_seleccionado.className = gruposEstilo[nivel][estado];
    div_seleccionado.firstChild.className = 'MEN_vineta_' + nivel + '_' + vineta_estado;
}

function EnlaceMenuPricipal(url, target) {

    if (url.toString() == '') {
        return;
    }
    if (url.toString().indexOf("JER_interna.ascx") == 0) {
        return;
    }
    //alert(url.toString().indexOf("APS_TOOLS"));
    /*if (url.toString().indexOf("/APS_Tools/") == "-1") {
    return;
    }*/
    target = target.toLowerCase();
    if (target == '_blank') window.open(url);
    if (target == '_self') self.location.href = url;
    if (target == '_top') top.location.href = url;
    if (target == '_parent') parent.location.href = url;

}
function EnlaceMenu(url, target) {

    if (url.toString() == '') {
        return;
    }
    target = target.toLowerCase();
    if (target == '_blank') window.open(url);
    else if (target == '_self') self.location.href = url;
    else if (target == '_top') top.location.href = url;
    else if (target == '_parent') parent.location.href = url;
    else window.location.href = url;

}


function desabilitaFuncion(obj) {
    //alert('desabilita');
    obj.onclick = new Function('return false;' + obj.onclick.toString().getFuncBody())
}

function habilitaFuncion(obj) {
    //alert('habilita');
    //alert(obj.onclick.toString().getFuncBody());
    if (!obj.onclick.toString().indexOf("return false;") != -1) {
        strClick = obj.onclick.toString().getFuncBody().replace("return false;", "")
        obj.onclick = new Function(strClick);
    }
}

String.prototype.getFuncBody = function() {
    var str = this.toString();
    str = str.replace(/[^{]+{/, "");
    str = str.substring(0, str.length - 1);
    str = str.replace(/\n/gi, "");
    if (!str.match(/\(.*\)/gi)) str += ")";
    return str;
}


function ExpandTreeMagic(variable) {
    try {

        var vstr_docHref = document.location.pathname;

        // alert(vstr_docHref.indexOf('/JER/'));
        // alert(vstr_docHref.indexOf('/PAR/'));

        //Esconder el menú al inicio para todos
        //document.getElementById('ctl00_div_MenuIzq').style.display = "none";
        var Posicion = 0;
        if (vstr_docHref.indexOf('/0/') != -1) {
            if (document.getElementById('Bot_1') != null) {
                document.getElementById('ctl00_div_MenuIzq').style.display = "";
                if (document.getElementById('Bot_1').className == "MEN_nivel_0_ACTIVO") {
                    //alert(1)
                    Posicion = 1;
                    document.getElementById('Bot_2').style.display = "none";
                    document.getElementById('Bot_4').style.display = "none";
                    if (document.getElementById('Bot_158') != null)
                        Posicion = 1;
                    //alert("1.1")
                    document.getElementById('Bot_158').style.display = "none";
                    return;

                }

                if (document.getElementById('Bot_2').className == "MEN_nivel_0_ACTIVO") {
                    document.getElementById('Bot_1').style.display = "none";
                    document.getElementById('Bot_4').style.display = "none";
                    //alert("2")
                    Posicion = 1;
                    if (document.getElementById('Bot_158') != null)
                    //alert("2.2")
                        Posicion = 1;
                    document.getElementById('Bot_158').style.display = "none";
                    return;
                }

                if (document.getElementById('Bot_4').className == "MEN_nivel_0_ACTIVO") {
                    //alert("3")
                    Posicion = 1;
                    document.getElementById('Bot_2').style.display = "none";
                    document.getElementById('Bot_1').style.display = "none";
                    if (document.getElementById('Bot_158') != null)
                    //alert("3.3")
                        Posicion = 1;
                    document.getElementById('Bot_158').style.display = "none";
                    return;
                }
                if (document.getElementById('Bot_158') != null) {
                    //alert("4")

                    Posicion = 1;
                    if (document.getElementById('Bot_158').className == "MEN_nivel_0_ACTIVO") {
                        //alert("4.4")
                        Posicion = 1;
                        document.getElementById('Bot_2').style.display = "none";
                        document.getElementById('Bot_4').style.display = "none";
                        document.getElementById('Bot_1').style.display = "none";
                        return;
                    }
                    else {
                        document.getElementById('ctl00_div_MenuIzq').style.display = "none";
                    }

                    if (Posicion == 0) {

                        document.getElementById('ctl00_div_MenuIzq').style.display = "none";
                    }
                }





                if (Posicion == 0) {
                    document.getElementById('ctl00_div_MenuIzq').style.display = "none";
                }

            }
            else {
                //alert(2)

            }
        }

        var regexS = "[\\?&]" + variable + "=([^&#]*)";
        var valor = "";
        var regex = new RegExp(regexS);
        var tmpURL = window.location.href;
        var results = regex.exec(tmpURL);
        if (results == null)
            valor = "";
        else
            valor = "Bot_" + results[1];

        var classnamejer;
        if (document.getElementById) {
            e = document.getElementById(valor);
            if (e != null) {
                classnamejer = e.className;
                //alert(classnamejer);
                if (classnamejer == 'MEN_nivel_0_OUT' || classnamejer == 'MEN_nivel_0_OUT2') {
                    e.className = "MEN_nivel_0_OVER2";
                    //cambiarDisplay(e,'MEN_N1_'+e.getAttribute('id').substring(4),0);
                    cambiarDisplay(e, 'MEN_N1_' + e.getAttribute('id').substring(4), 0);
                }
                if (classnamejer == 'MEN_nivel_1_OUT' || classnamejer == 'MEN_nivel_1_OUT2') {
                    var id_nivel0 = e.parentNode.getAttribute('id').substring(7);
                    var div = document.getElementById('Bot_' + id_nivel0);
                    if (div != null) {
                        cambiarDisplay(div, 'MEN_N1_' + id_nivel0, 0);
                        cambiarDisplay(e, 'MEN_N2_' + e.getAttribute('id').substring(4), 1);
                    }
                }
                if (classnamejer == 'MEN_nivel_2_OUT' || classnamejer == 'MEN_nivel_2_OUT2') {
                    var id_nivel0 = e.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            cambiarDisplay(e, 'MEN_N3_' + e.getAttribute('id').substring(4), 2);
                        }
                    }
                }
                if (classnamejer == 'MEN_nivel_3_OUT' || classnamejer == 'MEN_nivel_3_OUT2') {
                    var id_nivel0 = e.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            var id_nivel2 = e.parentNode.getAttribute('id').substring(7);
                            var div_nivel2 = document.getElementById('Bot_' + id_nivel2);
                            if (div_nivel2 != null) {
                                cambiarDisplay(div_nivel2, 'MEN_N3_' + id_nivel2, 2);
                                cambiarDisplay(e, 'MEN_N4_' + e.getAttribute('id').substring(4), 3);
                            }
                        }
                    }
                }
                if (classnamejer == 'MEN_nivel_4_OUT' || classnamejer == 'MEN_nivel_4_OUT2') {
                    var id_nivel0 = e.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            var id_nivel2 = e.parentNode.parentNode.getAttribute('id').substring(7);
                            var div_nivel2 = document.getElementById('Bot_' + id_nivel2);
                            if (div_nivel2 != null) {
                                cambiarDisplay(div_nivel2, 'MEN_N3_' + id_nivel2, 2);
                                var id_nivel3 = e.parentNode.getAttribute('id').substring(7);
                                var div_nivel3 = document.getElementById('Bot_' + id_nivel3);
                                if (div_nivel3 != null) {
                                    cambiarDisplay(div_nivel3, 'MEN_N4_' + id_nivel3, 3);
                                    cambiarDisplay(e, 'MEN_N5_' + e.getAttribute('id').substring(4), 4);
                                }
                            }
                        }
                    }
                }
                if (classnamejer == 'MEN_nivel_5_OUT' || classnamejer == 'MEN_nivel_5_OUT2') {
                    var id_nivel0 = e.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            var id_nivel2 = e.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                            var div_nivel2 = document.getElementById('Bot_' + id_nivel2);
                            if (div_nivel2 != null) {
                                cambiarDisplay(div_nivel2, 'MEN_N3_' + id_nivel2, 2);
                                var id_nivel3 = e.parentNode.parentNode.getAttribute('id').substring(7);
                                var div_nivel3 = document.getElementById('Bot_' + id_nivel3);
                                if (div_nivel3 != null) {
                                    cambiarDisplay(div_nivel3, 'MEN_N4_' + id_nivel3, 3);
                                    var id_nivel4 = e.parentNode.getAttribute('id').substring(7);
                                    var div_nivel4 = document.getElementById('Bot_' + id_nivel4);
                                    if (div_nivel4 != null) {
                                        cambiarDisplay(div_nivel4, 'MEN_N5_' + id_nivel4, 4);
                                        cambiarDisplay(e, 'MEN_N6_' + e.getAttribute('id').substring(4), 5);
                                    }

                                }
                            }
                        }
                    }
                }
                if (classnamejer == 'MEN_nivel_6_OUT' || classnamejer == 'MEN_nivel_6_OUT2') {
                    var id_nivel0 = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            var id_nivel2 = e.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                            var div_nivel2 = document.getElementById('Bot_' + id_nivel2);
                            if (div_nivel2 != null) {
                                cambiarDisplay(div_nivel2, 'MEN_N3_' + id_nivel2, 2);
                                var id_nivel3 = e.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                                var div_nivel3 = document.getElementById('Bot_' + id_nivel3);
                                if (div_nivel3 != null) {
                                    cambiarDisplay(div_nivel3, 'MEN_N4_' + id_nivel3, 3);
                                    var id_nivel4 = e.parentNode.parentNode.getAttribute('id').substring(7);
                                    var div_nivel4 = document.getElementById('Bot_' + id_nivel4);
                                    if (div_nivel4 != null) {
                                        cambiarDisplay(div_nivel4, 'MEN_N5_' + id_nivel4, 4);
                                        var id_nivel5 = e.parentNode.getAttribute('id').substring(7);
                                        var div_nivel5 = document.getElementById('Bot_' + id_nivel5);
                                        if (div_nivel5 != null) {
                                            cambiarDisplay(div_nivel5, 'MEN_N6_' + id_nivel5, 5);
                                            cambiarDisplay(e, 'MEN_N7_' + e.getAttribute('id').substring(4), 6);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (classnamejer == 'MEN_nivel_7_OUT' || classnamejer == 'MEN_nivel_7_OUT2') {
                    //		                    alert(e.getAttribute('id'));
                    var id_nivel0 = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                    var div_nivel0 = document.getElementById('Bot_' + id_nivel0);
                    if (div_nivel0 != null) {
                        cambiarDisplay(div_nivel0, 'MEN_N1_' + id_nivel0, 0);
                        var id_nivel1 = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);
                        if (div_nivel1 != null) {
                            cambiarDisplay(div_nivel1, 'MEN_N2_' + id_nivel1, 1);
                            var id_nivel2 = e.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                            var div_nivel2 = document.getElementById('Bot_' + id_nivel2);
                            if (div_nivel2 != null) {
                                cambiarDisplay(div_nivel2, 'MEN_N3_' + id_nivel2, 2);
                                var id_nivel3 = e.parentNode.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                                var div_nivel3 = document.getElementById('Bot_' + id_nivel3);
                                if (div_nivel3 != null) {
                                    cambiarDisplay(div_nivel3, 'MEN_N4_' + id_nivel3, 3);
                                    var id_nivel4 = e.parentNode.parentNode.parentNode.getAttribute('id').substring(7);
                                    var div_nivel4 = document.getElementById('Bot_' + id_nivel4);
                                    if (div_nivel4 != null) {
                                        cambiarDisplay(div_nivel4, 'MEN_N5_' + id_nivel4, 4);
                                        var id_nivel5 = e.parentNode.parentNode.getAttribute('id').substring(7);
                                        var div_nivel5 = document.getElementById('Bot_' + id_nivel5);
                                        if (div_nivel5 != null) {
                                            cambiarDisplay(div_nivel5, 'MEN_N6_' + id_nivel5, 5);
                                            var id_nivel6 = e.parentNode.getAttribute('id').substring(7);
                                            var div_nivel6 = document.getElementById('Bot_' + id_nivel6);
                                            if (div_nivel6 != null) {
                                                cambiarDisplay(div_nivel6, 'MEN_N7_' + id_nivel6, 6);
                                                cambiarDisplay(e, 'MEN_N8_' + e.getAttribute('id').substring(4), 7);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //.....
            }
        }

    }
    catch (er) {
        //alert(er.message);
    }
}