﻿// JScript File

function SetPageInterior()
{
  if (document.location.toString().indexOf("scrollTo")>0) {
    //AddEvent(document.body, "load", function() {ScrollTo(GetQueryStringValue("scrollTo"));});
    window.setTimeout(ScrollTo(GetQueryStringValue("scrollTo")), 1);
  }
  InitListArticles();
  
  /*
  LoadActualFontSize();
  MagnifyText(0);
  */
}



function ScrollTo(id)
{
  var obj = document.getElementById(id);
  if (obj) ScrollIntoView(obj);
}
      
   var MAX_FONTSIZE = 70;
   var ACTUAL_FONTSIZE = 0;
   var MIN_FONTSIZE = -20;
   
   function MagnifyText(iDirection)
   {
      var oNewsMain = document.getElementById("NewsMain");
      var oNewsHead = document.getElementById("NewsHead");
      var oNewsCommunity = document.getElementById("NewsCommunity");
      var oNewsRelated = document.getElementById("NewsRelated");
      if ( ACTUAL_FONTSIZE + 1*iDirection >= MIN_FONTSIZE &&  ACTUAL_FONTSIZE + 1*iDirection <= MAX_FONTSIZE){   
         ACTUAL_FONTSIZE = ACTUAL_FONTSIZE + 1*iDirection;
         SaveActualFontSize(); 
         
         var iGap = ( ACTUAL_FONTSIZE <= 0 ? 10: 30 );      
         if ( ACTUAL_FONTSIZE == 0 )  {
            var fontSize = ( window.showModalDialog ? "x-small" : "medium" );
            if (oNewsMain) oNewsMain.style.fontSize = fontSize;
            if (oNewsHead) oNewsHead.style.fontSize = fontSize;
            if (oNewsCommunity) oNewsCommunity.style.fontSize = fontSize;
            if (oNewsRelated) oNewsRelated.style.fontSize = fontSize;
         }
         else {
            if (oNewsMain) oNewsMain.style.fontSize = 100 + ACTUAL_FONTSIZE*iGap + "%";
            if (oNewsHead) oNewsHead.style.fontSize = 100 + ACTUAL_FONTSIZE*iGap + "%";
            if (oNewsCommunity) oNewsCommunity.style.fontSize = 100 + ACTUAL_FONTSIZE*iGap + "%";
            if (oNewsRelated) oNewsRelated.style.fontSize = 100 + ACTUAL_FONTSIZE*iGap + "%";
         }
      }
   }
   
   function SaveActualFontSize() 
   {
      var expire = new Date ();
      expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
      expire = expire.toGMTString();
      document.cookie="solFontSize=" + ACTUAL_FONTSIZE + "; path=/; expires=" + expire;
   }
   
   function LoadActualFontSize() 
   {
      tempArray = document.cookie.split(";");
      for (tA = 0; tA < tempArray.length; tA++){
         if (tempArray[tA].indexOf('solFontSize') > -1){
            fontSizeValue = tempArray[tA].split("=")
            ACTUAL_FONTSIZE = parseInt(fontSizeValue[1]);
         }
      }
   }
     
     
var NewsArgs;
var ContentId = GetQueryStringValue("content_id");
function PrintNews()
{
   var id = ContentId;
   if ( id ) {
       var sFeatures = "height=560px,width=600px,status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes";
       window.open("/Common/print.aspx?content_id=" + id, "Print", sFeatures);
   }
}

function SendNews(commentId, destinationId)
{
    var oTitle = document.getElementById("NewsTitle");
    var oSummary = document.getElementById("NewsSummary");
    var sFeatures, sLoc = document.location.toString().toLowerCase();
    var oLoc = document.getElementById("AudioVideoLink");
    if (oLoc && oLoc.value) sLoc = oLoc.value.toLowerCase();
    NewsArgs = Array((oTitle ? oTitle.innerHTML : ""), (oSummary ? oSummary.innerHTML:""), sLoc);
    var id = ContentId;
    if (!id) {
      var objId = document.getElementById("AudioVideoId");
      if (objId) id = objId.value;
    }
    if ( id ) {
         var sFeatures = "height=370px,width=700px,status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes";
         var url = "/Common/send.aspx?content_id=" + id;
         if (commentId) {
           var comment = document.getElementById(commentId);
           url += "&comment=" + ( comment && comment.value!=comment.title ? escape(comment.value) : "" );
         }
         if (destinationId) {
           var destination = document.getElementById(destinationId);
           url += "&destination=" + ( destination && destination.value!=destination.title ? escape(destination.value) : "" );
         }
         window.open(url, "Send", sFeatures);
    }
}


function ShowStats(visible)
{
    var statsWrapper = document.getElementById("StatsWrapper");
    
    if (statsWrapper) {
      statsWrapper.style.display = visible ? "inline" : "none";
    }
}




function InitListArticles()
{
   var docid = GetQueryStringValue("content_id");
   if (docid) {
     var objArticle = document.getElementById("ListArticle" + docid);
     if (objArticle) objArticle.style.display = "none";
   }
   var wrapper = document.getElementById("ListArticlesBlock");
   if (wrapper) {
     wrapper.style.display = "";
     if(wrapper.parentNode && wrapper.parentNode.parentNode && wrapper.parentNode.parentNode.parentNode && 
        wrapper.parentNode.parentNode.parentNode.className == "blc-artigo-dir-n2");
       wrapper.parentNode.innerHTML = wrapper.parentNode.innerHTML;
   }
   CorrectPageLayout(wrapper);
}


function CorrectPageLayout(articlesWrapper)
{
  var artigoContentDiv = null, artigoContent = 0, colunaDireita1 = 0, colunaDireita2 = 0, colunaDireita = 0;
  var conteudoCompleto = document.getElementById("blc-conteudos"); 
  var j, divsTotal = conteudoCompleto.getElementsByTagName("div");
  if (divsTotal) {
      for (j=0; j<divsTotal.length; j++) {
        if ( (divsTotal[j].className && divsTotal[j].className == "cln-esqmid") || divsTotal[j].id == "cln-esqmid") {
   
          var colunaCentral = divsTotal[j]; 
          if (colunaCentral) {
            var k, countdir = 0, divs = colunaCentral.getElementsByTagName("div");
            if (divs) {
            
        
              for (k=0; k<divs.length; k++) {
                switch (divs[k].className) {
                  case "blc-artigo-txt-n0": 
                    if (!artigoContentDiv) {
                      artigoContentDiv = divs[k];
                      artigoContent = divs[k].offsetHeight; 
                    }
                    break;
                  case "blc-artigo-dir-n0": 
                    if (!colunaDireita1) colunaDireita1 = divs[k].offsetHeight;
                    else if (!colunaDireita2) colunaDireita2 = 1*(colunaDireita1 + divs[k].offsetHeight);
                    colunaDireita = 1*(divs[k].offsetHeight+colunaDireita);
                    countdir++;
                    break;
                }
              }
              if (!colunaDireita2) colunaDireita2 = colunaDireita;
              var areaComentarios = document.getElementById("AreaComentariosWrapper");
              
              if (1*(artigoContent)<colunaDireita && countdir>1) {
                
                var height = 0;
                if (1*(artigoContent)<colunaDireita1) height = 1*(colunaDireita2+10);
                else if (1*(artigoContent)<colunaDireita2) height = 1*(colunaDireita2+10);
                if (artigoContent<height) artigoContentDiv.style.height = height + "px";

                if (articlesWrapper!=null || areaComentarios!=null) {
                var commentsSibling = areaComentarios == null ? null : GetSibling(areaComentarios.parentNode);
                
                if ((colunaDireita2-artigoContent-10)>0) {
                     var dif = 0;
                     if (articlesWrapper && (1*(colunaDireita2-artigoContent-50)>0) && (commentsSibling == null || commentsSibling.id == null || commentsSibling.id.indexOf("MaisNoticias")>=0)) {
                       articlesWrapper.style.marginTop = "-" + 1*(colunaDireita2-artigoContent-50) + "px";
                       articlesWrapper.style.position = "relative";
                       dif = articlesWrapper.offsetHeight;
                     }
                     if (areaComentarios && (1*(colunaDireita2-artigoContent-50-dif))>0) {
                       areaComentarios.style.marginTop = "-" + 1*(colunaDireita2-artigoContent-50-dif) + "px";
                       areaComentarios.style.position = "relative";
                     }
                   }
                }

              }
            }
          }
          
        }
        break;
      }
   }
}




var ArrayThumbList = new Array ();
var ThumbListPos = 0;

function ThumbList(img, pos, credits)
{
    this.img = img;
    this.pos = pos;
    this.credits = credits;
    this.html = ThumbListHTML(this.img, this.pos, this.credits);
    return this;
}

function ThumbListHTML(img, pos, credits)
{
    return ( !img ? '' : '' +
        "<a href='javascript:SwitchPhoto(\"Photo4201\", \"Thumb" + pos + "\", null, null, null, \"BigImageDetails\", \"" + credits + "\")'>" +
          "<img id='Thumb" + pos + "'  src='" + img + "' width='62' height='48' class='imagem-borda'/>" + 
        "</a>" );
}




