
// Initialize

window.onload = function() {
  logoPNG();
  targetLinks();
}

// Logo PNG

function logoPNG() {
  var obj = getElem('logo');
  if (obj) {
    if (document.all) {
      obj.childNodes[0].childNodes[0].src = "/tds/images/spacer.gif";
      obj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo.png', sizingMethod='scale')";
    }
    obj.style.visibility = "visible";
    obj.style.cursor = (document.all) ? "hand" : "pointer";
    setAttr(obj, "onclick", "goHome()");
  }
}

// Logo home link

function goHome() {
	location.href= "index.php";
}

// External links targetting

function targetLinks() {
  var i, trackingId;
  var links = document.getElementsByTagName("a");

  for (i = 0; i < links.length; i++) {
    if (links[i].href.indexOf('/pub/') != -1 || getHost(document.location.href) != getHost(links[i].href)) {
      links[i].setAttribute("target", "_blank");
  }
  }
}

// Return hostname and port as host string

function getHost(url) {
  var host = url.toLowerCase();

  if (host.indexOf("http://") >= 0) {
    host = host.substring(7, host.length);
  }

  host = host.substring(0, host.indexOf("/"));
  return host;
}

// Get element

function getElem(id) {
  var obj = (typeof id == 'string') ? document.getElementById(id) : id;
  return obj;
}

// Set event attribute

function setAttr(obj, handler, theFunction) {
  if (document.all) {
    obj[handler] = new Function(theFunction);
  } else {
    obj.setAttribute(handler, theFunction);
  }
}
