﻿// Archivo JScript

jQuery(document).ready(function() {
    jQuery("#mensajeJugador").dialog({autoOpen: false});
});

$(function() {
    $('a.lightbox').lightBox();
});

function Cargando() {
    $.blockUI({theme:true, title:"Actualizando Página", message:"Se están actualizando los datos de la página, espera un momento..."});
}

function MostrarNoticia(id) {
    var idioma = Request.QueryString("lang");
    var url = "noticia.aspx?id=" + Request.QueryString("id") + "&id_noticia=" + id + "&current=1";
    if ("<" + idioma + ">" != "<null>") {
        url = url + "&lang=" + idioma;
    }
    location.href = url;
}
   
function MostrarJugador(id) {
    $.blockUI({theme:true, title:"Obteniendo Datos", message:"Se están cargando los datos del jugador, espera un momento..."});
    $.ajax({
        type: "GET",
        url: "jugador.aspx",
        data: "id_jugador=" + id,
        success: function(html){
                    $("#contenidoJugador").html(html);
                    $.blockUI({theme:true, title:"Datos de un Jugador", message:$('#mensajeJugador'), themedCSS:{width:'500px'}}); 
                    $('#btnOkJugador').click(function() { 
                        $.unblockUI();return false; 
                    });
                },
        error:  function(html){
                    $.unblockUI();return false;
                }
    });
}

function Inicio() {
    /*var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "../index.aspx";
    } else {
        location.href = "../index.aspx?lang=" + idioma;
    }*/
    location.href = "../index.php";
}

function AbrirAvisoLegal() {
    //var mywin = window.open("htm/aviso_legal.htm","nyname");
    location.href='../index.php?page_id=2';
}

function getIFrameDocument(aID) {
    var rv = null; 
    // if contentDocument existe, entonces es compatible con el W3C (Mozilla)
    if (document.getElementById(aID).contentDocument){
	    rv = document.getElementById(aID).contentDocument;
    } else {
    // IE
	    rv = document.frames[aID].document;
    }
    return rv;
}

function setGoogleSearch() {
	var ifrGoogleDocument = getIFrameDocument("ifrGoogle");
    ifrGoogleDocument.getElementById("q").value=document.getElementById("ctl00_hidEquipoName").value;
    ifrGoogleDocument.getElementById("id").value=Request.QueryString("id");
}

function GetWindowWidth() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if( document.body && document.body.clientWidth ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}

function Portada() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "equipo.aspx?id=" + Request.QueryString("id");
    } else {
        location.href = "equipo.aspx?lang=" + idioma + "&id=" + Request.QueryString("id");
    }
}

function Noticias() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "noticias.aspx?id=" + Request.QueryString("id") + "&current=1";
    } else {
        location.href = "noticias.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=1";
    }
}

function Historia() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "historia.aspx?id=" + Request.QueryString("id") + "&current=2";
    } else {
        location.href = "historia.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=2";
    }
}

function Plantilla() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "jugadores.aspx?id=" + Request.QueryString("id") + "&current=3";
    } else {
        location.href = "jugadores.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=3";
    }
}

function Cronicas() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "cronicas.aspx?id=" + Request.QueryString("id") + "&current=4";
    } else {
        location.href = "cronicas.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=4";
    }
}

function Localizanos() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "gmaps.aspx?id=" + Request.QueryString("id") + "&current=5";
    } else {
        location.href = "gmaps.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=5";
    }
}

function Enlaces() {
    var idioma = Request.QueryString("lang");
    if ("<" + idioma + ">" == "<null>") {
        location.href = "enlaces.aspx?id=" + Request.QueryString("id") + "&current=6";
    } else {
        location.href = "enlaces.aspx?lang=" + idioma + "&id=" + Request.QueryString("id") + "&current=6";
    }
}

function doResize() {
    var totalAnchoElementosPagina = 55;
    var contentEscudo = document.getElementById("ctl00_ContentPlaceHolder1_panelEscudo");
    var contentTecnicos = document.getElementById("ctl00_ContentPlaceHolder1_panelTecnicos");
    var contentJugadores = document.getElementById("ctl00_ContentPlaceHolder1_panelJugadores");
    var contentClasificacion = document.getElementById("ctl00_ContentPlaceHolder1_panelClasificacion");
    var contentResultados= document.getElementById("ctl00_ContentPlaceHolder1_panelResultados");
    
    if (contentEscudo!=null || contentTecnicos!=null || contentJugadores!=null){
        totalAnchoElementosPagina = totalAnchoElementosPagina + 200;
    }
    
    if (contentClasificacion!=null || contentResultados!=null){
        totalAnchoElementosPagina = totalAnchoElementosPagina + 280;
    }

    // buscamos el panel de noticias
    var contentNoticias = document.getElementById("ctl00_ContentPlaceHolder1_panelNoticias");
    // si lo encontramos, seguimos
    if (contentNoticias!=null) {
        var windowWidth= GetWindowWidth();
        var data = contentNoticias.getElementsByTagName("div");
        if (windowWidth>totalAnchoElementosPagina) {
            for (a=0;a<data.length;a++) {
                var layerId = data[a].id;
                if (layerId.indexOf("panelContentNoticia")!=-1) {
                    var nuevoAncho = new String(windowWidth - totalAnchoElementosPagina);
                    document.getElementById(layerId).style.width = nuevoAncho + "px";
                }
            }
        }
    }
}

window.onresize = doResize;
