/* Simon Willison's addLoadEvent function allows you to stack up 'window.onload' events without them stepping on each other's toes. It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */
function addLoadEvent(func)
{
  var oldonload = window.onload;
  if(typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      oldonload();
      func();
    }
  }
}

/* this is the current popup function */
function acpopup(strURL, strType, strHeight, strWidth)
{
  var strOptions="";
  if(strType == "console") strOptions = "resizable,height=" + strHeight + ",width=" + strWidth;
  window.open(strURL, '', strOptions);
}

/* new accessible, unobtrusive popup code */
function windowLinks()
{
  if(!document.getElementsByTagName)
  {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for (var i = 0; i < anchors.length; i++)
  {
    var anchor = anchors[i];
    var relIndex = anchor.rel;
    if(relIndex)
    {
      var relSplit = relIndex.split("|");
      if(relSplit[0] == "external")
      {
        anchor.target = "_blank";
      }
      else if(relSplit[0] == "popup")
      {
        anchor.popupWidth = relSplit[1];
        anchor.popupHeight = relSplit[2];
        anchor.onclick = function() { acpopup(this.href, 'console', this.popupWidth, this.popupHeight); return false; };
      }
    }
  }
}

addLoadEvent(function() { windowLinks(); });
