// Track PDF clicks as PV (CUSTOMIZED FOR ADOBE)
// Function WSS_detectPDF
// Purpose: If a link is to a PDF, call _hbPageView(), to register click as a PV
function WSS_detectPDF(e) {
  var tg;
  if (!e) var e = window.event;
  if (e.target) tg = e.target;
  else if (e.srcElement) tg = e.srcElement;
  if (tg.nodeType == 3) tg = tg.parentNode; // Safari bug fix
  if (tg.href) {
    var tg_pathname = tg.href.toLowerCase();
    if ((tg_pathname.indexOf(".pdf")!= -1) && (tg_pathname.indexOf("adobe") != -1)) {
      var tg_path = tg_pathname.substring(tg_pathname.indexOf("//") + 2, tg_pathname.lastIndexOf("/"));
      var tg_filename = tg_pathname.substring(tg_pathname.lastIndexOf("/")+1, tg_pathname.lastIndexOf("."));
      tg_filename=tg_filename+".pdf";
      tg_path = "/PDFs/" + tg_path + "/" + tg_filename;
      _hbPageView(tg_filename, tg_path); //HBX Function to Set PV
    }
  }
}

// Function WSS_addLoadEvent
// Purpose: Ensures that other scripts that call window.onload will run
function WSS_addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// WSS_addLoadEvent executes when page is loaded
// Function is defined within the parameter of WSS_addLoadEvent
// Purpose: Register event handler to detect if a click to a link has been made
WSS_addLoadEvent(function() {
  if (!document.getElementsByTagName) return; 
  var WSS_checkAllLinks = document.getElementsByTagName("a");
  var WSS_checkLink;
  for (var i=0; i<WSS_checkAllLinks.length; i++) {
    WSS_checkLink = WSS_checkAllLinks[i];
    if (WSS_checkLink.getAttribute("href")) {
      if (! WSS_checkLink.getAttribute("onclick")) {
        WSS_checkAllLinks[i].onclick = WSS_detectPDF;
      }
    }
  }
  var WSS_checkImapLinks = document.getElementsByTagName("area");
  var WSS_checkImapLink;
  for (var i=0; i<WSS_checkImapLinks.length; i++) {
    WSS_checkImapLink = WSS_checkImapLinks[i];
    if (WSS_checkImapLink.getAttribute("href")) {
      if (! WSS_checkImapLink.getAttribute("onclick")) {
        WSS_checkImapLinks[i].onclick = WSS_detectPDF;
      }
    }
  }
});

// Ensure pages that don't have WSS variables set do not generate error message
if (!window.hbx) {
var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0103u";hbx.gn=location.hostname;
hbx.acct="DM550215EESA"; //PUT PAGES WITHOUT HEADER INTO STAGING ACCOUNT
}
