﻿function InicializaOpciones(iJSON) {
    if (iJSON != null) {
        var oJSON = eval(iJSON);
        if (oJSON.length > 0) {
            for (x = 0; x < oJSON.length; x++) {
                $("#menu").append("<div class='opcion' id='opc" + (x + 1) + "'><p>" + oJSON[x].Opcion + "</p></div>");
                $("#opc" + (oJSON[x].ID)).click(function () {
                    EjecutaAJAX("PaginaDat.aspx", "MuestraContenido", "{'OpcID':" + this.id.replace("opc", "") + ",'ID':0}", "DespliegaContenido(msg.d)");
                });
            }
            BuscaContenido(1);
        }
    }
}

function BuscaContenido(iID) {
    EjecutaAJAX("PaginaDat.aspx", "MuestraContenido", "{'OpcID':0,'ID':" + iID + "}", "DespliegaContenido(msg.d)");
}

function DespliegaContenido(iJSON) {
    
    $("#TemaAnt").hide();
    $("#TemaSig").hide();
    $("#TemaAnt").unbind('click');
    $("#TemaSig").unbind('click');

    if (iJSON != null) {
        var oJSON = eval("[" + iJSON + "]");
        if (oJSON.length > 0) {
            $("#TituloH1").text(oJSON[0].Opcion);
            $("#TituloH2").text(oJSON[0].Titulo);
            $("#articulo").html(oJSON[0].Descripcion);
            if (oJSON[0].TituloAnterior != undefined && oJSON[0].TituloAnterior != "") {
                $("#TemaAnt").html("<div class='flecha1'></div>" + oJSON[0].TituloAnterior);
                $("#TemaAnt").show();
                $("#TemaAnt").click(function () { BuscaContenido(oJSON[0].TituloAnteriorID); });
            }
            if (oJSON[0].TituloSiguiente != undefined && oJSON[0].TituloSiguiente != "") {
                $("#TemaSig").html(oJSON[0].TituloSiguiente + "<div class='flecha2'></div>");
                $("#TemaSig").show();
                $("#TemaSig").click(function () { BuscaContenido(oJSON[0].TituloSiguienteID); });
            }
            $(".LinkID").click(function () { BuscaContenido(parseInt(this.id)); });
        }
    }

}

function DespliegaEstadistica(iJSON) {
    if (iJSON != null) {
        var oJSON = eval("[" + iJSON + "]");
        if (oJSON.length > 0) {
            $("#Estadistica").text(oJSON[0].Visitas + " Visitas")
        }
    }
    EjecutaAJAX("PaginaDat.aspx", "ListarOpciones", null, "InicializaOpciones(msg.d)");
}

$(document).ready(function () {

    var userAgent = navigator.userAgent.toLowerCase();
    var cNav = "";

    jQuery.browser = {
        version: (userAgent.match(/.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/) || [])[1],
        chrome: /chrome/.test(userAgent),
        safari: /webkit/.test(userAgent) && !/chrome/.test(userAgent),
        opera: /opera/.test(userAgent),
        msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
        mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
    };

    if (jQuery.browser.webkit) {
        cNav = "WebKit";
    }
    if (jQuery.browser.msie) {
        cNav = "Internet Explorer";
    }
    if (jQuery.browser.mozilla) {
        cNav = "Firefox";
    }
    if (jQuery.browser.chrome) {
        cNav = "Google Chrome";
    }
    if (jQuery.browser.safari) {
        cNav = "Safari";
    }
    if (jQuery.browser.opera) {
        cNav = "Opera";
    }
    EjecutaAJAX("PaginaDat.aspx", "RegistraEstadistica", "{'Navegador':'" + cNav + "', 'Version':'" + jQuery.browser.version + "'}", "DespliegaEstadistica(msg.d)");

});

