// Global JavaScript Document For MyFedLoan

/*jslint white: true, onevar: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, indent: 2 */

/*global window, PHEAA, ActiveXObject */

var myFedLoan = (function () {

  // Set Array.prototype.forEach method
  if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (fnCallback, oOptional) {
      var i, iLength;
      
      if (typeof fnCallback !== "function") {
        throw new TypeError();
      }

      for (i = 0, iLength = this.length; i < iLength; i += 1) {
        if (i in this) { // Skip over any holes in the array;
          fnCallback.apply(oOptional || this, [this[i], i, this]);
        }
      }

    };
  }
  
  // Set String.prototype.trim method
  if (!String.prototype.trim) {
    String.prototype.trim = function () {
      var re = /^\s+|\s+$/g;
      return this.replace(re, "");
    };
  }

  var fnCreate = function (oObj) { // Method to create new dom elements;
    // Instantiate variables;
    var i, 
    // Build requested element;
    oElem = document.createElement(oObj.elem);
     
    // Add attributes, if present;
    if (oObj.attributes) {
      for (i in oObj.attributes) {
        if (oObj.attributes.hasOwnProperty(i)) {
          oElem[i] = oObj.attributes[i];
        }
      }
    }
    
    // Set style declarations, if present;
    if (oObj.style) {
      for (i in oObj.style) {
        if (oObj.style.hasOwnProperty(i)) {
          oElem.style[i] = oObj.style[i];
        }
      }
    }
    
    // Append Children, if present;
    if (oObj.children) {
      for (i = 0; i < oObj.children.length; i += 1) {
        oElem.appendChild(oObj.children[i]);
      }
    }
    
    // Return new element;
    return oElem;
  }, 
  
  // Get style properties of object;
  fnGetStyle = function (oElem, sName) {
      
    var oObj, 
    domView = document.defaultView; // Save reference to w3c method;
      
    // If the property exists in style[] then it's been set recently 
    // and is current;
    if (oElem.style[sName]) {
      return oElem.style[sName];
    } else if (oElem.currentStyle) {
      return oElem.currentStyle[sName]; //otherwise, try to use IE's method;

    // Or the w3c's method, if it exists;
    } else if (domView && domView.getComputedStyle) {
      // It uses the traditional 'text-align' style of rule writing 
      // instead of 'textAlign';
      sName = sName.replace(/([A-Z])/g, "-$1").toLowerCase();

      // Get the style object and get the value of the property if it exists;
      oObj = domView.getComputedStyle(oElem, "");
      return oObj && oObj.getPropertyValue(sName);

    } else { // Otherwise, some other browser is being used;
      return null;
    }

  },
  
  // Render iFrame element for IE Browsers;
  fnRenderIFrame = function (oElem) {  
    var oIFrame = document.getElementById("windowIFrame") || null, 
    sClassName = "windowIFrame", 
    sURL = 'javascript:"";', 
    iHeight = parseInt(fnGetStyle(oElem, "height"), 10) || 
              oElem.offsetHeight || 0, 
    iWidth = parseInt(fnGetStyle(oElem, "width"), 10) || 
             oElem.offsetWidth || 0;
    
    // Create iFrame if browser is Internet Explorer if IFrame isn't present;
    if (document.all && !window.opera) {
      if (!oIFrame) {
        oIFrame = fnCreate({
          elem: "iframe", 
          attributes: {
            className: sClassName, 
            src: sURL
          }
        });
        
        // Insert iFrame into element;
        oElem.appendChild(oIFrame);
     
        // Save reference to iFrame;
        oElem.iframe = oIFrame;
      } else {
        oIFrame = oIFrame.parentNode.removeChild(oIFrame);
        oIFrame.setAttribute("src", sURL);
        oIFrame.className = sClassName;
        oElem.appendChild(oIFrame);      
      }
      oIFrame.style.height = iHeight + "px";
      oIFrame.style.width = iWidth + "px";
    }
    
    // Return iFrame;
    return oIFrame;  
  }, 
    
  // Method to bind events, w3c style;
  fnAddEvent = function (oElement, sHandler, fnMethod) {
    // If using w3c method;
    if (oElement.addEventListener) {
      oElement.addEventListener(sHandler, fnMethod, false);
    // If using IE method;
    } else if (oElement.attachEvent) {
      oElement.attachEvent("on" + sHandler, fnMethod);
    }
  }, 
  
  // Method to unbind events, w3c style;
  fnRemoveEvent = function (oElement, sHandler, fnMethod) {
    // If using w3c method;
    if (oElement.addEventListener) {
      oElement.removeEventListener(sHandler, fnMethod, false);
    // If using IE method;
    } else if (oElement.attachEvent) {
      oElement.detachEvent("on" + sHandler, fnMethod);
    }
  }, 
  
  // Method to insert elements into the DOM after a given element;
  fnInsertAfter = function (oNewElement, oTargetElement) {

    // Find parent of target element;
    var oParent = oTargetElement.parentNode;
      
    // Insert new element after target element;
    if (oParent.lastChild === oTargetElement) {
      oParent.appendChild(oNewElement);
    } else {
      oParent.insertBefore(oNewElement, oTargetElement.nextSibling);
    }

  },
        
  // Method to open external links in new windows;
  fnTargetBlank = function () {

    // Instantiate loop variables;
    var i, iLength,  
    // Collect all links on the page;
    cLinks = document.getElementsByTagName("a"), 
    
    // Method to open a new window;
    fnOpenWindow = function () {
      
      // Instantiate variables;
      var wChild, 
      // Test to see if this is a contact form link;
      bContactForm = this.getAttribute("rel") === "contact_form", 
      // Build optional window arguments;
      sArguments = bContactForm ?
        "scrollbars" : "", 
      // Test to see if there are existing querystring variables;
      sModifier = this.getAttribute("href").indexOf("?") !== -1 ? 
        "&" : "?", 
      dNow = new Date();
          
      // Attempt to open a new window;
      if (bContactForm) {
        wChild = window.open(this.getAttribute("href") + sModifier + "javascriptEnabled=true", this.getAttribute("rel") + dNow.getMilliseconds(), sArguments);
      } else {
        wChild = window.open(this.getAttribute("href"), this.getAttribute("rel") + dNow.getMilliseconds(), sArguments);
      }
        
      return !wChild ? 
        true : // failed to open so follow link;
        false; // success, open new browser window;
    };
    
    // Attach new window method to appropriate links;
    for (i = 0, iLength = cLinks.length; i < iLength; i += 1) {
      if (cLinks[i].getAttribute("rel") && 
          (cLinks[i].getAttribute("rel") === "external" ||
           cLinks[i].getAttribute("rel") === "pdf" || 
           cLinks[i].getAttribute("rel") === "excel" ||
					 cLinks[i].getAttribute("rel") === "ppt" ||
           cLinks[i].getAttribute("rel") === "accountaccess" || 
           cLinks[i].getAttribute("rel") === "contact_form")) {
        cLinks[i].onclick = fnOpenWindow;
      }
    }
  }, 
  
  // Method to create quick links selector in page header;
  fnQuickLink = function (aData, vObject, sInsert, vHeaderString, vImageURL) {
    if (!document.getElementById || 
        !document.createElement || 
        (!document.addEventListener && !document.attachEvent)) {
      return false;  
    }
    
    // Instantiate variables;
    var oList, fnShowList, oParent, oListButton, 
    
    // Reg Exp to remove hide class;
    reHide = /\s*hide\b/g, 
    // Build Quick Links Div;
    oQuickLink = fnCreate({
      elem: "div", 
      attributes: {
        className: "quickLink"
      }, 
      // Build array of child elements;
      children: (function () {
        // Instantiate variables;
        var aItems = [],
        sDefaultTitle = vHeaderString && typeof vHeaderString === "string" ? 
          vHeaderString : "I want to...", 
        sDefaultImageURL = vImageURL && typeof vImageURL === "string" ? 
          vImageURL : "/images/quickLink/selectBox.gif";
        
        // Test if a caption element should be inserted;
        if (vHeaderString || typeof vHeaderString !== "boolean") {
          aItems.push(fnCreate({
            elem: "p", 
            attributes: {
              innerHTML: sDefaultTitle
            }
          }));
        }
        
        // Insert link and image to simulate combo box;
        aItems.push(oListButton = fnCreate({
          elem: "a", 
          attributes: {
            href: "#", 
            className: "quickListButton", 
            onclick: function (event) {
              fnShowList(event);
            }
          }, 
          children: [
            fnCreate({
              elem: "img", 
              attributes: {
                alt: "Select and Go To...", 
                src: sDefaultImageURL
              }
            })
          ]
        }));
        
        return aItems;
      }())
    }), 
    
    // Configure insert method value;
    sInsertMethod = typeof sInsert === "string" && ["before", "after"].join().indexOf(sInsert) !== -1 ?
      sInsert : "before", 
      
    // Retrieve reference DOM object;
    oObj = typeof vObject === "string" ? 
      document.getElementById(vObject) || false :
      vObject || false;

    // Check for existance of reference DOM object;
    if (!oObj || document.getElementById("quickListButton")) {
      return false;
    }
    
    // Find parent element of reference object;
    oParent = oObj.parentNode;
          
    // Configure show list method;
    fnShowList = function (e) {
      // Normalize event;
      var evt = e || window.event, 
      evtTarget = evt.target || evt.srcElement,
      oLinkList = oList.getElementsByTagName("ul")[0];
 
      // Process according to state of list;
      if (oList.className.indexOf("hide") !== -1) {
        oList.className = oList.className.replace(reHide, "");
        oList.style.height = oLinkList.offsetHeight + "px";
        if (typeof oList.iframe === "undefined") {
          fnRenderIFrame(oList);
        }
        fnAddEvent(document.body, "click", fnShowList);
      } else {
        oList.className += " hide";
        fnRemoveEvent(document.body, "click", fnShowList);
      }

      // Stop event propagation;
      if (evt.stopPropagation) {
        evt.stopPropagation();
      }
      evt.cancelBubble = true;
   
      // Stop default behavior if list link element, if applicable;
      if (evtTarget === oListButton || 
          evtTarget.parentNode === oListButton) {
        if (evt.preventDefault) {
          evt.preventDefault();
        }
        evt.returnValue = false; 
        return false;
      }
    };
    
    // Build list of links;
    oList = fnCreate({
      elem: "div", 
      attributes: {
        className: "quickLinkWrapper hide", 
        title: "Commonly Accessed Links"
      }, 
      children: [
        fnCreate({
          elem: "ul", 
          children: (function () {
            var i, iLength, 
            aElements = [];
  
            // Iterate through given collection of elements;
            for (i = 0, iLength = aData.length; i < iLength; i += 1) {
              // Create list item containing clone of passed element;
              aElements.push(fnCreate({
                elem: "li", 
                children: [aData[i].cloneNode(true)]
              }));
            }
          
            // Return array of list items;
            return aElements;
          }())
        })
      ]
    });

    // Insert list into Quick Links div;
    oQuickLink.appendChild(oList);
   
    // Insert Quick Links Div into page;
    if (sInsertMethod === "after") {
      fnInsertAfter(oQuickLink, oObj);
    } else {
      oParent.insertBefore(oQuickLink, oObj);
    }

    return oQuickLink;
  }, 
  
  // Method to clone search functionality into footer;
  fnSetSearchBox = function () {
    // Instantiate variables;
    var sSearchDefaultText = "Word or phrase...", 
    // Array of text search fields;
    oTextField = document.getElementById("sp-q"), 
        
    // Method to clear default text in search text fields;
    fnClearValue = function (e) {
      // Instantiate variables;
      var evt, that, sValue;
      
      // Set object context;
      if (typeof this.nodeName === "undefined") {
        evt = e || window.event;
        that = evt.target || evt.srcElement;
      } else {
        that = this;
      }
       
      // Get object value;
      sValue = that.value.trim();
   
      // Set color of text field;
      that.style.color = "#333333";
      
      // Check for match with preset value (trim whitespace on ends of string);
      if (that.value.trim() === sSearchDefaultText) {
        // Clear value;
        that.value = "";
      }
    }, 
    
    fnCheckValue = function (e) {
      // Instantiate variables;
      var evt, that, sValue;

      // Set object context;
      if (typeof this.nodeName === "undefined") {
        evt = e || window.event;
        that = evt.target || evt.srcElement;
      } else {
        that = this;
      }

      // Get object value;
      sValue = that.value.trim();
    
      // Check for match with preset value (trim whitespace on ends of string);
      if (sValue === sSearchDefaultText || 
          sValue === "") {
        // Clear value;
        that.value = sSearchDefaultText;
        // Set color of text field;
        that.style.color = "#7C7C7C";
        that.style.paddingLeft = "5px";
      }
    };
        
    // Initialize Field
    fnCheckValue.call(oTextField);

    // Bind methods on focus and blur of element;
    fnAddEvent(oTextField, "focus", fnClearValue);
    fnAddEvent(oTextField, "blur", fnCheckValue);
  }, 
  
  // General method to enable hide/show functionality;
  fnSetHideShow = function () {
    // Initialize variables;
    var i, iLength,  
    reHide = /\bhide\b/, // Reg Exp to add/remove hide class from elements;
    reText = /(View|Hide)/, // Reg Exp to change text in target elements;
    reEnabled = /\bhsTarget\b/, // Reg Exp to change class on targets;
    
    // Sections to activate hide/show method within;
    aParents = myFedLoan.getElementsByClassName("hsParent"), 
    
    // Method to hide/show elements;
    fnHideShow = function () {
      // Make sure referring object has target and result arrays;
      if (typeof this.aResults !== "object" || 
          this.aResults.constructor !== Array || 
          typeof this.aTargets !== "object" || 
          this.aTargets.constructor !== Array) {
        return true;
      }
      
      // Initialize variables;
      var sMethod;
      
      // Show/hide elements;
      this.aResults.forEach(function (oElem) {
        if (oElem.className.match(reHide)) {
          oElem.className = oElem.className.replace(reHide, "").trim();
        } else {
          oElem.className += " hide";
        }
      });
      
      // Adjust text of target elements;
      this.aTargets.forEach(function (oElem) {
        if (oElem.innerHTML.match(reText)) {
          sMethod = RegExp.$1 === "View" ? 
            "Hide" : "View";
          oElem.innerHTML = oElem.innerHTML.replace(reText, sMethod);
          oElem.style.backgroundPosition = RegExp.$1 === "View" ? 
            "0px -63px" : "0px 2px";
        }
      });
    }, 
    
    // Method to cancel default action on targets;
    fnCancelDefault = function (e) {
      // Cancel method if parent element isn't registered;
      if (typeof this.hsParent === "undefined") {
        return true;
      }
      
      // Normalize event for IE;
      var evt = e || window.event;
      
      // Fire hide/show against parent element;
      fnHideShow.call(this.hsParent);
      
      // Prevent default action of link;
      if (evt && evt.preventDefault) {
        evt.preventDefault();
      }
      evt.returnValue = false; 
    };
    
    // Iterate through parent sections;
    aParents.forEach(function (oElem) { 
      // Collect all target elements;
      var aTargets = myFedLoan.getElementsByClassName("hsTarget", oElem), 
      // Collect all hide/show elements;
      aResults = myFedLoan.getElementsByClassName("hsResults", oElem);
      
      // If both targets and results are found...;
      if (aResults.length > 0 && aTargets.length > 0) {
        // If this is IE, set zoom style to force hasLayout;
        if (document.all && !window.opera) {
          oElem.style.zoom = "1";
        }
        // Iterate through target elements;
        for (i = 0, iLength = aTargets.length; i < iLength; i += 1) {
          // Bind method to cancel default action;
          aTargets[i].onclick = fnCancelDefault;
          // Save reference to parent element;
          aTargets[i].hsParent = oElem;
          // Change Class Name;
          aTargets[i].className = aTargets[i].className.replace(reEnabled, "hsTargetEnabled");
        }
        
        // Save reference to all results in section;
        oElem.aResults = aResults;
        // Save reference to all targets in section;
        oElem.aTargets = aTargets;
        // Initialize section;
        fnHideShow.call(oElem);
      }
    });
  };

  return {
    addLoadEvent: function (vFunc) {
      var oldOnload = window.onload;
      if (typeof window.onload !== "function") {
        window.onload = vFunc;
      } else {
        window.onload = function () {
          oldOnload();
          vFunc();
        };
      }
    }, 
    
    cookies: (function () {
      return {
        createCookie: function (sName, sValue, oParams) {
          
          var dDate, iFutureDays, 
          sCookieString = "",  
          sExpires = "", 
          sPath = oParams && oParams.hasOwnProperty("sPath") ? 
            "; path=" + oParams.sPath : "; path=/", 
          sDomain = oParams && oParams.hasOwnProperty("sDomain") ?
            "; domain=" + oParams.sDomain : "";
      
          if (oParams && oParams.hasOwnProperty("iDays")) {
            dDate = new Date();
            iFutureDays = oParams.iDays * 24 * 60 * 60 * 1000;
            dDate.setTime(dDate.getTime() + iFutureDays);
            sExpires = "; expires=" + dDate.toGMTString();
          }

          sCookieString += sName + "=" + encodeURIComponent(sValue);
          sCookieString += sExpires + sPath + sDomain;
          document.cookie = sCookieString;
          
        }, 

        eraseCookie: function (sName, sType) {

          var i, iLength, aHashArray, // Instantiate variables;
          sThisType = sType ? sType : "single", // Set type of cookie to erase;
          
          /* 
            Initialize Regular Expression looking for given value at 
            the start of an entry;
          */
          reValue = new RegExp("^" + sName), 
          
          // Split string into array;
          aCookieArray = document.cookie.split(";"); 
  
          if (aCookieArray.length > 0) { // Loop through Cookie Array;
            for (i = 0, iLength = aCookieArray.length; i < iLength; i += 1) {
              // Split value into name|value pairs;
              aHashArray = aCookieArray[i].split("="); 
  
              /* 
                Reset the value to null if either the type is 'single' 
                (one cookie) and the cookie name matches the string given 
                (index) requested, or the type is 'class' (multiple cookies) 
                and the cookie's name starts with the string given (index)
              */
  
              aHashArray[0] = aHashArray[0].trim();
              if ((aHashArray[0] === sName && sThisType === "single") || 
                  (aHashArray[0].match(reValue) && sThisType === "class")) {
                PHEAA.util.cookies.createCookie(aHashArray[0], "", {iDays: -1});
              }
            }
          }
        }, 
        
        readCookie: function (sName) {

          var i, iLength, sCookie, 
          sValue = false, 
          sNameEQ = sName.trim() + "=", // Append "=" to cookie name;
          
          // Create array of cookie name/values;
          aCookieArray = document.cookie.split(';'); 
      
          // Iterate through array;
          for (i = 0, iLength = aCookieArray.length; i < iLength; i += 1) { 
            sCookie = aCookieArray[i].trim(); // Save individual entry;
            
            // Compare value to desired cookie;
            if (sCookie.indexOf(sNameEQ) === 0) { 
              // Extract cookie if match;
              sValue =  decodeURIComponent(sCookie.substring(sNameEQ.length, sCookie.length)); 
            }
          }
       
          if (sValue && sValue.length > 0) {
            return sValue; // Return cookie value;      
          } else {
            return null; // Cookie not found, return no value;
          }
          
        }
      };
    }()),
    
    // Method to see if Flash is installed;
    detectFlash: function () {
      // If w3c Method;
      if (navigator.mimeTypes.length > 0) {
        return typeof navigator.mimeTypes["application/x-shockwave-flash"] !== "undefined" ? 
          navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin !== null : false;
      // If ActiveXObject;
      } else if (window.ActiveXObject) {
        try {
          var oActiveX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
          oActiveX = null;
          return true;
        } catch (oError) {
          return false;
        }
      // If cannot detect;
      } else {
        return false;
      }
    }, 
    
    getElementsByClassName: function (sClassName, vElm, sTag) {

      var i, iLength, n, nLength, cElements, reNodeName, 
      sNamespace, sNameResolver, aElements, oNode, bMatch, 
      sClassesToCheck = "", 
      oElm = vElm && vElm.constructor === String ? // Normalize oElm;
        document.getElementById(vElm) || document : 
        vElm || document, 
      aClasses = sClassName.split(" "), // Create array of class names;
      aClassesToCheck = [], // Array for document.evaluate method;
      aReturnElements = []; // Returned array of elements;

      // If browser has a native document.getElementsByClassName method...;
      if (document.getElementsByClassName) {
        // Get collection of elements;
        cElements = oElm.getElementsByClassName(sClassName);
        // Build RegExp to filter by node name;
        reNodeName = sTag ? new RegExp("\\b" + sTag + "\\b", "i") : null;
        
        // Iterate through returned elements;
        for (i = 0, iLength = cElements.length; i < iLength; i += 1) {
          if (!reNodeName || reNodeName.test(cElements[i].nodeName)) {
            aReturnElements.push(cElements[i]);
          }
        }
      } else if (document.evaluate) {
        sTag = sTag || "*";
        sNamespace = "http://www.w3.org/1999/xhtml";
        sNameResolver = document.documentElement.namespaceURI === sNamespace ? 
          sNamespace : null;
      
        for (i = 0, iLength = aClasses.length; i < iLength; i += 1) {
          sClassesToCheck += "[contains(concat(' ', @class, ' '), ' " +
            aClasses[i] + " ')]";
        }
      
        try  {
          aElements = document.evaluate(".//" + sTag + sClassesToCheck, oElm, sNameResolver, 0, null);
        }
        catch (e) {
          aElements = document.evaluate(".//" + sTag + sClassesToCheck, oElm, null, 0, null);
        }
      
        while ((oNode = aElements.iterateNext()) !== null) {
          aReturnElements.push(oNode);
        }
      } else {
        sTag = sTag || "*";
      
        cElements = sTag === "*" && oElm.all ? 
          oElm.all : oElm.getElementsByTagName(sTag);
      
        aClasses.forEach(function (oElement) { 
          aClassesToCheck.push(new RegExp("(^|\\s)" + oElement + "(\\s|$)"));
        });
        
        for (i = 0, iLength = cElements.length; i < iLength; i += 1) {
          bMatch = false;
  
          for (n = 0, nLength = aClassesToCheck.length; n < nLength; n += 1) {
            bMatch = aClassesToCheck[n].test(cElements[i].className);
            if (!bMatch) {
              break;
            }
          }
  
          if (bMatch) {
            aReturnElements.push(cElements[i]);
          }
        }
      }
      
      return aReturnElements;

    }, 
    
    init: function () {
      // Instantiate variables;
      var cFormLinks, oFormsParent, oFooterChild, 
      oAltText = document.getElementById("flashIntroText"), 
      // Get ten most requested forms element;
      oTenForms = document.getElementById("topForms"), 
      oSurvey = document.getElementById("surveyQuestions"), 
      // Set quick links list array;
      aQuickLinkList = [ 
        fnCreate({elem: "a", attributes: {innerHTML: "Make an Online Payment", href: "/make-a-payment/ways-to-pay/pay-online.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Sign in or Create an Account", href: "https://accountaccess.myfedloan.org/auth/index.cfm?returnurl=https://accountaccess.myfedloan.org/accountaccess/index.cfm?event=common.loginRequest&amp;nextEvent=common.accountLogin&clientID=FD", className: "urchin"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Update My Account Information", href: "/manage-account/update-your-account-information.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Apply for a Deferment or Forbearance", href: "/manage-account/deferment-forbearance/index.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Apply for Direct Debit", href: "/make-a-payment/ways-to-pay/direct-debit.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Authorize a 3rd Party Access to My Account", href: "/account-access/account-authorizations.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "View My Loan Balance", href: "https://accountaccess.myfedloan.org/accountaccess/index.cfm?event=common.accountLogin", className: "urchin"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Change My Due Date", href: "/billing-payment/billing/change-due-date.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Change My Name, Address or Email Address", href: "/manage-account/update-your-account-information.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Lower  Payments", href: "/billing-payment/payment-plans/index.shtml"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Get My Loan Payoff Balance", href: "https://accountaccess.myfedloan.org/accountaccess/index.cfm?event=common.accountLogin", className: "urchin"}}), 
        fnCreate({elem: "a", attributes: {innerHTML: "Change My Repayment Plan", href: "/billing-payment/payment-plans/index.shtml"}})
      ],
      sStartLocation = window.location.pathname + window.location.search + window.location.hash; 
      
      // Construct and append quicklist links;
      if (document.getElementById("searchForm")) {
        PHEAA.Urchin.init(fnQuickLink(aQuickLinkList, "searchForm", "before"));
      }
      if (document.getElementById("footer")) {
        oFooterChild = document.getElementById("footer").getElementsByTagName("div")[0];	      
        PHEAA.Urchin.init(fnQuickLink(aQuickLinkList, oFooterChild, "before"));
      }
   
      // Construct and re-append ten forms links;
      if (oTenForms) {
        // Find parent of forms list;
        oFormsParent = oTenForms.parentNode; 
        // Hide parent node of forms;
        oFormsParent.style.display = "none";
        // Collect all links in ten forms element;
        cFormLinks = oTenForms.getElementsByTagName("a");
        
        if (cFormLinks.length > 0) {
          // Create new quick links version of ten forms;
          PHEAA.Urchin.init(fnQuickLink(cFormLinks, oTenForms, "before", false, "/images/quickLink/formBox.gif"));
          // Delete original ten forms element;
          oTenForms.parentNode.removeChild(oTenForms);
        }
        // Display parent node of forms;
        oFormsParent.style.display = "block";
      }
      
      // Construct and re-append survey links;
      if (oSurvey) {
        // Find parent of survey list;
        oFormsParent = oSurvey.parentNode; 
        // Hide parent node of survey list;
        oFormsParent.style.display = "none";
        // Collect all links in survey element;
        cFormLinks = oSurvey.getElementsByTagName("a");
        
        if (cFormLinks.length > 0) {
          // Create new quick links version of surveys;
          PHEAA.Urchin.init(fnQuickLink(cFormLinks, oSurvey, "before", false, "/images/quickLink/surveyDropDown.gif"));
          // Delete original survey element;
          oSurvey.parentNode.removeChild(oSurvey);
        }
        // Display parent node of surveys;
        oFormsParent.style.display = "block";
      }
      
      // Report load of page to Urchin;
      if (typeof PHEAA.Urchin !== "undefined") {
        PHEAA.Urchin.callUrchin(sStartLocation, "Page_Load");
      }
      
      if (!myFedLoan.detectFlash() && oAltText) {
        oAltText.setAttribute("id", null);
      }
      myFedLoan.writeFlashIntro = null;
   
      // Initialize search form;
      if (document.getElementById("sp-q")) {
        fnSetSearchBox();
      }

      // Set up external links to open in new windows;
      fnTargetBlank();
      
      // Activate general hide/show behavior;
      fnSetHideShow();
    }, 
    
    writeFlashIntro: function () {
      var sFlashCookie = myFedLoan.cookies.readCookie("sFlashInit"), 
      sFlashInit = sFlashCookie === "true" ? 
        sFlashCookie : "false";
        
      if (myFedLoan.detectFlash()) {
        // Write flash element into page;
        document.open();
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,0,0" width="698" height="183" title="Let us introduce ourselves."><param name="movie" value="\/images\/homepage\/promos\/FLS_intro.swf?sFlashInit=' + sFlashInit + '" \/><param name="quality" value="high" \/><param name="wmode" value="opaque" \/><embed src="\/images\/homepage\/promos\/FLS_intro.swf?sFlashInit=' + sFlashInit + '" quality="high" wmode="transparent" pluginspage="http:\/\/get.adobe.com\/flashplayer\/" type="application\/x-shockwave-flash" width="698" height="183" alt="Let us introduce ourselves."><\/embed><\/object>');
        document.close();
            
        myFedLoan.cookies.createCookie("sFlashInit", "true");
      }
    }
  };
}());

document.open();
document.write('<style type="text/css">#flashIntroText {left:-9999px;overflow:hidden;position:absolute;top:-9999px;}<\/style>');
document.close();

if (window.addEventListener) { // w3c method;
  window.addEventListener("load", myFedLoan.init, false);
} else if (window.attachEvent) { // IE method;
  window.attachEvent("onload", myFedLoan.init);
}