﻿
var AC_FL_RunContent = 0;
var DetectFlashVer = 0
var UseNet = false;
var ArrayStartupVideo = new Array();

function SetPage()
{
    if (typeof SetPageInterior != 'undefined') SetPageInterior();
    //try {if (SetPageInterior) SetPageInterior(); } catch (exp) {}
    SetPollControl();
    SetTimeGapsStart();
    SetCommentsStart();
    GetRatingFromQueue();
    SetScrollerCxDesporto("divTagScrollCxDesporto");
    window.setTimeout("SetTicker(1, true)", 10000); 
}

function EvalVideo()
{
    if (ArrayStartupVideo.length) {
      var video = ArrayStartupVideo.pop();
      //alert(video);
      eval (video);
    }
}






   
   
   
var oHiddenTimestamps = null;
var sServerDatetime = null;
var iServerGap = null;

function SetTimeGaps() {
    if (oHiddenTimestamps){
        var k, oUncle;
        for ( k=0; k<oHiddenTimestamps.length; k++ ){
          if ( oHiddenTimestamps[k].className == "date-issue" ){  
            oUncle = oHiddenTimestamps[k].nextSibling;
            while ( oUncle && oUncle.nodeName.toString().toLowerCase()=="#text" ) oUncle = oUncle.nextSibling;
            if (oUncle) {  

                oUncle.innerHTML = GetFormatedDate(oHiddenTimestamps[k].value.toString());
            }
          }
        }
    } 
}


function GetFormatedDate(dt)
{
    var sHidden = dt;  
    var oDate = new Date(new Date() - iServerGap);
    //alert(sHidden.substr(0,10) + " = " + oDate.getYear() + "-" + (oDate.getMonth()+1) + "-" + oDate.getDate() );
    var bSameDay = ( sHidden.substr(0,10) ==  FormatNumber(oDate.getFullYear(), 4, "0") + "-" + FormatNumber((oDate.getMonth()+1),2,"0") + "-" + FormatNumber(oDate.getDate(),2,"0") )
    
    var oHiddenDate = new Date();
    oHiddenDate.setYear(sHidden.substr(0,4));
    oHiddenDate.setMonth(sHidden.substr(5,2)*1-1);
    oHiddenDate.setDate(sHidden.substr(8,2));
    if ( bSameDay ) {
      oHiddenDate.setHours(sHidden.substr(11,2));
      oHiddenDate.setMinutes(sHidden.substr(14,2));
      oHiddenDate.setSeconds(sHidden.substr(17,2));
    }
    else {
      oHiddenDate.setHours("00");
      oHiddenDate.setMinutes("00");
      oHiddenDate.setSeconds("00");
      if ( (oDate - oHiddenDate) < 0 ) {
          oHiddenDate.setHours("23");
          oHiddenDate.setMinutes("59");
          oHiddenDate.setSeconds("59");
      }
    }
    
    //1 min = 1
    //1 dia = 1440
    var txt;
    var gap =  (oDate - oHiddenDate) / 60000 ;
    
    if ( dt.length == 10 ) { // esconder horas
      if ((1*gap > -1440 && 1*gap < 0) || (1*gap >= 0 && 1*gap <= 1440)) txt = txt = "Hoje";
      else if  (1*gap >= -2880 && 1*gap <= -1440) txt = "Amanh&atilde;";
      else if  (1*gap >= 0 && 1*gap <= 2880) txt = "Ontem";
      else txt = "<i>" + dt.substr(8,2) + "</i> " + GetFormatedMonth(dt.substr(5,2)) + " <i>" + dt.substr(0,4) + "</i>";
    }
    else {
      if ((1*gap >= 0 && 1*gap <= 1) || Math.floor(gap)==1) txt = "H&aacute; <i>1</i> minuto";
      else if  (1*gap >= 0 && 1*gap < 60) txt = "H&aacute; <i>" + Math.floor(gap) + "</i> minutos";
      else if  (1*gap >= 0 && 1*gap < 120) txt = "H&aacute; <i>1</i> hora";
      else if ((1*gap > -1440 && 1*gap < 0) || (1*gap >= 0 && 1*gap <= 1440)) txt = txt = "Hoje" + ", às <i>" + dt.substr(11,5) + "</i>";
      else if  (1*gap >= -2880 && 1*gap <= -1440) txt = "Amanh&atilde;" + ", às <i>" + dt.substr(11,5) + "</i>";
      else if  (1*gap >= 0 && 1*gap <= 2880) txt = "Ontem" + ", às <i>" + dt.substr(11,5) + "</i>";
      else txt = "<i>" + dt.substr(8,2) + "</i> " + GetFormatedMonth(dt.substr(5,2)) + "<i> " + dt.substr(2,2) + "</i>, às <i>" + dt.substr(11,5) + "</i>";
    }
    return txt;

}



function GetFormatedMonth(month)
{
    var sFormatedMonth = "";
    switch (1*month) {
        case 1 : sFormatedMonth = "Janeiro"; break;
        case 2 : sFormatedMonth = "Fevereiro"; break;
        case 3 : sFormatedMonth = "Março"; break;
        case 4 : sFormatedMonth = "Abril"; break;
        case 5 : sFormatedMonth = "Maio"; break;
        case 6 : sFormatedMonth = "Junho"; break;
        case 7 : sFormatedMonth = "Julho"; break;
        case 8 : sFormatedMonth = "Agosto"; break;
        case 9 : sFormatedMonth = "Setembro"; break;
        case 10 : sFormatedMonth = "Outubro"; break;
        case 11 : sFormatedMonth = "Novembro"; break;
        case 12 : sFormatedMonth = "Dezembro"; break;
    }
    return sFormatedMonth;
}


function SetTimeGapsStart() {
    oHiddenTimestamps = document.body.getElementsByTagName("input");
    var k;
    if ( oHiddenTimestamps )
        for ( k=oHiddenTimestamps.length-1; k>=0 && oHiddenTimestamps && !sServerDatetime; k-- )
            if (oHiddenTimestamps[k].value && oHiddenTimestamps[k].id.indexOf("ServerDatetime")>=0) 
                sServerDatetime = oHiddenTimestamps[k].value;
    
    if ( !sServerDatetime ) {
        var oTmpDate = new Date();
        sServerDatetime = oTmpDate.getFullYear() + "-" + (oTmpDate.getMonth()+1) + "-" + oTmpDate.getDay() + " " + 
                          oTmpDate.getHours() + ":" + oTmpDate.getMinutes() + ":" + oTmpDate.getSeconds(); 
        iServerGap = 0;                  
    }
    else {
        var oServerDate = new Date();
        oServerDate.setYear(sServerDatetime.substr(0,4));
        oServerDate.setMonth(sServerDatetime.substr(5,2)*1-1);
        oServerDate.setDate(sServerDatetime.substr(8,2));
        oServerDate.setHours(sServerDatetime.substr(11,2));
        oServerDate.setMinutes(sServerDatetime.substr(14,2));
        oServerDate.setSeconds(sServerDatetime.substr(17,2));

        iServerGap = new Date() - oServerDate;
    }

    
    SetTimeGaps();
    if (oHiddenTimestamps && oHiddenTimestamps.length>0) window.setInterval("SetTimeGaps()", 30000);
}


var oHiddenComments = null;
var posHiddenComments = 0;
function SetCommentsStart() {
  var inputs = document.body.getElementsByTagName("input");
  oHiddenComments = new Array();
  var k, ids = "";
  if (inputs) {
    for ( k=0; k<inputs.length; k++ ) {
        if (inputs[k].className == "link-comments") {
          oHiddenComments.push(inputs[k]);
          ids += ( ids == "" ? "" : "|" ) + inputs[k].value;
        }
    }
    if (oHiddenComments.length) {
      var loc = "/Common/Services/AssyncCS.aspx?ids=" + ids;
      if (typeof CSIfr != 'undefined') CSIfr.location.replace(loc);
      else {
        var ifr = document.getElementById("CSIfr");
        if (ifr) ifr.src = loc;
      }
    }
  }
}
function SetAssyncCSContent(html){
  var arrPos, htmlArray = html.split("|");
  for (arrPos=0; arrPos<htmlArray.length; arrPos++) 
    if ( oHiddenComments.length > arrPos ) {
      var oUncle = oHiddenComments[arrPos].nextSibling;
      while ( oUncle && oUncle.nodeName.toString().toLowerCase()=="#text" ) oUncle = oUncle.nextSibling;
      if (oUncle) {
        if (1*htmlArray[arrPos] > 0) oUncle.innerHTML = 1*htmlArray[arrPos] + "&nbsp;comentário" + (1*1*htmlArray[arrPos]==1 ? "" : "s");
        else oUncle.innerHTML = "Comentar";
      }
      var ancestor =   GetAncestor(oHiddenComments[arrPos], "comments-wrapper");
      if (ancestor) ancestor.style.visibility = "visible";
      
    }
}
 
 function FormatNumber(num, len, padding)
 {
   var ret = num.toString();
   if (num) {
      var k;
      for ( k=ret.length; k<len; k++ ) {
         ret = padding + ret;
      }
   }
   return ret;
 }




/*
var bScrollDiv = false;
   
function ScrollDiv (sDiv, direction, bSetFlag) {
  if ( bSetFlag ) bScrollDiv = true;
  
  try {
     var oDiv = document.getElementById(sDiv);
     if (oDiv) {
        var oParent = oDiv.parentNode, sNewPos = 0, sPos = ( oDiv.style.left ? oDiv.style.left : -1 ), divWidth = oDiv.clientWidth - oParent.clientWidth;
        alert(sPos && bScrollDiv);
        if ( sPos && bScrollDiv ) {
           sPos = sPos.toString().replace(/px/, "").replace(/pt/, "");
           sNewPos = sPos*1 + 2*direction;
           
           if (sNewPos <= 0 && (sNewPos >= -divWidth || !IsIE())){
              oDiv.style.marginLeft = sNewPos;
              alert(oDiv.style.marginLeft);
              window.setTimeout("ScrollDiv('" + sDiv + "', " + direction + ")", 1);
           }
           else {
              oDiv.style.left = ( direction > 0 ? -divWidth : 0 ); 
              window.setTimeout("ScrollDiv('" + sDiv + "', " + direction + ")", 1);
           }
        }
     }
  } catch(e){ alert(e.description) }
}



function ScrollDivStop () { bScrollDiv = false }
*/



/*


var AudioAndVideo_StarSelected = 0;
var AudioAndVideo_StarSelected_Hold = false;
function FillStars(obj, starvar, recursive)
{
    if (obj) {
        if (!recursive) eval(starvar + "_Hold = true");
        var mystar = GetElementName(obj);
        if ( 1*mystar > 1 ) FillStars(GetPreviousSibling(obj), starvar, true);
        var img = GetDescendant(obj, "star", "img");
        if (img) img.src = img.src.replace("_off.gif", "_on.gif");
        if (!recursive) 
            eval(starvar + "_Hold = false");
    } 
}
function ClearStars(obj, starvar)
{
    var img, imgName;
    if (obj) {
        
        if (!eval(starvar + "_Hold")){ // sent by star
            var mystar = GetElementName(obj);
            if ( 1*mystar < 5 ) {
                var followingsibling = GetSibling(obj);
                if (followingsibling) {
                    var img = GetDescendant(followingsibling, "star", "img");
                    if ( img && img.src.indexOf("_on.gif")>=0 )
                       return; 
                }
            }
            if (1*eval(starvar) < 1*mystar) {
                img = GetDescendant(obj, "star", "img");
                if (img) img.src = img.src.replace("_on.gif", "_off.gif");
                if ( 1*mystar > 1 ) ClearStars(GetPreviousSibling(obj), starvar);
            }
        }
     
    }
}
function ClickStars(obj, starvar)
{
    if (obj) {
        eval(starvar + "= '" + GetElementName(obj) + "'");
        ClearStars( GetDescendant(obj.parentNode, "5", "a"), starvar);
    }
}

*/



function InitAnimGroup(name, quant, isVertical)
{
    var obj, arr = eval("Array" + name);
    if (arr && arr.length) {
        
       obj = document.getElementById(name + "Main");
       if (obj) {
          var k;
          obj.innerHTML = "";
          for (k=0; k<quant && k<arr.length; k++)
              obj.innerHTML += arr[k].html;
       }
       
       if (arr.length <= quant) {
            var controlsLeft = document.getElementById(name + "Nav" + ( isVertical ? "Up" : "Left" ));
            if (controlsLeft) controlsLeft.style.visibility = "hidden";
            var controlsRight = document.getElementById(name + "Nav" + ( isVertical ? "Down" : "Right" ));
            if (controlsRight) controlsRight.style.visibility = "hidden";
            var indicadores = document.getElementById(name + "Indicadores");
            if ( indicadores ) indicadores.style.display = "none";
        }
        else if (arr.length <= 2*quant ) {
            var indicadores = document.getElementById(name + "IndicadorMeio");
            if ( indicadores ) indicadores.style.display = "none";
        }
    }
    else {
        obj = document.getElementById(name + "Container");
        if (obj) obj.style.display = "none";
    }
}


function ShowAnimGroup(dir, name, quant) //name = galeria, quant = 4
{
   var effect = document.getElementById(name + "Effect" + dir);
   var main = document.getElementById(name + "Main"); 
   var arr = eval("Array" + name);
   if (effect && main) {
       if ( effect.innerHTML == "" ) {
          var width = main.clientWidth; // + ou - 570
          var pos = eval(name + "Pos") + dir;
          var lenPos = Math.ceil(arr.length/quant);
          if ( pos < 0 ) pos = lenPos - 1;
          else if ( pos >= lenPos ) pos = 0;
          effect.style.marginLeft = (dir * width) + "px";
          var k;
          effect.innerHTML = "";
          for ( k=0; k<quant; k++ ) 
            effect.innerHTML += ( quant*pos + k<arr.length ? arr[quant*pos + k].html : eval(name + "HTML()") );
          effect.style.width = width;
          effect.style.display = "block";
          var x, y, height = 0, heighttmp = 0;
          for (x=0; x<effect.childNodes.length; x++) {
            heighttmp = effect.childNodes[x].offsetHeight;
            if (heighttmp>height) height = heighttmp;
          }
          effect.parentNode.parentNode.style.height = ( name == 'Topico' || name == 'Cronista' ? height : (height-12) ) + "px";
          if (dir<0) effect.style.styleFloat = "left";
          eval(name + "Pos = " + pos);
       }
       
       var left = effect.style.marginLeft.replace(/px/gi, "");
       if ( (dir>0 && 1*left > 0) || (dir<0 && 1*left<0)) {
          //alert("before: " + effect.style.marginLeft + ", " + main.style.marginLeft);
          effect.style.marginLeft = (1*left - dir * 40) + "px";
          if ( dir>0 ) {
            var leftMain = main.style.marginLeft.replace(/px/gi, "");
            main.style.marginLeft = (1*leftMain - 40) + "px";
          }
          //alert("after: " + effect.style.marginLeft + ", " + main.style.marginLeft);
          window.setTimeout("ShowAnimGroup(" + dir + ", '" + name + "', " + quant + ")", 1);
       }
       else {
          var aux = main.innerHTML;
          main.innerHTML = effect.innerHTML;
          main.style.marginLeft = "0px";
          effect.style.styleFloat = "";
          effect.style.display = "none";
          effect.innerHTML = "";
          
          var highlightIndicador = 1;
          if ( eval(name + "Pos") == 0 ) highlightIndicador = 0;
          else if ( quant*eval(name + "Pos") <= arr.length && quant*(eval(name + "Pos")+1) >= arr.length ) highlightIndicador = 2;
          SetIndicadores(name, highlightIndicador);
       }
   }
}



function ShowAnimGroupVertical(dir, name, quant, offsetTop) //name = galeria, quant = 4
{
   if (!offsetTop) offsetTop = 0;
   var effect = document.getElementById(name + "Effect" + dir);
   var main = document.getElementById(name + "Main"); 
   var arr = eval("Array" + name);
   if (effect && main) {
       var height = main.clientHeight; // + ou - 570
       if ( effect.innerHTML == "" ) {
          var pos = eval(name + "Pos") + dir;
          var lenPos = Math.ceil(arr.length/quant);
          if ( pos < 0 ) pos = lenPos - 1;
          else if ( pos >= lenPos ) pos = 0;
          if ( dir>0 ) effect.style.marginTop = offsetTop + "px";
          else effect.style.marginTop = (-height - offsetTop) + "px";
          var k;
          effect.innerHTML = "";
          for ( k=0; k<quant; k++ ) 
            effect.innerHTML += ( quant*pos + k<arr.length ? arr[quant*pos + k].html : eval(name + "HTML()") );
          effect.style.height = height;
          effect.style.display = "block";
          eval(name + "Pos = " + pos);
       }
       
       var top = effect.style.marginTop.replace(/px/gi, "");
       var topMain = main.style.marginTop.replace(/px/gi, "");
       
       //alert(top + "<" + offsetTop);
       if ( (dir>0 && 1*topMain > - height - offsetTop) || (dir<0 && 1*top<offsetTop)) {
          //alert("before: " + effect.style.marginTop + ", " + main.style.marginTop);
          if ( dir>0 ) main.style.marginTop = (1*topMain - 20) + "px";
          else effect.style.marginTop = (1*top + 20) + "px";
          //alert("after: " + effect.style.marginTop + ", " + main.style.marginTop);
          window.setTimeout("ShowAnimGroupVertical(" + dir + ", '" + name + "', " + quant + ", " + offsetTop + ")", 1);
       }
       else {
          var aux = main.innerHTML;
          main.innerHTML = effect.innerHTML;
          main.style.marginTop = offsetTop + "px";
          effect.style.display = "none";
          effect.innerHTML = "";
          
          var highlightIndicador = 1;
          if ( eval(name + "Pos") == 0 ) highlightIndicador = 0;
          else if ( quant*eval(name + "Pos") <= arr.length && quant*(eval(name + "Pos")+1) >= arr.length ) highlightIndicador = 2;
          SetIndicadores(name, highlightIndicador);
       }
   }
}


/* bolinhas associadas às galerias que indicam se estamos na primeira página, na última ou no meio */
function SetIndicadores(name, highlight)
{
  var indicador1 = document.getElementById(name + "IndicadorInicio");
  if (indicador1) indicador1.src = ( highlight == 0 ? indicador1.src.replace("_off", "_on") :  indicador1.src.replace("_on", "_off") );
  var indicador2 = document.getElementById(name + "IndicadorMeio");
  if (indicador2) indicador2.src = ( highlight == 1 ? indicador2.src.replace("_off", "_on") :  indicador2.src.replace("_on", "_off") );
  var indicador3 = document.getElementById(name + "IndicadorFim");
  if (indicador3) indicador3.src = ( highlight == 2 ? indicador3.src.replace("_off", "_on") :  indicador3.src.replace("_on", "_off") );
}







/* tabs que parecem chavetas */
function SetApontador(parentId, offsetOn, divRefId)
{
  var parent = document.getElementById(parentId);
  if (parent) {
    var k, tables = parent.getElementsByTagName("table");
    if (tables && tables.length) {
      for (k=0; k<tables.length; k++) {
        var j, lnk;
        var div = document.getElementById(divRefId + k);
        if (div) div.style.display = ( offsetOn == k ? "" : "none" );
        
        var tds = tables[k].getElementsByTagName("td");
        if (tds && tds.length) {
          for (j=0; j<tds.length; j++) {
            if ( offsetOn == k ) {
              tds[j].innerHTML = tds[j].innerHTML.replace("_off", "_on");
              if ( j == 1 ) {
                lnk = tds[j].getElementsByTagName("a");
                if (lnk && lnk[0] && lnk[0].attributes && lnk[0].attributes.getNamedItem("href"))
                  lnk[0].attributes.removeNamedItem("href");
              }
            }
            else {
              tds[j].innerHTML = tds[j].innerHTML.replace("_on", "_off");
              if ( j == 1 ) {
                lnk = tds[j].getElementsByTagName("a");
                if (lnk && lnk[0])
                  lnk[0].href = "javascript:SetApontador('" + parentId + "', " + k + ", '" + divRefId + "')";
              }
            }
          }
        }
      }
    }
  }
  
}




/*

var Video_StarSelected = 0;
var Video_StarSelected_Hold = false;
function FillStars(obj, starvar, recursive)
{
    if (obj) {
        if (!recursive) eval(starvar + "_Hold = true");
        var mystar = GetElementName(obj);
        if ( 1*mystar > 1 ) FillStars(GetPreviousSibling(obj), starvar, true);
        var img = GetDescendant(obj, "star", "img");
        if (img) img.src = img.src.replace("_off.gif", "_on.gif");
        if (!recursive) 
            eval(starvar + "_Hold = false");
    } 
}
function ClearStars(obj, starvar)
{
    var img, imgName;
    if (obj) {
        
        if (!eval(starvar + "_Hold")){ // sent by star
            var mystar = GetElementName(obj);
            if ( 1*mystar < 5 ) {
                var followingsibling = GetSibling(obj);
                if (followingsibling) {
                    var img = GetDescendant(followingsibling, "star", "img");
                    if ( img && img.src.indexOf("_on.gif")>=0 )
                       return; 
                }
            }
            if (1*eval(starvar) < 1*mystar) {
                img = GetDescendant(obj, "star", "img");
                if (img) img.src = img.src.replace("_on.gif", "_off.gif");
                if ( 1*mystar > 1 ) ClearStars(GetPreviousSibling(obj), starvar);
            }
        }
     
    }
}
function ClickStars(obj, starvar)
{
    if (obj) {
        eval(starvar + "= '" + GetElementName(obj) + "'");
        ClearStars( GetDescendant(obj.parentNode, "5", "a"), starvar);
    }
}


function SwitchPhotoOld(ancestorName, obj)
{
  var ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    var photo = GetDescendant(ancestor, "Photo", "img");
    if (photo) photo.src = obj.src;
  }
}*/
var GalleryImgPos = 1;
function SwitchPhoto(mainImgId, thumbId, GalleryNavWrapperId, pos, total, imgDetailsWrapperId, imgDetails)
{
  var mainImg = document.getElementById(mainImgId);
  if (1*total>1) {
    GalleryImgPos += (1*pos);
    var ancestor = document.getElementById(GalleryNavWrapperId);
    var thumbImg = document.getElementById(thumbId + GalleryImgPos);
    if (mainImg!=null && thumbImg!=null && ancestor!=null) {
      mainImg.src = thumbImg.src;
      
      var navLeft = GetDescendant(ancestor, "GalleryNavLeft", "td");
      if (navLeft){
        if (1*GalleryImgPos==1) navLeft.style.visibility = "hidden";
        else navLeft.style.visibility = "visible";
      }
      var navRight = GetDescendant(ancestor, "GalleryNavRight", "td");
      if (navRight){
        if (1*GalleryImgPos==total) navRight.style.display = "none";
        else navRight.style.display = "";
      }      
    }
  }
  else if (!GalleryNavWrapperId) {
    var thumbImg = document.getElementById(thumbId);
    if (mainImg!=null && thumbImg!=null) mainImg.src = thumbImg.src;
  }
  if (imgDetailsWrapperId) {
    var imgDetailsWrapperObj = document.getElementById(imgDetailsWrapperId);
    if (imgDetailsWrapperObj) imgDetailsWrapperObj.innerHTML = unescape (imgDetails);
  }
  // update pager info if available
  var pagerinfoObj = document.getElementById('pagerinfo');
  if (pagerinfoObj!=null)
  {
    var pagerinfoLbl = pagerinfoObj.innerHTML;
    var pagerinfoArr = pagerinfoLbl.split('/')
    pagerinfoObj.innerHTML = GalleryImgPos+'/'+total
  }

}




function ChangeTab(obj, ancestorName, pos, page)
{
  var k, oDivs, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    //abrir div
    var topElem = GetAncestor(obj, ancestorName + "Wrapper");
    if (topElem) {
      var contentWrapper = GetSibling(topElem);
      if (contentWrapper) {
        oDivs = contentWrapper.getElementsByTagName("div");
        if (oDivs && oDivs.length) { 
          for (k=0; k<oDivs.length; k++) {
            var elemName = GetElementName(oDivs[k]);
            if ( elemName.indexOf("ContentTab")==0 ) {
              if (elemName == "ContentTab" + pos) {
                if (page) {
                  var oDivContentHtml = GetDescendant(oDivs[k], "ContentHTML" + pos, "div");
                  if (oDivContentHtml!=null && oDivContentHtml.innerHTML == "") 
                    GetAssyncContent("/common/services/" + page, oDivContentHtml, "");
                  oDivs[k].style.display = "";
                }
                oDivs[k].style.display = "";
              }
              else oDivs[k].style.display = "none";
            }
          }
        }
      }
    }
    oDivs = ancestor.getElementsByTagName("div");
    if (oDivs && oDivs.length) {
      for (k=0; k<oDivs.length; k++) {
        if (k==pos) {
          oDivs[k].className = "tab-index-" + oDivs.length;
          if (IsIE()) oDivs[k].style.backgroundImage = oDivs[k].style.backgroundImage.toString().replace("_off", "_on");
          else oDivs[k].parentNode.innerHTML = oDivs[k].parentNode.innerHTML.toString().replace("_off", "_on");
        }
        else {
          oDivs[k].className = "tab-index-" + (oDivs.length-k-1);
          if (IsIE()) oDivs[k].style.backgroundImage = oDivs[k].style.backgroundImage.toString().replace("_on", "_off");
          else oDivs[k].parentNode.innerHTML = oDivs[k].parentNode.innerHTML.toString().replace("_on", "_off");
        }
      }
    }
  }
}



function ChangeTabClass(obj, ancestorName, pos, iframeId, iframeSource)
{
  var k, oDivs, cssArr, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    oDivs = ancestor.getElementsByTagName("div");
    
    if (oDivs && oDivs.length) {
      for (k=0; k<oDivs.length; k++) {
        cssArr = oDivs[k].className.split(" ");
        if (k==pos) {
          oDivs[k].className ="tab-index-" + oDivs.length + " " +  cssArr[1].replace("-off", "-on");
          if (iframeId) {
            var notIe = true;
            try {
              var iframeObj = eval(iframeId);
              if (typeof iframeObj != 'undefined') {
                iframeObj.location.replace(iframeSource);
                notIe = false;
              }
            } catch(exp) {}  
            if (notIe) {
                var ifr = document.getElementById(iframeId);
                if (ifr) ifr.src = iframeSource;
            }
          }
        }
        else 
          oDivs[k].className = "tab-index-" + (oDivs.length-k-1) + " " + cssArr[1].replace("-on", "-off");
      }
    }
    //abrir div
    var topElem = GetAncestor(obj, ancestorName + "Wrapper");
    if (topElem) {
      var contentWrapper = GetSibling(topElem);
      if (contentWrapper) {
        oDivs = contentWrapper.getElementsByTagName("div");
        if (oDivs && oDivs.length) { 
          var pos_found = 0;
          for (k=0; k<oDivs.length; k++) 
            if ( GetElementName(oDivs[k]).indexOf("ContentTab")==0 ) {
              oDivs[k].style.display = ( pos_found==pos ? "block" : "none" );
              pos_found++;
            }
        }
      }
    }
  }
}


function ChangeTabDyn(obj, ancestorName, imgSrc, divTabs, pos)
{
  var html = "";
  var isIE6 = (document.getElementsByTagName('html')[0].className.indexOf("ie6") > 0);
  var ancestor = GetAncestor(obj, ancestorName); 
  if (ancestor) {
    var tabsArr = ancestor.getElementsByTagName("div");
    if (tabsArr) {
      var k; for (k=0; k<tabsArr.length; k++) {
        if (obj.parentNode.className) {
          var childLinksArr = tabsArr[k].getElementsByTagName("a");
          if (childLinksArr) {
            if (tabsArr[k].className.toString()==obj.parentNode.className.toString()) {
              tabsArr[k].className = tabsArr[k].className.toString().replace(/off/gi, "on");
              if (isIE6) {
                var imgsArr = tabsArr[k].getElementsByTagName("img");
                if (imgsArr && imgsArr.length == 2) {
                   imgsArr[0].src = "/Common/Images/" + imgSrc + "/left_on.png";
                   if (tabsArr[k].className.indexOf("last")>=0) imgsArr[1].src = "/Common/Images/" + imgSrc + "/right_on_ss.png";
                   else imgsArr[1].src = "/Common/Images/" + imgSrc + "/right_on.png";
                }
              }
            }
            else {
              tabsArr[k].className = tabsArr[k].className.toString().replace(/on/gi, "off");
              if (isIE6) {
                var imgsArr = tabsArr[k].getElementsByTagName("img");
                if (imgsArr && imgsArr.length == 2) {
                  imgsArr[0].src = "/Common/Images/" + imgSrc + "/left_off.png";
                  if (tabsArr[k].className.indexOf("last")>=0) imgsArr[1].src = "/Common/Images/" + imgSrc + "/right_off_ss.png";
                  else imgsArr[1].src = "/Common/Images/" + imgSrc + "/right_off.png";
                }
              }
            }
          }
        }
      }
    }
  } 
  
  //abrir div
  var contentWrapper = GetSibling(obj.parentNode.parentNode, divTabs + "Wrapper");
  if (contentWrapper) {
      oDivs = contentWrapper.getElementsByTagName("div");
      if (oDivs && oDivs.length) { 
        var pos_found = 0;
        for (k=0; k<oDivs.length; k++) 
          if ( GetElementName(oDivs[k]).indexOf(divTabs)==0 ) {
            oDivs[k].style.display = ( pos_found==pos ? "block" : "none" );
            pos_found++;
          }
      }
  }
}


function ChangeTabOutrasMod(obj, ancestorName, pos)
{
  var k, oDivs, cssArr;
    //abrir div
    var topElem = GetAncestor(obj, ancestorName + "Wrapper");
    if (topElem) {
      var contentWrapper = GetSibling(topElem);
      if (contentWrapper) {
        oDivs = contentWrapper.getElementsByTagName("div");
        if (oDivs && oDivs.length) { 
          var pos_found = 0;
          for (k=0; k<oDivs.length; k++) 
            if ( GetElementName(oDivs[k]).indexOf("ContentTab")==0 ) {
              oDivs[k].style.display = ( pos_found==pos ? "" : "none" );
              pos_found++;
            }
        }
      }
    }
}

function ChangeTabCaixaDesporto(obj, ancestorName, pos)
{
  var k, oDivs, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    oDivs = ancestor.getElementsByTagName("div");
    if (oDivs && oDivs.length) {
      for (k=0; k<oDivs.length; k++) {
        if (k==pos) {
          oDivs[k].className = "cx-tabs-liga-activa";
        }
        else {
          oDivs[k].className = "cx-tabs-liga-inactiva";
        }
      }
    }
    //abrir div
    var topElem = GetAncestor(obj, ancestorName + "Wrapper");
    if (topElem) {
      var contentWrapper = GetSibling(topElem);
      if (contentWrapper) {
        oDivs = contentWrapper.getElementsByTagName("div");
        if (oDivs && oDivs.length) { 
          var pos_found = 0;
          for (k=0; k<oDivs.length; k++) 
            if ( GetElementName(oDivs[k]).indexOf("ContentTab")==0 ) {
              oDivs[k].style.display = ( pos_found==pos ? "" : "none" );
              pos_found++;
            }
        }
      }
    }
  }
}


function ShowHideLayer(obj, ancestorName, pos)
{
  var k, oDivs, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
        oDivs = ancestor.getElementsByTagName("div");
        if (oDivs && oDivs.length) { 
          var pos_found = 0, pos_title_found = 0;
          for (k=0; k<oDivs.length; k++) 
            if ( GetElementName(oDivs[k]).indexOf("TitleDiv")==0 ) {
              oDivs[k].className = ( pos_found==pos ? oDivs[k].className.replace("_off", "_on").replace("-off", "-on") : oDivs[k].className.replace("_on", "_off").replace("-on", "-off") );
              pos_title_found++;
            }
            else if ( GetElementName(oDivs[k]).indexOf("ContentDiv")==0 ) {
              oDivs[k].style.display = ( pos_found==pos ? "" : "none" );
              pos_found++;
            }
        }
  }
}

function ShowHideZoom(layerId, imgSrc)
{
  var layer = document.getElementById (layerId);
  if (layer) {
    if (imgSrc) {
      var imgs = layer.getElementsByTagName("img");
      if (imgs!=null && imgs.length>0) imgs[0].src = imgSrc;
      layer.style.display = "block";
    }
    else layer.style.display = "none";
  }
}



function SwitchVisibilityCaixaRegioes(oNameDivSelected, oNameDivUnselected, oNameDivUnselected2, oNameDivUnselected3, oNameDivUnselected4, justSwitch, property, affectObjId)
{
    var oDiv1 = document.getElementById(oNameDivSelected);
    var oDiv2 = document.getElementById(oNameDivUnselected);
    var oDiv3 = document.getElementById(oNameDivUnselected2);
    var oDiv4 = document.getElementById(oNameDivUnselected3);
    var oDiv5 = document.getElementById(oNameDivUnselected4);
    var affectObj = affectObjId ? document.getElementById(affectObjId) : null;
    if ( oDiv1 && oDiv2 && oDiv3 && oDiv4 && oDiv5 ){
      if( (!property || property=="display") && oDiv1.style.display == "")
      {
        oDiv1.style.display = "none";
        if (justSwitch)
          {
            oDiv2.style.display = "";
            oDiv3.style.display = "";
            oDiv4.style.display = "";
            oDiv5.style.display = "";
          }
          
        else if (affectObj) affectObj.style.lineHeight = "1px";
      }
      else if (!property || property=="display")
      {
        oDiv1.style.display = "";
        oDiv2.style.display = "none";
        oDiv3.style.display = "none";
        oDiv4.style.display = "none";
        oDiv5.style.display = "none";
        if (affectObj) affectObj.style.lineHeight = ( ( IsIE() ? 5 : 11) + oDiv1.offsetHeight ) + "px"; 
      }
      else if( property=="visibility" && oDiv1.style.visibility == "visible")
      {
        oDiv1.style.visibility = "hidden";
        if (justSwitch)
        {
          oDiv2.style.visibility = "visible";
          oDiv3.style.visibility = "visible";
          oDiv4.style.visibility = "visible";
          oDiv5.style.visibility = "visible";
        }
      }
      else 
      {
        oDiv1.style.visibility = "visible";
        oDiv2.style.visibility = "hidden";
        oDiv3.style.visibility = "hidden";
        oDiv4.style.visibility = "hidden";
        oDiv5.style.visibility = "hidden";
      }
   }
}




var ArrayEdImpressa = new Array ();
var EdImpressaPos = 0;

function EdImpressa(img,pre_title, title, link)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.html = EdImpressaHTML(this.img, this.pre_title, this.title, this.link);
    return this;
}

function EdImpressaHTML(img, pre_title, title, link)
{
    return (!img ? '<div class="cx-multiusos-tipo-a-slidescln-meio" style="height:200px">&nbsp;</div>' : '<div class="cx-multiusos-tipo-a-slidescln-meio" style="height:200px"><a href="' + link + '"><img src="' + img + '" alt="' + title + '" title="' + title + '" width="108" /></a><p><a href="' + link + '">' + title + '</a></p></div>');
}



var ArrayCronista = new Array ();
var CronistaPos = 0;

function Cronista(img, pre_title, title, link)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.html = CronistaHTML(this.img, this.pre_title, this.title, this.link);
    return this;
}

function CronistaHTML(img, pre_title, title, link)
{
    return ( !img ? '<div class="cx-cronista">&nbsp;</div>' : '' +
        '<div class="cx-cronista">' +
				      ( link ? '<a href="' + link + '"><img src="' + img + '" width="52" height="64"/></a>' : '<img src="' + img + '" width="52" height="64"/>')+
				      '<div class="cx-cronista-nome">' + title + '</div>' +
				      ( pre_title ? '<div class="cx-cronista-cargo">' + pre_title + '</div>' : '' ) +
			  '</div>' );
}




var ArrayGaleria = new Array ();
var GaleriaPos = 0;

function Galeria(img, pre_title, title, link)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.html = GaleriaDefaultHTML(this.img, this.pre_title, this.title, this.link, "cx-galeria-cln", 292, 200);
    return this;
}
function GaleriaHTML(img, pre_title, title, link, css_name, img_width, img_height)
{
  return GaleriaDefaultHTML(img, pre_title, title, link, css_name, img_width, img_height);
}

var ArrayVideo = new Array ();
var VideoPos = 0;

function Video(img, pre_title, title, link, id, date, link_video, summary, display_type)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.id = id;
    this.date = date;
    this.summary = summary.replace('<p> </p>', '');
    this.link_video = link_video;
    this.display_type = display_type;
    this.html = VideoHTML(this.img, this.pre_title, this.title, this.link, "cx-fotovideo-cln-meio-uni", 120, 100, this.id, this.date, this.link_video, this.summary, this.display_type);
    
    if (!ArrayVideo.length) ShowVideoOnPlayer(this, true);
    return this;
}

function VideoHTML(img, pre_title, title, link, css_name, img_width, img_height, id, date, link_video, summary,display_type)
{
    var css = css_name ? ' class="' + css_name + '"' : '';
    return ( !img ? '<div' + css + '>&nbsp;</div>' : '' +
        '<div name="ListaVideoWrapper" ' + css + '>' +
            '<a href="javascript:Empty()" onclick="ShowVideoOnPlayer(this)">' +
                '<img src="' + img + '" width="' + img_width + '" height="' + img_height + '" alt="' + title + '" title="' + title + '"/><br/>' +
            '</a>' +
            '<p><strong>' + pre_title + '</strong></p>' +
            '<p><a name="content-title" href="javascript:Empty()" onclick="ShowVideoOnPlayer(this)">' + title + '</a></p>' +
            ( id ? '<input type="hidden" name="content-id" value="' + id + '"/>' : '' ) +
            ( link ? '<input type="hidden" name="content-link" value="' + link + '"/>' : '' ) +
            ( date ? '<input type="hidden" name="content-date" value="' + date + '"/>' : '' ) +
            ( summary ? '<div style="display:none" name="content-summary">' + summary + '</div>' : '' ) +
            '<input type="hidden" name="video-link" value="' + link_video + '"/>' +
            '<input type="hidden" name="display-type" value="' + display_type + '"/>' +
        '</div>' );
}

function ShowVideoOnPlayer(obj, fromObj)
{
  var titleDestaque, dateDestaque, videoDestaque, idDestaque, summaryDestaque, visitas;
  var titleLista, linkLista, dateLista, videoLista, idLista, summaryLista;
  if (obj) {
    var parentDestaque = document.getElementById("DestaqueVideoWrapper");
    if (parentDestaque) {
      idDestaque = GetDescendant(parentDestaque, "content-id", "input");
      titleDestaque = GetDescendant(parentDestaque, "title", "a");
      dateDestaque = GetDescendant(parentDestaque, "date", "p");
      //videoDestaque = GetDescendant(parentDestaque, "video", "img");
      summaryDestaque = GetDescendant(parentDestaque, "summary", "div");
      visitas = GetDescendant(parentDestaque, "visitas", "span");
    }
    
    if (fromObj){
      if (titleDestaque){
        titleDestaque.href = obj.link;
        titleDestaque.innerHTML = obj.title;
      }
      ArrayStartupVideo.push('try {replacePlayList("BoxVideo","/common/services/buildplaylist.aspx?content_id=' + obj.id + '|' + obj.display_type + '|0")} catch(exp){}');
      if (dateDestaque) dateDestaque.innerHTML = GetFormatedDate(obj.date);
      if (summaryDestaque) summaryDestaque.innerHTML = obj.summary;
      //if (videoDestaque) videoDestaque.src = obj.link_video;
      getPlayerVisits(visitas, obj.id);
      idDestaque.id = "VideoVote" + obj.id;
      idDestaque.value = obj.id;
      GetRating(idDestaque, "VideoVote");
    }
    else {
      var parentListaItm = GetAncestor(obj, "ListaVideoWrapper");
      if (parentListaItm) {
        titleLista = GetDescendant(parentListaItm, "content-title", "a");
        linkLista = GetDescendant(parentListaItm, "content-link", "input");
        dateLista = GetDescendant(parentListaItm, "content-date", "input");
        //videoLista = GetDescendant(parentListaItm, "video-link", "input");
        idLista = GetDescendant(parentListaItm, "content-id", "input");
        summaryLista = GetDescendant(parentListaItm, "content-summary", "div");
        displayType = GetDescendant(parentListaItm, "display-type", "input");
      }
      if (titleDestaque && titleLista && linkLista){
        titleDestaque.href = linkLista.value;
        titleDestaque.innerHTML = titleLista.innerHTML;
      }
      if (dateDestaque && dateLista) dateDestaque.innerHTML = GetFormatedDate(dateLista.value.toString());
      //if (videoDestaque && videoLista) videoDestaque.src = videoLista.value;
      if (summaryDestaque && summaryLista) summaryDestaque.innerHTML = summaryLista.innerHTML;
      try {replacePlayList("BoxVideo","/common/services/buildplaylist.aspx?content_id=" + idLista.value + "|" + displayType.value +  "|1");} catch(exp){}
      getPlayerVisits(visitas,idLista.value);
      idDestaque.id = "VideoVote" +idLista.value;
      idDestaque.value = idLista.value;
      GetRating(idDestaque, "VideoVote");
    }
    
  }
}

var ArrayCartoon = new Array ();
var CartoonPos = 0;

function Cartoon(img, pre_title, title, link, id, date, section)
{
    this.img = img;
    this.title = section;
    this.date = date.substring(0, 10);
    this.html = CartoonHTML(this.img, this.title, this.date);
    if (!ArrayCartoon.length) ShowCartoon(0, this);
    return this;
}

function CartoonHTML(img, title, date)
{
    return ( !img ? '<div>&nbsp;</div>' : '' +
        '<center>' +
           '<img src="' + img + '" alt="' + title + '" width="500" height="190"/>' +
        '</center>' );
}
function ShowCartoon(pos, obj)
{
  var titleDestaque, dateDestaque;

  var parentDestaque = document.getElementById("DestaqueCartoonWrapper");
  if (parentDestaque) {
    titleDestaque = GetDescendant(parentDestaque, "title", "a");
    dateDestaque = GetDescendant(parentDestaque, "date", "p");
  }  
  var fromObj;
  if (pos>0) {
    if (CartoonPos==ArrayCartoon.length-1) fromObj = ArrayCartoon[0];
    else fromObj = ArrayCartoon[CartoonPos+1];
  }
  else if (pos<0){
    if (CartoonPos==0) fromObj = ArrayCartoon[ArrayCartoon.length-1];
    else fromObj = ArrayCartoon[CartoonPos-1];
  }
  else fromObj = obj;
  
  if (fromObj){
    if (dateDestaque) dateDestaque.innerHTML = GetFormatedDate(fromObj.date); 
    if (titleDestaque) titleDestaque.innerHTML = fromObj.title.replace("&", "&amp;");
  }
  

}


var ArrayTopico = new Array ();
var TopicoPos = 0;

function Topico(img, pre_title, title, link, id, date, summary)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.id = id;
    this.date = date;
    this.summary = summary.replace('<p> </p>', '');;
     this.html = TopicoHTML(this.img, this.pre_title, this.title, this.link, "cx-galeriatopicos-cln", 120, 100, this.id, this.date, this.summary);
    if (!ArrayTopico.length) ShowTopico(this, true);
    return this;
}

function TopicoHTML(img, pre_title, title, link, css_name, img_width, img_height, id, date, summary)
{
    var css = css_name ? ' class="' + css_name + '"' : '';
    return ( !img ? '<div' + css + '>&nbsp;</div>' : '' +
        '<div name="ListaTopicoWrapper" ' + css + '>' +
            '<a href="javascript:Empty()" onclick="ShowTopico(this)">' +
                '<img name="content-img" src="' + img + '" width="' + img_width + '" height="' + img_height + '" alt="' + title + '" title="' + title + '"/><br/>' +
            '</a>' +
            '<p>' +
               '<strong>' + pre_title + '</strong><br/>' +
               '<a name="content-title" href="javascript:Empty()" onclick="ShowTopico(this)">' + title + '</a>' +
            '</p>' +
            ( link ? '<input type="hidden" name="content-link" value="' + link + '"/>' : '' ) +
            ( date ? '<input type="hidden" name="content-date" value="' + date + '"/>' : '' ) +
            ( summary ? '<div style="display:none" name="content-summary">' + summary + '</div>' : '' ) +
        '</div>' );
}
function ShowTopico(obj, fromObj)
{
  var titleDestaque, dateDestaque, imgDestaque, idDestaque, summaryDestaque;
  var titleLista, linkLista, dateLista, imgLista, idLista, summaryLista;
  if (obj) {
    var parentDestaque = document.getElementById("DestaqueTopicoWrapper");
    if (parentDestaque) {
      titleDestaque = GetDescendant(parentDestaque, "title", "a");
      dateDestaque = GetDescendant(parentDestaque, "date", "p");
      imgDestaque = GetDescendant(parentDestaque, "image", "img");
      summaryDestaque = GetDescendant(parentDestaque, "summary", "td");
    }
    
    if (fromObj){
      if (titleDestaque){
        titleDestaque.href = obj.link;
        titleDestaque.innerHTML = obj.title;
      }
      if (dateDestaque) dateDestaque.innerHTML = GetFormatedDate(obj.date);
      if (summaryDestaque) summaryDestaque.innerHTML = obj.summary;
      if (imgDestaque) imgDestaque.src = obj.img;
    }
    else {
      var parentListaItm = GetAncestor(obj, "ListaTopicoWrapper");
      if (parentListaItm) {
        titleLista = GetDescendant(parentListaItm, "content-title", "a");
        linkLista = GetDescendant(parentListaItm, "content-link", "input");
        dateLista = GetDescendant(parentListaItm, "content-date", "input");
        imgLista = GetDescendant(parentListaItm, "content-img", "img");
        summaryLista = GetDescendant(parentListaItm, "content-summary", "div");
      }
      if (titleDestaque && titleLista && linkLista){
        titleDestaque.href = linkLista.value;
        titleDestaque.innerHTML = titleLista.innerHTML;
      }
      if (dateDestaque && dateLista) dateDestaque.innerHTML = GetFormatedDate(dateLista.value.toString());
      if (imgDestaque && imgLista) imgDestaque.src = imgLista.src;
      if (summaryDestaque && summaryLista) summaryDestaque.innerHTML = summaryLista.innerHTML;

    }
    
  }
}


var ArrayDossie = new Array ();
var DossiePos = 0;

function Dossie(img, pre_title, title, link)
{
    this.img = img;
    this.pre_title = pre_title;
    this.title = title;
    this.link = link;
    this.html = DossieHTML(this.img, this.pre_title, this.title, this.link, "cx-dossie-cln", 120, 72);
    return this;
}

function DossieHTML(img, pre_title, title, link, css_name, img_width, img_height)
{
  return GaleriaDefaultHTML(img, pre_title, title, link, css_name, img_width, img_height);
}

function GaleriaDefaultHTML(img, pre_title, title, link, css_name, img_width, img_height)
{
    var css = css_name ? ' class="' + css_name + '"' : '';
    return ( !img ? '<div' + css + '>&nbsp;</div>' : '' +
        '<div' + css + '>' +
            '<a href="' + link + '"' + ( link.toLowerCase().indexOf('http://') >= 0 ? ' target="_blank"' : '' ) + '>' +
                '<img src="' + img + '" width="' + img_width + '" height="' + img_height + '" alt="' + title + '" title="' + title + '"/><br/>' +
            '</a>' +
            '<p><strong>' + pre_title + '</strong></p>' +
            '<p><a href="' + link + '">' + title + '</a></p><br/>' +
        '</div>' );
}

	function isReady() {
		return jsReady;
	}
	function linkInit() {
		jsReady = true;
		if (IsIE()) EvalVideo();
		else window.setTimeout("EvalVideo()", 8000);
	}
	function thisMovie(movieName) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
	    return document.getElementById(movieName);
		} else {
			return document[movieName];
		}
	}
	function jumpToMedia(playername,value) {
		thisMovie(playername).jumpToMedia(value);
	}
	function replacePlayList(playername,value) {
		thisMovie(playername).replacePlayList(value);
	}

  function trace(qualquer)
  {
    alert(qualquer);
  }



function SetPollControl()
{
  var ancestor = document.getElementById("SondagemWrapper");
  if (ancestor) {
    var k, pollId = 0, resultsWrapper = null, divsArr = ancestor.getElementsByTagName("div");
    for (k=0; k<divsArr.length; k++)
      if (divsArr[k].id.search(/Poll([0-9]+)Results/gi)==0) {
        resultsWrapper = divsArr[k];
        pollId = divsArr[k].id.replace("Poll", "").replace("Results", "");
        break;
      }
    if (resultsWrapper && 1*pollId>0 && LoadCookie("AnswerPoll" + pollId)!=null ){
      ShowHidePollResults(pollId, true);
      HidePollControls(resultsWrapper);
    }
  }
}

function HidePollControls(resultsWrapper)
{
    var k, divsArr = resultsWrapper.getElementsByTagName("div");
    for (k=0; k<divsArr.length; k++)
      if (divsArr[k].className == "poll-controls") {
        divsArr[k].style.display = "none";
        break;
      }
}

function SavePollChoicesCookie(pollId)
{
  var choicesStr = "";
  var pollWrapper = document.getElementById("Poll" + pollId + "Wrapper");
  if (pollWrapper) {
    var k, choicesBts = pollWrapper.getElementsByTagName("input");
    for (k=0; k<choicesBts.length; k++){
      if (k>0) choicesStr += "|";
      choicesStr += choicesBts[k].value;
    }
  }
  if (choicesStr != "") SaveCookie("ChoicesPoll" + pollId, escape(choicesStr));
}

function VotePoll(pollId)
{
  var pollWrapper = document.getElementById("Poll" + pollId + "Wrapper");
  if (pollWrapper) {
    var k, choicesStr="", choicesBts = pollWrapper.getElementsByTagName("input");
    var go_vote = false;
    for (k=0; k<choicesBts.length; k++){
      if (k>0) choicesStr += "|";
      choicesStr += choicesBts[k].value;
      if (choicesBts[k].checked) {
        SaveCookie("AnswerPoll" + pollId, escape(choicesBts[k].value) );
        go_vote = true;
      }
    }
    if (go_vote) {
      SaveCookie("ChoicesPoll" + pollId, escape(choicesStr));
      var ifr = document.getElementById("ifrPoll");
      if (ifr) ifr.src = "/Common/Services/VotePoll.aspx?poll_id=" + pollId;
    }
  }
}


function PollHasVoted(pollId)
{
  var pollHasVotedWrapper = document.getElementById("Poll" + pollId + "HasVoted");
  if (pollHasVotedWrapper) pollHasVotedWrapper.style.display = "";
  //ShowHidePollResults(pollId, true, false);
}

function PollResults(pollId, resultArr)
{
  SavePollChoicesCookie(pollId);
  var resultsDiv = document.getElementById("Poll" + pollId + "Results");
  if (resultsDiv) {
     var k, optionSpans = resultsDiv.getElementsByTagName("span");
     var total = 0;
     if (optionSpans && optionSpans.length ) {
       for (k=0; k<optionSpans.length; k++) {
          optionSpans[k].innerHTML = ( resultArr && resultArr[k] ? resultArr[k] + (resultArr[k]==1 ? " voto" : " votos") : "0 votos" );
          total += 1* ( resultArr && resultArr[k] ? resultArr[k] : "0" );
       }
       var bars = GetDescendants(resultsDiv, "Poll" + pollId + "Result", "div");
       var barsperc = GetDescendants(resultsDiv, "Poll" + pollId + "ResultPerc", "div");
       if (bars.length) {
          for (k=0; k<optionSpans.length; k++) {
            var percent = ( ( resultArr && resultArr[k] ? resultArr[k] : "0" )*1 ? ( resultArr && resultArr[k] ? resultArr[k] : "0" )/total : "0" );
            bars[k].style.width = Math.round(bars[0].parentNode.offsetWidth * percent) + "px";
            barsperc[k].style.width = bars[k].style.width;
            barsperc[k].innerHTML = Math.round(percent*100) + "%";
            //alert(barsperc[k].parentNode.outerHTML);
          }
       }
          
     }
  }
}

function ShowHidePollResults(pollId, show, justVoted)
{
  var choicesDiv = document.getElementById("Poll" + pollId + "Choices");
  var resultsDiv = document.getElementById("Poll" + pollId + "Results");
  if (choicesDiv) choicesDiv.style.display = ( show ? "none" : "");
  if (resultsDiv) {
    resultsDiv.style.display = ( !show ? "none" : "");
    if (show) {
   
      var optionSpans = resultsDiv.getElementsByTagName("span");
      if (optionSpans && optionSpans.length) 
        if (!IsNumeric(optionSpans[0].innerHTML) || justVoted) {
          var ifr = document.getElementById("ifrPoll");
          if (ifr) ifr.src = "/Common/Services/VotePoll.aspx?poll_id=" + pollId + "&action=view" + (justVoted ? "&usecache=false" : "");
        }
    }
    else {
      var pollHasVotedWrapper = document.getElementById("Poll" + pollId + "HasVoted");
      if (pollHasVotedWrapper) pollHasVotedWrapper.style.display = "none";
    }
  }
}


function PollAnswerSaved(pollId)
{
  ShowHidePollResults(pollId, true, true);
  var resultsWrapper = document.getElementById("Poll" + pollId + "Results");
  if (resultsWrapper) HidePollControls(resultsWrapper);
}



/*** Servicos ****/

var MeteoPath = "";
function SetMeteoPath(path) { MeteoPath = path; }
function GetMeteo(city)
{
 var ifr = document.getElementById("meteoIfr");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + escape(MeteoPath + "/" + city) + 
       "&objid=meteoContentDiv&func=" + escape("SetMeteoCity('" + city + "')");
   ifr.src = loc;
 }
 ShowHideLayer('meteoLayer', false);
}

function GetMeteoByCombo(obj)
{
 var city = obj.value;
 var pathEscaped = escape(MeteoPath + "/" + city);
 var ifr = document.getElementById("meteoIfr");
 var sdate = document.getElementById("cbDataMeteo");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("date=" + sdate.value) +
       "&objid=meteoContentDiv&func=" + escape("SetMeteoCityByCombo('" + city + "')");
   ifr.src = loc;
 }
}

function GetMeteoByComboDate(obj)
{
 var sdate = obj.value;
 var city = document.getElementById("meteorologialist");
 var pathEscaped = escape(MeteoPath + "/" + city.value);
 var ifr = document.getElementById("meteoIfr");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("date=" + sdate) +
       "&objid=meteoContentDiv&func=" + escape("SetMeteoCityByCombo('" + city.value + "')");
   ifr.src = loc;
 }
}

function GetMeteoByComboHome(obj)
{
 var city = obj.value;
 var pathEscaped = escape(MeteoPath + "/" + city);
 var ifr = document.getElementById("meteoIfr");

 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&style=" + escape("Meteo Simple * DN") +
       "&objid=meteoContentDiv&func=" + escape("SetMeteoCityByCombo('" + city + "')");
   ifr.src = loc;
 }
}





function GetHoroscopoByCombo(obj)
{
 var signo = obj.value;
 if (signo!=-1){ 
 var pathEscaped = escape("/NewsGen/Publicação/DN/Serviços/Horóscopo");
 var ifr = document.getElementById("horoscopoIfr");
 SaveCookie("DN_Signo", escape(signo));
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("signo=" + signo) +
       "&objid=HoroscopoContentCol";
   ifr.src = loc;
 }
 GetFamososByCombo(obj);
}
}
function GetHoroscopoByParam(signo)
{

 var pathEscaped = escape("/NewsGen/Publicação/DN/Serviços/Horóscopo");
 var ifr = document.getElementById("horoscopoIfr");
 SaveCookie("DN_Signo", escape(signo));
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("signo=" + signo) +
       "&objid=HoroscopoContentCol";
   ifr.src = loc;
   
 }
 GetFamososByParam(signo);
}
function GetFamososByCombo(obj)
{
 var signo = obj.value;
 if (signo!=-1){ 
 var pathEscaped = escape("/NewsGen/Publicação/DN/Início/Pessoas/Publicação Automática/Faz Anos/" + signo);
 var ifr = document.getElementById("famososIfr");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("signo=" + signo) +
       "&objid=FamososContentCol";
   ifr.src = loc;
 }
}
}
function GetFamososByParam(signo)
{

 var pathEscaped = escape("/NewsGen/Publicação/DN/Início/Pessoas/Publicação Automática/Faz Anos/" + signo);
 var ifr = document.getElementById("famososIfr");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + pathEscaped + 
       "&qc=" + escape("signo=" + signo) +
       "&objid=FamososContentCol";
   ifr.src = loc;}
}

function GetJogosByCombo(obj)
{
 var link = obj.value;
 document.location = "totojogos.aspx#" + link;
}

//function GetMeteoByComboHome(obj)
//{
// var city = obj.value;
// SaveCookie("DN_MeteoCity", escape(city));
// document.location = "meteo.aspx";
//}

function GetHoroscopoByComboHome(obj)
{
 var signo = obj.value;
 SaveCookie("DN_Signo", escape(signo));
 document.location = "horoscopo.aspx";
}

function SetMeteoCityByCombo(city)
{    
 SaveCookie("DN_MeteoCity", escape(city));
}

function SetMeteoCity(city)
{
 var obj = document.getElementById("meteoCity");
 if (obj) obj.innerHTML = city;
 SaveCookie("DN_MeteoCity", escape(city));
}

function SetAssyncContent(html, objId, func)
{
 var obj = document.getElementById(objId);
 if (obj) {
   obj.innerHTML = html;
   if (func) eval(func);
 }
}

function ShowHideLayer(layerId, show)
{
 var layer = document.getElementById(layerId);
 if (layer) layer.style.visibility = ( show ? "visible" : "hidden" );
}

  function ResetCmb(regionObj, concelhoId, regionArr)
  {
    var concelhoObj = document.getElementById(concelhoId);
    if (regionObj && concelhoObj && regionArr) {
      var k;
      for ( k=0; k<regionArr.length; k++ ) {
        if (regionArr[k].length == 2) {
          var region = regionArr[k][0];
          if (region == regionObj.value) {
            var locationArr = regionArr[k][1]; 
            concelhoObj.length = 0;
            var i;
            concelhoObj.options[0] = new Option("...", "");
            for ( i=0; i<locationArr.length; i++) {
              concelhoObj.options[i+1] = new Option(locationArr[i], locationArr[i]);
            }
            break;
          }
        }
      }
    }
  }
  
  function ResetCmbEleicoes(regionObj, concelhoId, regionArr)
  {
    var concelhoObj = document.getElementById(concelhoId);
    if (regionObj && concelhoObj && regionArr) {
      var k;
      for ( k=0; k<regionArr.length; k++ ) {
        if (regionArr[k].length == 2) {
          var region = regionArr[k][0];
          if (region == regionObj.value) {
            var locationArr = regionArr[k][1]; 
            concelhoObj.length = 0;
            var i;
            if (concelhoId=='concelho') concelhoObj.options[0] = new Option("Concelho", "");
            if (concelhoId=='freguesia') concelhoObj.options[0] = new Option("Freguesia", "");
            for ( i=0; i<locationArr.length; i++) {
              concelhoObj.options[i+1] = new Option(locationArr[i][1], locationArr[i][0]);
            }
            break;
          }
        }
      }
    }
  }

  function CleanCombo(objname)
  {
    var obj = document.getElementById(objname);
    for(var count = obj.options.length - 1; count >= 0; count--)
    {
        obj.options[count] = null;
        if (objname=='distrito') obj.options[0] = new Option("Distrito", "");
        if (objname=='concelho') obj.options[0] = new Option("Concelho", "");
        if (objname=='freguesia') obj.options[0] = new Option("Freguesia", "");
    }
  }
  
  
  function ChangeConcelho(locationObj,distritoId)
  {
    var distritoObj = document.getElementById(distritoId);
    document.location.href="/paginainicial/pais/concelho.aspx?Distrito=" + distritoObj.value + "&Concelho=" + locationObj.value + "&Option=News";
  }
  
  function ChangeConcelhoFarmacias(locationObj,distritoId)
  {
    var distritoObj = document.getElementById(distritoId);
    if (locationObj.value) {
        SaveCookie("DN_FarmaciasRegion", escape(distritoObj.value));
        SaveCookie("DN_FarmaciasLocation", escape(locationObj.value));
        document.location.href="/servicos/farmacias.aspx?region=" + distritoObj.value + "&location=" + locationObj.value;
     }
  }
  

function CreateRoteirosLink()
{
  var type = document.getElementById("roteirosTypeCmb");
  var region = document.getElementById("roteirosRegionCmb");
  var orderBy = document.getElementById("roteirosOrderBy");
  
  if ( type && region && orderBy ) {
     SaveCookie("TSF_RoteirosRegion", escape(region.value));
     document.location = "/servicos/cartaz.aspx?display=" + escape(orderBy.value) + 
        "&region=" + escape(region.value) + 
        "&type=" + escape(type.value);
  }
}

function SetSearchBox (obj)
{
    if( !obj.value || obj.title == obj.value ) {
      obj.value = '';
    }
}

function GoSearch(obj, evnt, type)
{
  if (obj && evnt.keyCode == 13)
  { 
    try {
      evnt.cancelBubble = true; 
      evnt.returnValue = false;     
    } catch (exp) {}
    return SubmitSearch(obj, type);
  }
}

function FindSearchCriteria(idSearch, type)
{
  var obj = document.getElementById(idSearch);
  if (obj) return SubmitSearch(obj, type);
}

function SubmitSearch(obj, type)
{
    if( !obj.value || obj.title == obj.value ) {
      obj.value = '';
      //alert("Escolha um critério de pesquisa");
      obj.focus();
    }
    else if (type == 'Classificados')
      document.location='http://classificados.lojadojornal.pt/dn/Entrada.aspx?EP=5&Texto=' + escape(obj.value.replace('"','').replace('"',''));
    else { 
      var loc = '/pesquisa/default.aspx?Pesquisa=' + obj.value.replace('"','').replace('"','');
      document.forms[0].action = loc;
      SaveCookie("TopBoxSearch", "1");
      top.document.location = loc;
    }
}

function submitLigas(obj)
{
  if(obj.value=="Liga" || obj.value=="Liga de Honra")
  {
    document.location="/desporto/classificacoes/default.aspx?Type=principal&Name="+obj.value;
  }
  else
  {
    document.location="/desporto/classificacoes/default.aspx?Type=menor&Name="+obj.value;
  }
}

function submitClubes(obj)
{
  document.location=obj.value;
}

function SubmitTransito(obj)
{
    if( obj) {
      document.location='/servicos/transito.aspx?detalhe=' + obj.value.replace('"','').replace('"','');
      }
}


var TickerOffset = 1;
var TickerOffsetLastFromButton = -1;
var TickerPaused = false;
function SetTicker(op, from_button)
{
   if ( (TickerPaused && !from_button) || (Math.abs(TickerOffsetLastFromButton-TickerOffset)<=1 && !from_button) ) return;
   var new_offset = 0;
   switch (op) {
    case 0: TickerPaused = true; break;
    case 1: new_offset = ( TickerOffset >= 10 ? 1 : TickerOffset+1 ); break;
    case -1: new_offset = ( TickerOffset <= 1 ? 10 : TickerOffset-1 ); break;
   }
   if (op) {
    if (from_button) TickerOffsetLast = TickerOffset;
    var obj_old = document.getElementById("Ticker" + TickerOffset);
    var obj_new = document.getElementById("Ticker" + new_offset);
    if (obj_old) obj_old.style.display = "none";
    if (obj_new) obj_new.style.display = "";
    TickerOffset = new_offset;
    window.setTimeout("SetTicker(1)", 10000); 
   }
}





var bScrollDiv = false;
var bHasScroll = true; 
var imgScrollerRightSrc, imgScrollerLeftSrc;

function SetScroller(sDiv, imgRight, imgLeft, typeScroller)
{
   imgScrollerRightSrc = imgRight;
   imgScrollerLeftSrc = imgLeft;
   var oDiv = document.getElementById(sDiv);
   if (oDiv) {
      var oParent = oDiv.parentNode;
      if (oParent) {
        if( oParent.clientWidth < oDiv.clientWidth ) {
            var arrowRightLink = document.getElementById("linkScrollerRight" + ( typeScroller == null ? "" : typeScroller ) );
            var arrowRightImg = document.getElementById("imgScrollerRight" + ( typeScroller == null ? "" : typeScroller ) );
            if (arrowRightLink && arrowRightImg) {
              arrowRightImg.src = imgScrollerRightSrc;
              arrowRightLink.href="javascript:Empty()";
            }
        }
      }
  }
}
   
function ScrollDiv (sDiv, direction, bSetFlag, typeScroller) {
  if ( bSetFlag ) bScrollDiv = true;
  
  try {
     var oDiv = document.getElementById(sDiv);
     if (oDiv) {
        var oParent = oDiv.parentNode, sNewPos = 0, sPos = ( oDiv.style.left ? oDiv.style.left : -1 ), divWidth = oDiv.clientWidth - oParent.clientWidth;
        if ( sPos && bScrollDiv ) {
           sPos = sPos.toString().replace(/px/, "").replace(/pt/, "");
           sNewPos = sPos*1 + direction;
           
            var arrowLeftLink = document.getElementById("linkScrollerLeft" + ( typeScroller == null ? "" : typeScroller ));
            var arrowLeftImg = document.getElementById("imgScrollerLeft" + ( typeScroller == null ? "" : typeScroller ));
            var arrowRightLink = document.getElementById("linkScrollerRight" + ( typeScroller == null ? "" : typeScroller ));
            var arrowRightImg = document.getElementById("imgScrollerRight" + ( typeScroller == null ? "" : typeScroller ));
              
           if (arrowLeftLink!=null && arrowLeftImg!=null && arrowRightLink!=null && arrowRightImg!=null && sNewPos <= 0 && sNewPos >= -divWidth){
              if (bHasScroll)
                if (arrowLeftImg.src.indexOf("1x1t.gif")>0) {
                  arrowLeftImg.src = imgScrollerLeftSrc;
                  arrowLeftLink.href="javascript:Empty()";
                }
                else if (arrowRightImg.src.indexOf("1x1t.gif")>0) { 
                  arrowRightImg.src = imgScrollerRightSrc;
                  arrowRightLink.href="javascript:Empty()";
                }
              oDiv.style.left = sNewPos + "px";
              window.setTimeout("ScrollDiv('" + sDiv + "', " + direction + ", false, '" + ( typeScroller == null ? "" : typeScroller ) + "')", 1);
           }
           else {
              if ( direction > 0 ){
                arrowLeftImg.src = "/common/images/1x1t.gif";
                arrowLeftLink.attributes.removeNamedItem("HREF");
              }
              else {
                arrowRightImg.src = "/common/images/1x1t.gif";
                arrowRightLink.attributes.removeNamedItem("HREF");
              }
           }
        }
     }
  } catch(e){ alert(e.description) }
}



function ScrollDivStop () { bScrollDiv = false }



function GetContentInPath(path, divId, obj, tag, classNameNormal, classNameSelected, idLinkVerMais, linkVerMais)
{

 var ifr = document.getElementById("contentIfr");

 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?path=" + escape(path) + "&objid=" + divId;
   ifr.src = loc;
 }
 if (obj) {
  var k;
  var allspans = obj.parentNode.getElementsByTagName(tag);
  if (allspans && allspans.length){
    for (k=0; k<allspans.length; k++)
      if ( allspans[k].className == classNameSelected ) {
        allspans[k].className = allspans[k].className.replace(classNameSelected, classNameNormal);
        break;
      }
  }
  var objspans = obj.getElementsByTagName(tag);
  if (objspans && objspans.length)
   for (k=0; k<objspans.length; k++)
     if ( objspans[k].className == classNameNormal ) {
        objspans[k].className = objspans[k].className.replace(classNameNormal, classNameSelected);
        break;
      }
 }
 if (idLinkVerMais) {
  var link = document.getElementById(idLinkVerMais);
  if (link) link.href = linkVerMais;
 }
}

function GetContentInTag(tagname,tagsite,style, divId, obj, tag, classNameNormal, classNameSelected, iFrm)
{
 var ifr = document.getElementById(iFrm);
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?tag=" + escape(tagname) + "&tagsite=" + escape(tagsite) + "&style=" + escape(style) + "&objid=" + divId;
   ifr.src = loc;
 }
 if (obj) {
  var k;
  var allspans = obj.parentNode.getElementsByTagName(tag);
  if (allspans && allspans.length){
    for (k=0; k<allspans.length; k++)
      if ( allspans[k].className == classNameSelected ) {
        allspans[k].className = allspans[k].className.replace(classNameSelected, classNameNormal);
        break;
      }
  }
  var objspans = obj.getElementsByTagName(tag);
  if (objspans && objspans.length)
   for (k=0; k<objspans.length; k++)
     if ( objspans[k].className == classNameNormal ) {
        objspans[k].className = objspans[k].className.replace(classNameNormal, classNameSelected);
        break;
      }
 }

}
function GetContentById(content_id,style, divId, obj, tag, classNameNormal, classNameSelected)
{
 var ifr = document.getElementById("contentIfr");
 if (ifr) {
   var loc = "" +
     "/Common/Services/AssyncContent.aspx" +
       "?content_id=" + escape(content_id) + "&style=" + escape(style) + "&objid=" + divId;
   ifr.src = loc;
 }
 if (obj) {
  var k;
  var allspans = obj.parentNode.getElementsByTagName(tag);
  if (allspans && allspans.length){
    for (k=0; k<allspans.length; k++)
      if ( allspans[k].className == classNameSelected ) {
        allspans[k].className = allspans[k].className.replace(classNameSelected, classNameNormal);
        break;
      }
  }
  var objspans = obj.getElementsByTagName(tag);
  if (objspans && objspans.length)
   for (k=0; k<objspans.length; k++)
     if ( objspans[k].className == classNameNormal ) {
        objspans[k].className = objspans[k].className.replace(classNameNormal, classNameSelected);
        break;
      }
 }

}

function getPlayerVisits(obj, id_content)
{  
  if (obj) {
    GetAssyncContent("/common/services/stats.aspx?content_id=" + id_content + "&type=views", obj, "0");
    if ( obj.innerHTML == "1" ) 
      obj.parentNode.innerHTML = obj.parentNode.innerHTML.replace("&nbsp;vezes", "&nbsp;vez");
  }
}





var bScrollDivCxDesporto = false;
var bHasScrollCxDesporto = true; 


function SetScrollerCxDesporto(sDiv)
{
   var oDiv = document.getElementById(sDiv);
   if (oDiv) {
      var oParent = oDiv.parentNode;
      if (oParent) {
      
        if( oParent.clientWidth < oDiv.clientWidth ) {
            var arrowRightLink = document.getElementById("linkScrollerRightCxDesporto");
            var arrowRightImg = document.getElementById("imgScrollerRightCxDesporto");
            if (arrowRightLink && arrowRightImg) {
              arrowRightImg.src = "/Common/Images/img_desporto/bt_cx_desporto_peq_dir.gif";
              arrowRightLink.href="javascript:Empty()";
            }
        }
      }
  }
}
   
function ScrollDivCxDesporto (sDiv, direction, bSetFlag) {
  if ( bSetFlag ) bScrollDivCxDesporto = true;
  
  try {
     var oDiv = document.getElementById(sDiv);
     if (oDiv) {
        var oParent = oDiv.parentNode, sNewPos = 0, sPos = ( oDiv.style.left ? oDiv.style.left : -1 ), divWidth = oDiv.clientWidth - oParent.clientWidth;
        if ( sPos && bScrollDivCxDesporto ) {
           sPos = sPos.toString().replace(/px/, "").replace(/pt/, "");
           sNewPos = sPos*1 + direction;
           
            var arrowLeftLink = document.getElementById("linkScrollerLeftCxDesporto");
            var arrowLeftImg = document.getElementById("imgScrollerLeftCxDesporto");
            var arrowRightLink = document.getElementById("linkScrollerRightCxDesporto");
            var arrowRightImg = document.getElementById("imgScrollerRightCxDesporto");
              
           if (arrowLeftLink && arrowLeftImg && arrowRightLink && arrowRightImg && sNewPos <= 0 && (sNewPos >= -divWidth-50 )){
              if (bHasScrollCxDesporto)
                if (arrowLeftImg.src.indexOf("1x1t.gif")>0) {
                  arrowLeftImg.src = "/Common/Images/img_desporto/bt_cx_desporto_peq_esq.gif";
                  arrowLeftLink.href="javascript:Empty()";
                }
                else if (arrowRightImg.src.indexOf("1x1t.gif")>0) { 
                  arrowRightImg.src = "/Common/Images/img_desporto/bt_cx_desporto_peq_dir.gif";
                  arrowRightLink.href="javascript:Empty()";
                }
              oDiv.style.left = sNewPos + "px";
              window.setTimeout("ScrollDivCxDesporto('" + sDiv + "', " + direction + ")", 1);
           }
           else {
              if ( direction > 0 ){
                arrowLeftImg.src = "/common/images/1x1t.gif";
                arrowLeftLink.attributes.removeNamedItem("HREF");
              }
              else {
                arrowRightImg.src = "/common/images/1x1t.gif";
                arrowRightLink.attributes.removeNamedItem("HREF");
              }
              //oDiv.style.left = ( direction > 0 ? -divWidth : 0 ); 
              //window.setTimeout("ScrollDiv('" + sDiv + "', " + direction + ")", 1);
           }
        }
     }
  } catch(e){ alert(e.description) }
}

function ScrollDivStopCxDesporto () { bScrollDivCxDesporto = false }




function PlayClip(id, display_type)
{
  var ancestor = document.getElementById("ClipsSemana");
  if (ancestor) {
    var clipsArr, clipDetail, clipHeader, k;
    clipArr = GetDescendants(ancestor, "clip", "div");
    for (k=0; k<clipArr.length; k++) {
      clipDetail = GetDescendant(clipArr[k], "detail", "div");
      clipHeader = GetDescendant(clipArr[k], "header", "div");
      if (clipDetail!=null && clipHeader!=null) {
        if (clipArr[k].id == "Clip" + id) {
          clipHeader.className = "cx-clips-atocar";
          clipDetail.style.display = "";
        }
        else {
          clipHeader.className = "cx-clips-parado";
          clipDetail.style.display = "none";
        }
      }
    }  
  }
  try {replacePlayList("ClipsSemanaPlayer","/common/services/buildplaylist.aspx?content_id=" + id + "|" + display_type + "|1")} catch(exp){}
}



function GetStats(ancestorId, typeName) 
{
  var showVezes = true;
  var ancestor = document.getElementById(ancestorId);
  if (ancestor) {
    var visitsObj = GetDescendant(ancestor, "views", "span");
    if (!visitsObj) {
      visitsObj = GetDescendant(ancestor, "views", "strong");
      showVezes = false;
    }
    if (visitsObj) {
      var contentId = ancestorId.replace(typeName, "");
      //alert( visitsObj.parentNode.innerHTML);
      GetAssyncContent("/common/services/stats.aspx?content_id=" + contentId + "&type=views", visitsObj, "0");
      //alert( visitsObj.parentNode.innerHTML);
      if (!showVezes)
        visitsObj.parentNode.innerHTML = visitsObj.parentNode.innerHTML.replace(" vezes", "");
      else if ( visitsObj.innerHTML == "1" ) 
        visitsObj.parentNode.innerHTML = visitsObj.parentNode.innerHTML.replace(" vezes", " vez");
    }
  }
  
}

/************** ratings * start **************/

var bUsingRatingCookie = true;
			
function SetRatingVote(obj, vote, ancestorName)
{
  var ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    var cookieId = GetDescendant(ancestor, "content-id", "input");
    if (!bUsingRatingCookie || (cookieId!=null && !LoadCookie("Rating" + cookieId.value))) {
      SaveCookie("Rating" + cookieId.value, vote); 
      var ifr = document.getElementById("ifrRating");
      if (ifr) ifr.src = "/Common/Services/VoteRating.aspx?id=" + cookieId.value + "&vote=" + vote + "&action=register&objid=" + ancestorName + cookieId.value;
    }
  } 
}

var ratingsRequestQueue = new Array();

function GetRating(obj, ancestorName)
{

  var ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    var contentId = GetDescendant(ancestor, "content-id", "input");
    if ( contentId ) {
      ratingsRequestQueue.push("/Common/Services/VoteRating.aspx?id=" + contentId.value + "&action=view&objid=" + ancestorName + contentId.value);
    }
  } 
  
}

function GetRatingFromQueue()
{

  if (ratingsRequestQueue.length) {
    var loc = ratingsRequestQueue.pop();
    if (typeof ifrRating != 'undefined') ifrRating.location.replace(loc);
    else {
      var ifr = document.getElementById("ifrRating");
      if (ifr) ifr.src = loc;
    }
  }
  
}


function RatingResults(ratingId, ratingAverage, totalRatings, objId)
{
  //alert(ratingId + ", " + ratingAverage + ", " + totalRatings + ", " + objId);
  if (1*ratingAverage >= 0 && 1*ratingAverage<=5) {
    var obj = document.getElementById(objId);
    if (obj) {
      var ancestor = GetAncestor(obj, objId.replace(ratingId, ""));
      if (ancestor) {
        var k, imgArr = ancestor.getElementsByTagName("img");
        for (k=0; k<ratingAverage; k++) 
          imgArr[k].src = imgArr[k].src.replace("_0.", "_1.");
        for (k=ratingAverage; k<5; k++) 
          imgArr[k].src = imgArr[k].src.replace("_1.", "_0.");
        var rating = GetDescendant(ancestor, "rating", "input");
        if (rating) rating.value = ratingAverage;
        var votos = GetDescendant(ancestor, "votos", "span");
        if (votos) {
          votos.innerHTML = totalRatings;
          if (totalRatings==1) 
            votos.parentNode.innerHTML = votos.parentNode.innerHTML.replace("&nbsp;votos", "&nbsp;voto");
        }
        var cookieId = GetDescendant(ancestor, "content-id", "input");
        var linkArr = ancestor.getElementsByTagName("a");
        if (!bUsingRatingCookie || (cookieId!=null && !LoadCookie("Rating" + cookieId.value))) 
          for (k=0; k<linkArr.length; k++) {
            var namedItem = document.createAttribute("href");
            namedItem.value = "javascript:Empty()";
            linkArr[k].attributes.setNamedItem(namedItem);
          }
        else
          for (k=0; k<linkArr.length; k++) linkArr[k].attributes.removeNamedItem("href");
      }
    }
  }
  GetRatingFromQueue();
}

function OverRatingVote(obj, evnt, offset, ancestorName)
{

  var k, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    var cookieId = GetDescendant(ancestor, "content-id", "input");
    if (!bUsingRatingCookie || (cookieId!=null && !LoadCookie("Rating" + cookieId.value))) {
      var imgArr = ancestor.getElementsByTagName("img");
      var xCoordOld = GetDescendant(ancestor, "x-coord-old", "input");
      var xCoordNew = GetDescendant(ancestor, "x-coord-new", "input");
      var yCoordOld = GetDescendant(ancestor, "y-coord-old", "input");
      var yCoordNew = GetDescendant(ancestor, "y-coord-new", "input");
      if (xCoordOld && xCoordNew && yCoordOld && yCoordNew){
        SetMouseCoords	(obj, evnt, xCoordOld, xCoordNew, yCoordOld, yCoordNew);  
        //alert(xCoordOld.value + " < " + xCoordNew.value);
        for (k=0; k<=offset; k++) 
          imgArr[k].src = imgArr[k].src.replace("_0.", "_1.");
        for (k=offset+1; k<imgArr.length; k++) 
          imgArr[k].src = imgArr[k].src.replace("_1.", "_0.");
        
      }
    }
  }
  
}
function OutRatingVote(obj, evnt, offset, ancestorName)
{

  var k, ancestor = GetAncestor(obj, ancestorName);
  if (ancestor) {
    var cookieId = GetDescendant(ancestor, "content-id", "input");
    if (!bUsingRatingCookie || (cookieId!=null && !LoadCookie("Rating" + cookieId.value))) {
      var imgArr = ancestor.getElementsByTagName("img");
      var xCoordOld = GetDescendant(ancestor, "x-coord-old", "input");
      var xCoordNew = GetDescendant(ancestor, "x-coord-new", "input");
      var yCoordOld = GetDescendant(ancestor, "y-coord-old", "input");
      var yCoordNew = GetDescendant(ancestor, "y-coord-new", "input");
      if (xCoordOld && xCoordNew && yCoordOld && yCoordNew){
        SetMouseCoords	(obj, evnt, xCoordOld, xCoordNew, yCoordOld, yCoordNew);  
        //alert(xCoordOld.value + " > " + xCoordNew.value);
        for (k=0; k<offset; k++) 
          imgArr[k].src = imgArr[k].src.replace("_0.", "_1.");
        for (k=offset; k<imgArr.length; k++) 
          imgArr[k].src = imgArr[k].src.replace("_1.", "_0.");
        if ( offset == 0 || offset == (imgArr.length-1) || Math.abs(yCoordOld.value - yCoordNew.value) > 2 ) {
          var ratingAverage = 0, rating = GetDescendant(ancestor, "rating", "input");
          if (rating) ratingAverage = rating.value;
          for (k=0; k<ratingAverage; k++) 
            imgArr[k].src = imgArr[k].src.replace("_0.", "_1.");
          for (k=ratingAverage; k<imgArr.length; k++) 
            imgArr[k].src = imgArr[k].src.replace("_1.", "_0.");
        }
        //else alert(yCoordOld.value + " : " + yCoordNew.value + " : " + imgArr[0].height + " : " + imgArr[0].offsetTop);
      }
    }
  }
  
}		
function SetMouseCoords	(obj, evnt, xCoordOld, xCoordNew, yCoordOld, yCoordNew)
{
  if (xCoordOld && xCoordNew){
    var x = ((window.event)? evnt.x : evnt.pageX);
    if (x != xCoordNew.value) xCoordOld.value = xCoordNew.value;
    xCoordNew.value = x;
  }
  if (yCoordOld && yCoordNew){
    var y = ((window.event)? evnt.y : evnt.pageY);
    if (y != yCoordNew.value) yCoordOld.value = yCoordNew.value;
    yCoordNew.value = y;
  }
}


/************** ratings * end **************/

function submitHemeroteca(data)
{
  window.location="/pesquisa/default.aspx?data=" + data;
}
	  
function submitAnoHemeroteca(obj)
{
    if( obj) {
      document.location='/arquivo/default.aspx?y=' + obj.value.replace('"','').replace('"','');
      }
}

function submitDestaquesTV()
{

    var sDateobj = document.getElementById("cbDate");
    var sDate = sDateobj.options[sDateobj.selectedIndex].value;
    
    var sChannelobj=document.getElementById("cbChannel");
    var sChannel = sChannelobj.options[sChannelobj.selectedIndex].value;
    document.location='/inicio/tv/destaques.aspx?channel=' + sChannel + '&date=' + sDate;
    
}

function ShowAntidopingDetalhe(name)
{
        
       obj = document.getElementById("mais" + name);
       obj2 = document.getElementById("menos" + name);
       obj3 = document.getElementById("biblio" + name);
       if (obj && obj2 && obj3) {
        obj.style.display = "none";
        obj2.style.display = "";
        obj3.style.display = "";
       }
}
function HideAntidopingDetalhe(name)
{
        
       obj = document.getElementById("mais" + name);
       obj2 = document.getElementById("menos" + name);
       obj3 = document.getElementById("biblio" + name);
       if (obj && obj2 && obj3) {
        obj.style.display = "";
        obj2.style.display = "none";
        obj3.style.display = "none";
       }
}

