﻿var channel;
var news;
var next;
var previous;
var isMostVoted = false;
var origin = "SCRIPTOR";
var videoTitle = "";
var videoID = "";
var videoSize = 388;

function clearCurrent(obj) {
    for (i = 0; i < obj.parentNode.childNodes.length; i++) {
        obj.parentNode.childNodes[i].className = '';
    }
}
function getEditorial(obj, idc, channelID, previousID, nextID) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    channel = channelID;
    previous = previousID;
    next = nextID;
    Publico.WS.Desporto.getLastNewsFromChannel(idc, onSuccessNewsByChannel, onError);
    doPageCount("DESPORTO TAB");
    $get(channelID).value = idc;
}

function getPreviousByChannel(channelID, newsID, nextID, callBack) {
    channel = channelID;
    previous = newsID;
    next = nextID;

    Publico.WS.Desporto.getNewsForChannel($get(channelID).value, $get(newsID).value, eval(callBack), onError);
    doPageCount("DESPORTO TAB");
}

function getNextByChannel(channelID, newsID, previousID, callBack) {
    channel = channelID;
    next = newsID;
    previous = previousID
    Publico.WS.Desporto.getNewsForChannel($get(channelID).value, $get(newsID).value, eval(callBack), onError);
    doPageCount("DESPORTO TAB");
}

function onSuccessNewsByChannel(results) {
    if (results) {
        for (iCount = 0; iCount < $get("destaqueEditorial").childNodes.length; iCount++) {
            if ($get("destaqueEditorial").childNodes[iCount].tagName == "IMG")
                break;
        }

        if (results.image != "") {
            $get("destaqueEditorial").childNodes[iCount].style.display = 'inline';
            $get("destaqueEditorial").childNodes[iCount].src = "/imagens.aspx/" + results.image + "?tp=UH&db=IMAGENS&w=79&h=79&act=cropResize";
        } else {
            $get("destaqueEditorial").childNodes[iCount].style.display = 'none';
        }
        
        $get("destaqueEditorialTexto").innerHTML = "<h1><a href=\"" + results.subtitle + "\">" + results.title + "</a></h1>";
        $get("destaqueEditorialTexto").innerHTML += "<h2>" + results.lead + "</h2>";

        $get("linkNext").style.display = !results.previous ? 'none' : 'inline';
        $get("linkPrevious").style.display = !results.nextID ? 'none' : 'inline';

        $get(previous).value = results.previous;
        $get(next).value = results.nextID;
    } else {
        $get("linkPrevious").style.display = 'none';
        $get("linkNext").style.display = 'none';
    }
}

function onError(err) {
    alert(err.get_message());
}

function getTop(obj, opt) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = "current";
    $get("listaTopComSetas").innerHTML = "<li style=\"width:252px\"><p><strong>Aguarde por favor....</strong></p></li>";
    Publico.WS.Desporto.getTop(opt, onSuccessTop, onError);
    doPageCount("DESPORTO TOP");
}

function onSuccessTop(results) {
    if (results) {
        $get("listaTopComSetas").innerHTML = results;
    }
}

function setMultimedia(value, obj, idc) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = "current";
    if (value == "VIDEO") {
        $get("linksFoto").style.display = 'none';
        $get(fotoBox).style.display = 'none';
        $get(videoBox).style.display = 'inline';
    } else {
        $get(videoBox).style.display = 'none';
        $get(fotoBox).style.display = 'inline';
        $get("LinksVideo").style.display = 'none';
        $get("linksFoto").style.display = 'inline';
    }
}

function onSuccessVideos(results) {
    alert(results);
}

function setMultimediaTab(value, obj) {
    Publico.WS.Desporto.getFirstVideo(onSuccessVideos, onError);
    doPageCount("DESPORTO MULTIMEDIA");
}

function getClassificaton(value, obj) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    var myTableClassification = $get("classificacaoTabela")
    while (myTableClassification.rows.length > 1) {
        myTableClassification.deleteRow(myTableClassification.rows.length - 1);
    }
    Publico.WS.Desporto.getClassification(value, onSuccessClassification, onError);
    doPageCount("DESPORTO CLASSIFICACAO");
}

function getClassificatonOpta(value, obj) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    var myTableClassification = $get("classificacaoTabela")
    while (myTableClassification.rows.length > 1) {
        myTableClassification.deleteRow(myTableClassification.rows.length - 1);
    }

    var myTableJornada = $get("calendar_football")
    while (myTableJornada.rows.length > 1) {
        myTableJornada.deleteRow(myTableJornada.rows.length - 1);
    }

    Publico.WS.Desporto.getClassificationOPTA(value, onSuccessClassificationOpta, onError);
    doPageCount("DESPORTO CLASSIFICACAO");
}

function onSuccessClassificationOpta(results) {
     if (results) 
     {
         try{
         $get("ctl00_ContentPlaceHolder1_ctl00_ctl17_numeroJornada").innerHTML = results.jornada;
         $get("ctl00_ContentPlaceHolder1_ctl00_ctl17_classificacaoTitulo").innerHTML = results.liga;
         
     } catch (e) { }

     try {
         $get("ctl00_ContentPlaceHolder1_ctl08_numeroJornada").innerHTML = results.jornada;
         $get("ctl00_ContentPlaceHolder1_ctl08_classificacaoTitulo").innerHTML = results.liga;
     } catch (e) { }

     try {
         $get("ctl00_ContentPlaceHolder1_ctl07_numeroJornada").innerHTML = results.jornada;
         $get("ctl00_ContentPlaceHolder1_ctl07_classificacaoTitulo").innerHTML = results.liga;
     } catch (e) { }

         var myTableClassification = $get("classificacaoTabela")
         while (myTableClassification.rows.length > 1) 
         {
             myTableClassification.deleteRow(myTableClassification.rows.length - 1);
         }

         var par = 1;
         for (iCount = 0; iCount < results.posicao.length; iCount++) 
         {
             var row = myTableClassification.insertRow(myTableClassification.rows.length);
             row.className = par == 1 ? "tabelaImpar" : "tabelaPar";
             var cell = row.insertCell(0);
             cell.innerHTML = results.posicao[iCount].lugar;
             cell.className = "coluna1";

             var cell = row.insertCell(1);

             cell.className = "coluna2";
             var nome = results.posicao[iCount].nome;
             var customName = results.posicao[iCount].customName;
             
             if (customName == "" || customName == null) {
                cell.innerHTML = nome ;
             }else{
                cell.innerHTML = customName;
            }

             //cell.innerHTML = results.posicao[iCount].nome;
             var cell = row.insertCell(2);
             cell.innerHTML = results.posicao[iCount].jogos;
             var cell = row.insertCell(3);
             cell.innerHTML = results.posicao[iCount].vitorias;
             var cell = row.insertCell(4);
             cell.innerHTML = results.posicao[iCount].empates;
             var cell = row.insertCell(5);
             cell.innerHTML = results.posicao[iCount].derrotas;
             var cell = row.insertCell(6);
             cell.innerHTML = results.posicao[iCount].golosmarcados;
             var cell = row.insertCell(7);
             cell.innerHTML = results.posicao[iCount].golossofridos;
             var cell = row.insertCell(8);
             cell.innerHTML = results.posicao[iCount].pontos
             par = par == 1 ? 0 : 1;
         }

         var mycalendar_football = $get("calendar_football")
         while (mycalendar_football.rows.length > 1) {
             mycalendar_football.deleteRow(mycalendar_football.rows.length - 1);
         }

         for (iCount = 0; iCount < results.jornadacalendar.length; iCount++) {
             var row = mycalendar_football.insertRow(mycalendar_football.rows.length);

             var cell = row.insertCell(0);
             cell.innerHTML = results.jornadacalendar[iCount].data;
             cell.className = "game_date";

             var cell = row.insertCell(1);
             cell.innerHTML = results.jornadacalendar[iCount].hora;
             cell.className = "game_time";

             var cell = row.insertCell(2);
             cell.className = "game_teams";

             var home = " ";
             var homeCustomName = results.jornadacalendar[iCount].homeCustomName;
             var away = " ";
             var awayCustomName = results.jornadacalendar[iCount].awayCustomName;

             if (homeCustomName == "" || homeCustomName == null) {
                 home = results.jornadacalendar[iCount].home;
             }else{
                 home = homeCustomName;
             }

             if (awayCustomName == "" || awayCustomName == null) {
                 away = results.jornadacalendar[iCount].away;
             } else {
                 away = awayCustomName;
             }

             var currentTime = new Date();
             //currentTime = currentTime.getTime();
             var xhtml = " "
             if (currentTime >= results.jornadacalendar[iCount].apreData && results.jornadacalendar[iCount].estado != "Postponed") {
                 xhtml = "<a href=\"/jogoLive.aspx?id=" + results.jornadacalendar[iCount].idJogo + "\"><span class=\"team1\"> " + home + " </span><span class=\"score\"><span class=\"score1\">" + results.jornadacalendar[iCount].goloCasa + "</span> <span class=\"sep\"> - </span> <span class=\"score2\"> " + results.jornadacalendar[iCount].golosFora + "</span></span><span class=\"team2\"> " + away + "</span></a>";
             } else if (currentTime >= results.jornadacalendar[iCount].apreData && results.jornadacalendar[iCount].estado == "Postponed") {
                 xhtml = "<a href=\"/jogoLive.aspx?id=" + results.jornadacalendar[iCount].idJogo + "\"><span class=\"team1\">" + home + " </span><span class=\"score\"> ADI </span><span class=\"team2\"> " + away + "</span></a>";
             } else {
                 xhtml = "<a><span class=\"team1\">" + home + " </span><span class=\"score\"> - </span><span class=\"team2\"> " + away + "</span></a>";
             }
                        
             cell.innerHTML = xhtml

             var cell = row.insertCell(3);
             cell.className = "game_tv"
             cell.innerHTML = " "

         }
     }
  }


function onSuccessClassification(results) {
    if (results) {
        $get("classificacaoTitulo").innerHTML = results.liga;
        var myTableClassification = $get("classificacaoTabela")
        while (myTableClassification.rows.length>1){
            myTableClassification.deleteRow(myTableClassification.rows.length-1);
        }

        var par = 1;
        for (iCount = 0; iCount < results.posicao.length; iCount++) {
            var row = myTableClassification.insertRow(myTableClassification.rows.length);
            row.className = par = 1 ? "tabelaImpar" : "tabelapar";
            var cell = row.insertCell(0);
            cell.innerHTML = results.posicao[iCount].lugar;
            cell.className = "coluna1";
            var cell = row.insertCell(1);
            cell.className = "coluna2";
            cell.innerHTML = results.posicao[iCount].nome;
            var cell = row.insertCell(2);
            cell.innerHTML = results.posicao[iCount].jogos;
            var cell = row.insertCell(3);
            cell.innerHTML = results.posicao[iCount].vitorias;
            var cell = row.insertCell(4);
            cell.innerHTML = results.posicao[iCount].empates;
            var cell = row.insertCell(5);
            cell.innerHTML = results.posicao[iCount].derrotas;
            var cell = row.insertCell(6);
            cell.innerHTML = results.posicao[iCount].golosmarcados;
            var cell = row.insertCell(7);
            cell.innerHTML = results.posicao[iCount].golossofridos;
            var cell = row.insertCell(8);
            cell.innerHTML = results.posicao[iCount].pontos
            par = par = 1 ? 0 : 1;
        }
    }
}

function onSuccessMultimedia(results) {
    if (results) {
        $get(imgMultimediaPreview).src = "/imagens.aspx/" + results.image + "?tp=UH&db=IMAGENS&w=288";
        $get(imgMultimediaPreview).onclick = function() {
            //showModal('/gallery.aspx?id=' + results.id, results.title, 610, 500);
            document.location = '/Galeria/?id=' + results.id ;
        }
        $get("multimediaTitle").innerHTML = results.title;
        $get("multimediaText").innerHTML = results.lead;

        $get("linkNextFoto").style.display = !results.previous ? 'none' : 'inline';
        $get("linkNextVideo").style.display = !results.previous ? 'none' : 'inline';

        $get("linkPreviousFoto").style.display = !results.nextID ? 'none' : 'inline';
        $get("linkPreviousVideo").style.display = !results.nextID ? 'none' : 'inline';

        $get(previous).value = results.previous;
        $get(next).value = results.nextID;
    }
}

function onSuccessPoker(results) {
    $get("pokerTitle").innerHTML = "";
    $get("pokerImgLead").innerHTML = "";
    
    if (results) {
        if (results.image)
            $get("pokerImgLead").innerHTML = "<img alt=\"\" width=\"81\" align=\"left\" src=\"/imagens.aspx/" + results.image + "?tp=UH&db=IMAGENS&w=81&h=88&act=cropResize\"  />&nbsp;";

        $get("pokerImgLead").innerHTML += results.lead;
        $get("pokerTitle").innerHTML = "<a href=\"noticia.aspx?id=" + results.id + "\">" + results.title + "</a>";

        $get("linkNextPoker").style.display = !results.previous ? 'none' : 'block';
        $get("linkPreviousPoker").style.display = !results.nextID ? 'none' : 'block';

        if (results.previous) $get(previous).value = results.previous;
        if (results.nextID) $get(next).value = results.nextID;
        if (results.idChannel) $get(channel).value = results.idChannel;
    } else {
        $get("linkPreviousPoker").style.display = 'none';
        $get("linkNextPoker").style.display = 'none';
    }
}


function showModal(href, title, w, h){
    myLightWindow.activateWindow({
        href: href,
        loadingAnimation: true,
        title: title,
        width: w,
        height: h
    });
}

function setVote(item, value) {
    Publico.WS.Desporto.addVote(item, value);
    doPageCount("DESPORTO VOTE");
}

function denounceComment(obj, id) {
    Publico.WS.Desporto.denounce(id);
    doPageCount("DESPORTO DENUNCIAR");
    obj.innerHTML = '';
    obj.onclick = null;
}

function setStars() {
    var imgElements = document.getElementsByTagName("img")
    for (iCount = 0; iCount < imgElements.length; iCount++) {
        if (imgElements[iCount].className != 'star') continue;

        imgElements[iCount].onmouseover = function() {
            this.style.cursor = 'pointer';
            var maxVal = parseInt(this.getAttribute("value"));
            var starElements = document.getElementsByName(this.name);
            for (iSum = 0; iSum < starElements.length; iSum++) {
                if (parseInt(starElements[iSum].getAttribute("value")) <= maxVal) {
                    starElements[iSum].src = '/imagens/estrela_on.gif';
                }
            }
        }

        imgElements[iCount].onmouseout = function() {
            var starElements = document.getElementsByName(this.name);
            for (iSum = 0; iSum < starElements.length; iSum++) {
                starElements[iSum].src = '/imagens/estrela_off.gif';
            }
        }

        imgElements[iCount].onclick = function() {
            var starElements = document.getElementsByName(this.name);
            for (iSum = 0; iSum < starElements.length; iSum++) {
                starElements[iSum].onmouseover = function() {
                    this.style.cursor = '';
                };
                starElements[iSum].onmouseout = null;
                starElements[iSum].onclick = null;
            }
            setVote(this.getAttribute("item"), this.getAttribute("value"));
        }
    }
}

function sendComment(id) {
    var isOkToGo = true;
    var title = $get("txtCommentTitle").value;
    var text = $get("txtCommentText").value;
    var name = $get("txtCommentName").value;
    var email = $get("txtCommentEmail").value;
    var local = $get("txtCommentLocal").value;
    var isAnonimous = $get("checkCommentAnonimous").checked;

    if (!checkValue(title, "Titulo", $get("txtCommentTitle"))) isOkToGo = false;
    if (!checkValue(text, "Texto", $get("txtCommentText"))) isOkToGo = false;
    if (!checkValue(name, "Nome", $get("txtCommentName"))) isOkToGo = false;
    if (!checkValue(email, "Email", $get("txtCommentEmail"))) isOkToGo = false;
    if (!checkValue(local, "Localidade, País", $get("txtCommentLocal"))) isOkToGo = false;

    var rules = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (!rules.test(email)) {
        $get("txtCommentEmail").style.background = '#D0AFAE';
        $get("txtCommentEmail").focus();
        isOkToGo = false;
    }

    if (!isOkToGo)
        return false;
        
    $get("btnSend").disabled = true;
    Publico.WS.Desporto.sendComment(id, title, name, text, local, email, isAnonimous, origin, onSuccessComment, onError);
    doPageCount("DESPORTO COMENTARIO");
}

function sendToFriend() {
    var isOkToGo = true;
    var name = $get("txtSendName");
    var email = $get("txtSendEmail");
    var nameDest = $get("txtSendDestName");
    var emailDest = $get("txtSendDestEmail");
    var sentText = $get("txtSendDestEmail");

    if (!checkForInvalidValue(name)) isOkToGo = false;
    if (!checkForInvalidValue(email)) isOkToGo = false;
    if (!checkForInvalidValue(nameDest)) isOkToGo = false;
    if (!checkForInvalidValue(emailDest)) isOkToGo = false;

    if (!isValidEmail(email)) isOkToGo = false;
    if (!isValidEmail(emailDest)) isOkToGo = false;
    
    if (!isOkToGo)
        return;

    Publico.WS.Desporto.sendToFriend(name.value, email.value, nameDest.value, emailDest.value, sentText.value, document.location.href, $get("title").innerHTML, onSuccessMail, onError);
    doPageCount("DESPORTO AMIGO");
}

function onSuccessMail(result) {
    if (result) {
        $get("btnSendFriend").disabled = true;
        $$('#enviar').hide(400);
    } else {
        alert("Não foi possível enviar!\nVerifique os seus dados e tente de novo.");
    }
}

function onSuccessComment(result) {
    if (result) {
        $get("frmComment").style.display = 'none';
        $get("frmThankx").style.display = 'inline';
        $get("btnSend").value = "Enviado..."
    } else {
        alert("Não foi possível enviar o seu comentário, por favor verifique os dados e tente de novo!");
        $get("btnSend").disabled = false;
    }
}

function isValidEmail(obj) {
    var rules = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (!rules.test(obj.value)) {
        obj.style.backgroundColor = '#D0AFAE';
        return false;
    }
    return true;
}

function checkForInvalidValue(obj) {
    var myReg = /^\s+|\s+$/i;
    obj.value = obj.value.replace(myReg, "");
    if (obj.value == "") {
        obj.style.backgroundColor = '#D0AFAE';
        return false;
    }
    return true;
}

function checkValue(result, orginal, obj) {
    if (result.toLowerCase() == orginal.toLowerCase() || trim(result, " ") == "") {
        obj.value = "";
        obj.style.background = '#D0AFAE';
        obj.focus();
        return false;
    }
    return true;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function changeSize(obj, size) {
    try {
        $get(obj).style.fontSize = (parseInt($get(obj).style.fontSize) + size) + "px";
    } catch (e) {
        //alert(e);
    }
}

function doLogin(user, pass) {
    Publico.WS.Desporto.doLogin(user, pass, onSuccessUserLogin, onError);
}

function onSuccessUserLogin(results) {
    if (results) {
        $get("loginForm").innerHTML = "Olá " + results.nome + "&nbsp;&nbsp;";
    } else {
        alert("Nome ou palavra-chave errada!");
    }
}


function getCanais(nome) {
    Publico.WS.Desporto.getCanais(nome, onSuccessCanais, onError);
    doPageCount("DESPORTO CANAIS");
}

function onSuccessCanais(results) {
    if (results) {
        $get("canaisList").innerHTML = "";
        for (iCount = 0; iCount < results.length; iCount++) {
            $get("canaisList").innerHTML += "<li><a href=\"" + results[iCount].link + "\">" + results[iCount].nome + "</a></li>";
        }
    }
}

function PopNews(page, name, myWidth, myHeight, x, y) {
    popWind = window.open(page, name, "width=" + myWidth + ",height=" + myHeight + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y + ",toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,resizable=no");
    if (popWind.opener == null) {
        popWind.opener = window;
    }
    else {
        popWind.focus();
    }
    window.opener = popWind;
}

function setCounter(id, Origin, type, section, title) {
    if (!isNaN(id)) {
        var params = "&id=" + id + "&Origin=" + Origin + "&type=" + type + "&section=" + section + "&title=" + title + "&url=" + document.location.href;
        var pic1 = new Image(1, 1);
        pic1.src = "http://www.publico.pt/includes/lib/statistics.aspx?" + params;
    }
}

function mkGETReq(url, parameters) {
    url = url.replace("&amp;", "&");
    parameters = parameters.replace("&amp;", "&");

    //	http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!http_request) {
        return false;
    }
    //http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
}

function getNextTopic(page) {
    Publico.WS.Desporto.getHistory(4773, page, onSuccessTopic, onError);
    doPageCount("DESPORTO TOPIC");
}

function onSuccessTopic(results) {
    if (results) {
        $get("topicPage").value = results.actual;
        $get("previousTopic").style.display = results.actual < 2 ? "none" : "inline";
        $get("nextTopic").style.display = results.actual < results.total ? "inline" : "none";
        $get("topicContainer").innerHTML = "";
        for (iCount = 0; iCount < results.n.length; iCount++) {
            $get("topicContainer").innerHTML += "<div class=\"temasLista\"><strong>" + results.n[iCount].data + "</strong><br /><a href=\"/forum/?id=" + results.n[iCount].id + "\">" + results.n[iCount].titulo + "</a>";
        }
    }
}

function changeCommentType(obj, bool) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    isMostVoted = bool;
    getComments(1, bool)
}

function getComments(page, type) {
    $get("actualPage").value = page;
    $get("pagAnteriorLink").style.display = page > 1 ? 'inline' : 'none';
    try{
        $get("pagSeguinteLink").style.display = page < parseInt($get("maxPage").value) ? 'inline' : 'none';
    }catch(e){
        var pageNext = document.getElementsByName("pagSeguinteLink");
        if(pageNext.length>0)
            pageNext[0].style.display = page < parseInt($get("maxPage").value) ? 'inline' : 'none';
    }
    Publico.WS.Desporto.getCommments($get("idNot").value, page, type, origin, onSuccessComments, onError);
    doPageCount("DESPORTO COMENTARIOS");
}

function onSuccessComments(results) {
    if (results) {
        $get("navNum").innerHTML = results.nav;
        var container = $get("commentListing");
        container.innerHTML = "";
        for (iCount = 0; iCount < results.coms.length; iCount++) {
            var htmlStar = "";
            var maxStars = 5;
            var starPoints = parseInt(results.coms[iCount].average);

            for (iStar = 1; iStar < starPoints + 1; iStar++) {
                htmlStar += "<img alt=\"\" src=\"/imagens/estrela_on.gif\" width=\"9\" height=\"10\" />";
                maxStars -= 1;
            }
            for (iStar = maxStars; iStar > 0; iStar--) {
                htmlStar += "<img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" />";
            }
            container.innerHTML += "<div class=\"comentarioForum\">" +
	                    "<div class=\"fl\"><strong>" + results.coms[iCount].author + ", " + results.coms[iCount].location + ". " + results.coms[iCount].commentDate + "</strong></div>" +
                        "<div class=\"forumVotos\">Vota <img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" name=\"star" + results.coms[iCount].id + "\" class=\"star\" value=\"1\" item=\"" + results.coms[iCount].id + "\" /><img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" name=\"star" + results.coms[iCount].id + "\" class=\"star\" value=\"2\" item=\"" + results.coms[iCount].id + "\"/><img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" name=\"star" + results.coms[iCount].id + "\" class=\"star\" value=\"3\" item=\"" + results.coms[iCount].id + "\"/><img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" name=\"star" + results.coms[iCount].id + "\" class=\"star\" value=\"4\" item=\"" + results.coms[iCount].id + "\"/><img alt=\"\" src=\"/imagens/estrela_off.gif\" width=\"9\" height=\"10\" name=\"star" + results.coms[iCount].id + "\" class=\"star\" value=\"5\" item=\"" + results.coms[iCount].id + "\"/> " +
                        "| " + htmlStar + " " + results.coms[iCount].vote_number + " votos</div>" +
	                    "<div class=\"comentarioTexto\">" + results.coms[iCount].text + "</div>" +
                        "<div class=\"denunciar\"><a style=\"cursor:pointer\" onclick=\"denounceComment(this, '" + results.coms[iCount].id + "');\">Denunciar este comentário</a></div>" +
                        "</div>";
        }
        setStars();
    }
}

function setValueForVideo(vid, vis, vit) {
    videoID = vid;
    videoSize = vis;
    videoTitle = vit;
    showVideo();
}

function showVideo() {
    var params = "";

    if (videoSize == 302)
        params = '|z=1&f=16';
    else
        params = '|z=1&f=4';

    if (videoID != "") {
        setCounter(videoID, 'IPSILON', 'VISTO', 'VIDEOS', videoTitle);
        myLightWindow.activateWindow({
            href: '/iplayer.aspx?id=' + videoID + params,
            loadingAnimation: true,
            title: videoTitle,
            width: 480,
            height: videoSize
        });
    }
}

function getPoker(obj, type, previousID, nextID, channelID) {
    previous = previousID;
    next = nextID;
    channel = channelID;    
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    Publico.WS.Desporto.getPoker(type, onSuccessPoker, onError);
    doPageCount("DESPORTO JOKER");
}

function getAgenda(obj, bool) {
    clearCurrent(obj.parentNode);
    obj.parentNode.className = 'current';
    Publico.WS.Desporto.getAgenda(bool, onSuccessAgenda, onError);
    doPageCount("DESPORTO AGNEDA");
}

function onSuccessAgenda(results) {
    if (results) {
        $get("agendaContainer").innerHTML = "";
        var strString = "";
        if (results.datas) {
            for (iCount = 0; iCount < results.datas.length; iCount++) {
                strString += "<div id=\"agendaData\" class=\"agendaBarraDia\">" + results.datas[iCount].nome + "</div>";
                var modalities = results.datas[iCount].modalidades;
                for (iModalidades = 0; iModalidades < modalities.length; iModalidades++) {
                    strString += "<div class=\"agendaModalidade\">" + modalities[iModalidades].nome + "</div>";
                    strString += "<div class=\"agendaLista\">";
                    var competitions = modalities[iModalidades].competicoes;
                    for (iComp = 0; iComp < competitions.length; iComp++) {
                        strString += "<div class=\"agendaDivisao\">" + competitions[iComp].nome + "</div>";
                        var ev = competitions[iComp].events;
                        for (iEvents = 0; iEvents < ev.length; iEvents++) {
                            strString += "<div class=\"agendaEquipas\">" + ev[iEvents].nome + "</div>";
                            strString += "<div class=\"agendaHora\">" + ev[iEvents].hora + "</div>";
                            if (ev[iEvents].link == "")
                                strString += "<div class=\"agendaTv\">" + ev[iEvents].canal + "</div>";
                            else
                                if (ev[iEvents].link != "") strString += "<div class=\"agendaTv\"><a target=\"_blank\" href=\"" + ev[iEvents].link + "\">mais</a></div>";
                        }
                    }
                    strString += "</div>";
                }
            }
        }
        $get("agendaContainer").innerHTML = strString;
    }
}

function refresPage() {
    //document.location.reload();
}

function checkMaxLength(obj, maxSize) {
    if (obj.value.length > maxSize)
        obj.value = obj.value.substring(0, maxSize);
    document.getElementById("actualN").innerHTML = maxSize - obj.value.length;
}

function doPageCount(section) {
    try {
        w_counter = new wreport_counter(WRP_SECTION, section, WRP_ID, WRP_ACC, WRP_CHANNEL);
        w_counter.add_content(section + " content");
        w_counter.count();
    } catch (e) { }
}
