if ( typeof APS == "undefined" || !APS ) {
  var APS = function (obj) { };
}

APS.UTILS = {};

APS.UTILS.popups = function() {
  if (!document.getElementById) return false;
  var anchors = document.getElementsByTagName("a"),
      anchor,
      attr_rel_string, width_start_pos, attr_rel_substring,
      width_end_pos, width;

  for (var i=0; i<anchors.length; i++) {
    anchor = anchors[i];
    if ( anchor.getAttribute("href") ) {
      anchor.onclick = function() {
        target = this.getAttribute("href");
        //Check "rel" attribute in anchor tag for certain values: "external" or "popup_w800_".
        //If "popup_w800_" is present, the width value is parsed from string and used in opening new window
        if ( this.getAttribute("rel") ) {
          attr_rel_string = this.getAttribute("rel");
          width_start_pos = attr_rel_string.indexOf("_w");
          if ( width_start_pos != -1 ) {
            attr_rel_substring = attr_rel_string.substring(width_start_pos+2);
            width_end_pos = attr_rel_substring.indexOf("_");
            if ( width_end_pos != -1) {
              width = attr_rel_string.substr(width_start_pos+2, width_end_pos);
            }
            else {
              width = attr_rel_string.substr(width_start_pos+2, width_end_pos);
            }
            window.open(target,"popup_win","height=550,width="+width+",scrollbars=yes");
            return false;
          }
          else {
            anchor.target = "_blank";
            window.open(target,"popup_win");
            return false;
          }
        }
      }
    }
  }
}

APS.UTILS.addLoadEvent = function(func) {
  var oldonload = window.onload;
  if ( typeof window.onload != 'function' )
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      oldonload();
      func();
    }
  }
}

APS.UTILS.addLoadEvent( function()
                        {
                          APS.UTILS.popups();
                        }
                      );