// Function to make links with 'rel' set to 'external' open in a new window
function externalLinks() {
 if (!document.getElementsByTagName) return;

 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

// Countdown clock function
var _countDowncontainer = 0;
var _currentSeconds     = 0;
var _stopCountDown      = false;
 
function ActivateCountDown(strContainerID, initialValue, redirectLocation) {
  _countDowncontainer = document.getElementById(strContainerID);

  if (!_countDowncontainer) {
    // alert("count down error: container does not exist: "+strContainerID+
    //    "\nmake sure html element with this ID exists");
    return;
  }
  
  SetCountdownText(initialValue);
  window.setTimeout("CountDownTick('" + redirectLocation  + "')", 1000);
}
 
function CountDownTick(redirectLocation) {
  
  if (_stopCountDown) {
    //_countDowncontainer.parentNode.innerHTML = '';
    countdown_wrapper = document.getElementById('countdown_wrapper');
    countdown_wrapper.innerHTML = '';
    return;
  }

  if (_currentSeconds <= 0) {
    window.location = redirectLocation;
    return;
  }
  
  SetCountdownText(_currentSeconds-1);
  window.setTimeout("CountDownTick('" + redirectLocation + "')", 1000);
}
 
function SetCountdownText(seconds) {
  //store:
  _currentSeconds = seconds;
  
  //get minutes:
  var minutes=parseInt(seconds/60);
  
  //shrink:
  seconds = (seconds%60);
  
  //get hours:
  var hours=parseInt(minutes/60);
  
  //shrink:
  minutes = (minutes%60);
  
  //build text:
  //var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);
  var strText = AddZero(seconds);
  
  //apply:
  _countDowncontainer.innerHTML = strText;
}
 
function AddZero(num) {
  return ((num >= 0)&&(num < 10))?"0"+num:num+"";
} 
