/*****************************************************************************
 * This file defines Javascript functionality for the entire site and is
 * automatically linked to from every page that includes the common header
 * file.
 *****************************************************************************/


function GoToUrl(url)
{
    window.location = url;
}


function popupWindow(location, width, height)
{
    window.open (location, "", "location=0,status=0,scrollbars=0,width=" + width + ",height=" + height);
}


function addBookmark(title, url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

function addLoadEvent(func) {
  var oldOnload = window.onload;
  if (typeof window.onload != "function") {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldOnload();
      func();
    }
  }
}


/**
 * Makes external links open in new windows.
 *
 * Source: http://muzso.hu/node/59
 */
function externalLinks() {
  if (typeof document.getElementsByTagName == "undefined") {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for (var i = 0; i < anchors.length; i++) {
    var anchor = anchors[i];
    var rel = "" + anchor.getAttribute("rel");
    if (
      typeof anchor.hostname != "undefined" > 0
      && (
        (
          rel.length > 0
          && rel.indexOf("blank") >= 0
        )
        || (
          (
            rel.length == 0
            || rel.indexOf("self") < 0
          )
          && anchor.protocol.indexOf("javascript") < 0
          && anchor.hostname != document.location.hostname
        )
      )
    ) {
      anchor.target = "_blank";
    }
  }
}


addLoadEvent(externalLinks);
