﻿/******* Nr de visitas controladas pelo Cookie *******/
var NumVisitedSDM = 2000;
/*********************************************/

var BlockID1, BlockID2, BlockID3,  BlockHeightID1,  BlockHeightID2,  BlockHeightID3,  BlockHeightMax, BlockHeightPx;

function EqualHeight(CountBlock){
  $(function() {
    BlockID1=('#Block' + (CountBlock - 2)); 
    BlockID2=('#Block' + (CountBlock - 1)); 
    BlockID3=('#Block'+(CountBlock)); 

    var highestCol = Math.max($($(BlockID1)).height(),$($(BlockID2)).height(),$($(BlockID3)).height());
    BlockHeightPx = (highestCol +'px');

    $($(BlockID1)).height(highestCol);
    $($(BlockID2)).height(highestCol);
    $($(BlockID3)).height(highestCol);
  });
}


function EqualHeight2(CountBlock){
$(function() {
    var DivModHeight = (CountBlock % LoopMod3);

 //alert(DivModHeight);

     if(DivModHeight !=0){
         BlockID22=('#Block'+(CountBlock)); 
         BlockID11=('#Block' + (CountBlock - 1)); 

         var highestCol2 = Math.max($($(BlockID11)).height(),$($(BlockID22)).height());
         BlockHeightPx2 = (highestCol2 +'px');

         $($(BlockID11)).height(highestCol2);
         $($(BlockID22)).height(highestCol2);
      }
 });
}


function EqualH2Items(ModNews, NewsIDBlock){
    if(ModNews == 1) {
     BItemID1=('#Block'+NewsIDBlock);     
    } 
    if(ModNews == 0){
     BItemID2=('#Block'+NewsIDBlock); 
     HeightMax2Item = Math.max($($(BItemID2)).height(),$($(BItemID1)).height());
     HeightMax2ItemPx = (HeightMax2Item +'px');
     $($(BItemID1)).height(HeightMax2ItemPx);
     $($(BItemID2)).height(HeightMax2ItemPx);
    }
}



function CheckForNews(PIDH) {
  HeightNews = document.getElementById('Show' + PIDH).innerHTML;
  HeightNewsT = HeightNews.search(/DwNewsList/);
  //var teste = HeightNews.split("CountBlock");
  if(HeightNewsT >0){

 }
}


function CategoryId(cat) {
  if (cat=='10' ) {
     scrimg = "SDM/Graphics/iconvideo.gif";  
   }
    else if (cat=='11') {
    scrimg = "SDM/Graphics/iconaudio.gif";  
   } 
    else if (cat=='2' || cat=='19' || cat=='20') {
    scrimg = "SDM/Graphics/icondoc.gif";  
   } 
    else {
   scrimg = "SDM/Graphics/graphicDoc.gif";  
   }
}



function MyCheckMenu() {
  //document.getElementsByName('postform1')[0].action = "http://api-verify.recaptcha.net/verify";
  //document.getElementsByName('challenge')[0].value = Recaptcha.get_challenge();
  //document.getElementsByName('response')[0].value = Recaptcha.get_response();
  //alert("rePatcha em testes");
}

function PrintParagraph(ParagraphID) {
  var wnd = window.open('','PrintWindow','width=700,height=400');
    wnd.document.open();
    wnd.document.write('<html><head><title>PopUp Window<\/title>');
    wnd.document.write('<link rel="stylesheet" type="text/css" href="/Files/Stylesheet1565.css"><\/link><link rel="stylesheet" type="text/css" href="/Files/System/SDM/css/SDM.css"><\/link><link rel="stylesheet" type="text/css" href="/Files/Legend1.css"><\/link><link rel="stylesheet" type="text/css" href="/files/templates/newsv2/newsv2.css"><\/link>');
    wnd.document.write('<style type="text/css">body{margin:10px;background-color:#ffffff;}.paragraphfeatures{display:none;}<\/style>');
    wnd.document.write('<\/head><body bgcolor="#ffffff">');
    wnd.document.write('<div style="margin-bottom:10px;"><img src="Files/System/SDM/layout/PrintHeader.gif" /><\/div>');
    wnd.document.write(document.getElementById('ParagraphHeader' + ParagraphID).innerHTML);
    wnd.document.write('<br/>');
    wnd.document.write(document.getElementById('Show' + ParagraphID).innerHTML);
    wnd.document.write('<\/body><\/html>');
    wnd.document.close();
    wnd.focus();
    wnd.print();
    wnd.close();
  }

/* Adicionar aos favoritos */
function CreateBookmarkLink() {
  title = document.title + " - Douro Azul";
  url = window.location;

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  }
  else if( window.external ) { // IE Favorite
   window.external.AddFavorite(url, title);
  }
  else if(window.opera && window.print) { // Opera Hotlist
    alert("Press CTRL + D, to add this page to your bookmarks!");
  }
}

function OpenMenu(TheMenu, TheHref) {
  if (document.getElementById('SubMenu' + TheMenu)) {
    if (document.getElementById('SubMenu' + TheMenu).style.display == "block") {
      document.getElementById('MainMenuItem' + TheMenu).style.backgroundImage = "none";
    }
    else {
      document.getElementById('MainMenuItem' + TheMenu).style.backgroundImage = "url(Files/Navigation/SDM/MainMenuActive.gif)";
    }
    animatedcollapse.toggle('SubMenu' + TheMenu);
  }
  else {
    window.location = TheHref;
  }
}

function MouseOverMainMenu(TheMenu) {
  if (document.getElementById('SubMenu' + TheMenu)) {
    if (document.getElementById('SubMenu' + TheMenu).style.display != "block") {
      document.getElementById('MainMenuItem' + TheMenu).style.backgroundImage = "url(Files/Navigation/SDM/MainMenuOver.gif)";
    }
  }
}

function MouseOutMainMenu(TheMenu) {
  if (document.getElementById('SubMenu' + TheMenu)) {
    if (document.getElementById('SubMenu' + TheMenu).style.display != "block") {
      document.getElementById('MainMenuItem' + TheMenu).style.backgroundImage = "";
    }
  }
}

function My_ShowHide(PID){
  var MyLinkValue = "";

  MyLinkValue = document.getElementById('toggleLink' + PID).innerHTML;
  
  if(MyLinkValue == PShow) {
    document.getElementById('toggleLink' + PID).innerHTML = PHide;
    //CheckForNews(PID);
  }
  else {
    document.getElementById('toggleLink' + PID).innerHTML = PShow;
  }

  animatedcollapse.toggle('Show' + PID);
}
function My_Show(PID){
  document.getElementById('MyHideLink' + PID).style.display = "block";
  document.getElementById('toggleLink' + PID).style.display = "none";
  animatedcollapse.toggle('Show' + PID);
  
}
function My_Hide(PID){
  //document.getElementById('MyHideLink' + PID).style.display = "none";
  document.getElementById('toggleLink' + PID).style.display = "block";
  animatedcollapse.toggle('Show' + PID);
  
  document.getElementById('toggleLink' + PID).innerHTML = PShow;
}


// Login Bar
// function JSFX_FloatTopLeft() {
//  var startX = 0, startY = 0;
//  var ns = (navigator.appName.indexOf("Netscape") != -1);
 // var d = document;
//  var px = document.layers ? "" : "px";
// function ml(id) {
//    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
//    if(d.layers)el.style=el;
//     el.sP=function(x,y){this.style.left=x+px;this.style.bottom=-1-y+px;};
//    el.x = startX; el.y = startY;
//    return el;
// }
//  window.stayTopLeft=function() {
//    var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
//    var dY = (pY > startY) ? pY : startY;
//    ftlObj.y += (dY - ftlObj.y)/8;
//    ftlObj.sP(ftlObj.x, ftlObj.y);
//    setTimeout("stayTopLeft()", 20);
//  }
 // ftlObj = ml("FloatBara");
//  stayTopLeft();
//}

function getCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie() {
  VisitedSDM=getCookie('VisitedSDM');
  if (document.getElementById('ContentVisited')) {
    if (VisitedSDM <= NumVisitedSDM) {
      VisitedSDM++;
      setCookie('VisitedSDM',VisitedSDM,365);
      document.getElementById('ContentVisited').style.display = "block";
    } 
  }
}

// My onLoad function
function InitFunction() {
 // JSFX_FloatTopLeft();
 checkCookie();

  try
 {
   initialize();
 }
 catch(err)
 {
  }
}


