/*
 * Opens links with "external" in their class attributes in a new window.
 */

(function(){

var old_onload = window.onload ? window.onload : function(){};

window.onload = function() {
  old_onload();

  var links = document.getElementsByTagName('a');

  var window_ref = null;

  for (var i=0; i< links.length; i++) {
    if (/(^|\s)external(\s|$)/.test(links[i].className)) { // If the link's class attribute contains "external"...
      links[i].onclick = (function() {
        return function(e) {
          e = e ? e : event;
          var target = e.target ? e.target : e.srcElement;
          if (window_ref) {
            window_ref.location.href = target.href;
          } else {
            window_ref = window.open(target.href, '');
          }
          if (e.preventDefault) {e.preventDefault();} else {
            e.returnValue = false;
          }
        };
      })();
    }
  }
};

})();