

function getNextSibling(startBrother) {

    endBrother = startBrother.nextSibling;

    while (endBrother.nodeType != 1) {

        endBrother = endBrother.nextSibling;

    }

    return endBrother;

}



function abrirSeleccionado(div_seleccionado, div_desplegar) {

    if (!document.getElementById) return false;

    var id = div_seleccionado.getAttribute('id');

    var nivel = div_seleccionado.className.substring(11, 10)

    var fila = document.getElementById(div_desplegar);

    var filaActiva = document.getElementById(id);

    var filaActivaHermano = getNextSibling(filaActiva.firstChild);

    $("#" + id).removeAttr("onclick");

    if (fila != null) {

        if ($(fila).is(":hidden")) {

            //$(fila).slideDown("fast");

            $(fila).show();



            filaActivaHermano.className = "MEN_desplegar_" + nivel + "_ON";

            filaActiva.className = "MEN_seleccionado_" + nivel + "_ACTIVO";

            filaActiva.firstChild.className = "MEN_vineta_" + nivel + "_ACTIVO";

            $(filaActiva).unbind('mouseover');

            $(filaActiva).unbind('mouseout');

        }

    } else {

        filaActiva.className = "MEN_nivel_" + nivel + "_OVER2";

        $(filaActiva).hover(MenuEstadoQuery1, MenuEstadoQuery2);

    }

}


function cambiarDisplay(div_seleccionado, div_desplegar) {



    if (!document.getElementById) return false;

    var id = div_seleccionado.getAttribute('id');

    var nivel = div_seleccionado.className.substring(11, 10)

    var fila = document.getElementById(div_desplegar);

    var filaActiva = document.getElementById(id);

    var filaActivaHermano = getNextSibling(filaActiva.firstChild);



    if (fila != null) {

        if ($(fila).is(":hidden")) {

            //$(fila).slideDown("fast");

            $(fila).show();



            filaActivaHermano.className = "MEN_desplegar_" + nivel + "_ON";

            //alert("mostrar -> "+filaActivaHermano.className)

            filaActiva.className = "MEN_nivel_" + nivel + "_ACTIVO";

            filaActiva.firstChild.className = "MEN_vineta_" + nivel + "_ACTIVO";

            $(filaActiva).bind('mouseover', MenuEstadoActivo1).bind('mouseout', MenuEstadoActivo2);

        } else {

            $(fila).hide();

            //$(fila).slideUp("fast");

            filaActivaHermano.className = "MEN_desplegar_" + nivel + "_OFF";

            filaActiva.firstChild.className = "MEN_vineta_" + nivel + "_OVER";

            $(filaActiva).unbind('mouseover');

            $(filaActiva).unbind('mouseout');

            $(filaActiva).bind('mouseover', MenuEstadoOver).bind('mouseout', MenuEstadoOut);

            $(filaActiva).filter(function() {
                var estado = this.className.slice(-1);

                var nivel = this.className.substring(11, 10);

                if (estado == "T") { estado = "" };

                if (estado == "O") { estado = "" };

                if (estado == "R") { estado = "" };

                this.firstChild.className = "MEN_vineta_" + nivel + "_OVER";

                this.className = "MEN_nivel_" + nivel + "_OVER" + estado;

            })

        }

    } else {

        filaActiva.className = "MEN_nivel_" + nivel + "_OVER2";

        $(filaActiva).hover(MenuEstadoQuery1, MenuEstadoQuery2);

    }

}




function MenuEstadoQuery1() {

    var nivel = this.className.substring(11, 10);

    this.className = "MEN_nivel_" + nivel + "_OVER2";

    this.firstChild.className = "MEN_vineta_" + nivel + "_OVER";

}



function MenuEstadoQuery2() {

    var nivel = this.className.substring(11, 10);

    this.className = "MEN_nivel_" + nivel + "_OVER2";

    this.firstChild.className = "MEN_vineta_" + nivel + "_OVER";

}



function MenuEstadoActivo1() {

    var nivel = this.className.substring(11, 10);

    this.className = "MEN_nivel_" + nivel + "_ACTIVO";

    this.firstChild.className = "MEN_vineta_" + nivel + "_ACTIVO";

}



function MenuEstadoActivo2() {

    var nivel = this.className.substring(11, 10);

    this.className = "MEN_nivel_" + nivel + "_ACTIVO";

    this.firstChild.className = "MEN_vineta_" + nivel + "_ACTIVO";

}



function MenuEstadoOver() {

    var estado = this.className.slice(-1);

    var nivel = this.className.substring(11, 10);

    if (estado == "T") { estado = "" };

    if (estado == "O") { estado = "" };

    if (estado == "R") { estado = "" };

    this.firstChild.className = "MEN_vineta_" + nivel + "_OVER";

    this.className = "MEN_nivel_" + nivel + "_OVER" + estado;

}



function MenuEstadoOut() {

    var estado = this.className.slice(-1);

    var nivel = this.className.substring(11, 10);

    if (estado == "T") { estado = "" };

    if (estado == "R") { estado = "" };

    if (estado == "O") { estado = "" };

    this.firstChild.className = "MEN_vineta_" + nivel + "_OUT";

    this.className = "MEN_nivel_" + nivel + "_OUT" + estado;

}





function EnlaceMenuPricipal(url, target) {

    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 ExpandTreeMagic(variable) {

    try {

        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";

                    abrirSeleccionado(e, 'MEN_N1_' + e.getAttribute('id').substring(4));

                    abrirSeleccionado(e, 'MEN_N1_' + e.getAttribute('id').substring(4));

                }

                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) {

                        abrirSeleccionado(div, 'MEN_N1_' + id_nivel0, 0);

                        abrirSeleccionado(e, 'MEN_N2_' + e.getAttribute('id').substring(4));

                    }

                }

                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) {

                        abrirSeleccionado(div_nivel0, 'MEN_N1_' + id_nivel0);

                        var id_nivel1 = e.parentNode.getAttribute('id').substring(7);

                        var div_nivel1 = document.getElementById('Bot_' + id_nivel1);

                        if (div_nivel1 != null) {

                            abrirSeleccionado(div_nivel1, 'MEN_N2_' + id_nivel1);

                            abrirSeleccionado(e, 'MEN_N3_' + e.getAttribute('id').substring(4));

                        }

                    }

                }

                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);

                        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);

                            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);

                                cambiarDisplay(e, 'MEN_N4_' + e.getAttribute('id').substring(4));

                            }

                        }

                    }

                }

                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);

                        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);

                            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);

                                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);

                                    cambiarDisplay(e, 'MEN_N5_' + e.getAttribute('id').substring(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);

                        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);

                            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);

                                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);

                                    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);

                                        cambiarDisplay(e, 'MEN_N6_' + e.getAttribute('id').substring(4));

                                    }



                                }

                            }

                        }

                    }

                }

                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);

                        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);

                            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);

                                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);

                                    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);

                                        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);

                                            cambiarDisplay(e, 'MEN_N7_' + e.getAttribute('id').substring(4));

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

                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);

                        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);

                            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);

                                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);

                                    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);

                                        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);

                                            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);

                                                cambiarDisplay(e, 'MEN_N8_' + e.getAttribute('id').substring(4));

                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

                //.....

            }

        }

    }

    catch (er) {

        alert(er.message);

    }

}



function desabilitaFuncion(obj) {

    obj.onclick = new Function('return false;' + obj.onclick.toString().getFuncBody())

}



function habilitaFuncion(obj) {

    //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;

} 





