// JavaScript Document

// Method to fire Urchin page load;
var fnFireUrchin = function () {
  // Instantiate variables;
  var oTimeout, 
  sLocation = window.location.pathname, 
  iCountdown = 500,
  
  // Method to loop until PHEAA.Urchin can be called;
  fnCallUrchin = (function () {
    // Clear timeout, if present;
    if (oTimeout) {
      clearTimeout(oTimeout);
    }
    
    // Check if PHEAA.Urchin is defined;
    if (typeof PHEAA !== "undefined" && 
        typeof PHEAA.Urchin !== "undefined") {
      // Call PHEAA.Urchin
      PHEAA.Urchin.callUrchin(sLocation, "Page_Load");  
      // Remove method from DOM;
      fnFireUrchin = null;
      
    // Else try again in a 10th of a second (for 500 tries total);
    } else if (iCountdown > 0) {
      iCountdown -= 1;
      oTimeout = setTimeout(fnCallUrchin, 100);
    }
  }());  
};

// Bind fnFireUrchin to onload event;
if (window.addEventListener) {
  window.addEventListener("load", fnFireUrchin, false);	
} else if (window.attachEvent) {
  window.attachEvent("onload", fnFireUrchin);
}