/*global window, PHEAA */

// 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);
    }
  }());  
},

// Redirect school users to correct portal location.

fnTempSchoolLogin = function () {
  var i,
  oSchoolLoginForm = document.getElementById("schoolLogin"),
  cFormInputs = oSchoolLoginForm ? oSchoolLoginForm.getElementsByTagName("input") : null,
  
  fnSubmitForm = function (e) {
    var evt = e || window.event;
    
    if (evt && evt.preventDefault) {
      evt.preventDefault();
    }
		
    if (oSchoolLoginForm.username.value.substr(0, 2).toUpperCase() === "CG") {
      //oSchoolLoginForm.action = "https://host137.aessuccess.org/AlecWeb/index.htm";
      oSchoolLoginForm.action = "https://host136.aessuccess.org/AlecWeb/index.htm";
    }
    
    oSchoolLoginForm.submit();
    
    return false;
		
  }, 
  
  fnIEKeypress = function () {
    if (window.event.keyCode === 13) { //if the "enter" key was pressed;
      fnSubmitForm();
    }
  };
	
  if (cFormInputs) {
    for (i = cFormInputs.length - 1; i >= 0; i -= 1) {
      if (typeof cFormInputs[i].type === "string" && 
          (cFormInputs[i].type === "image" ||
          cFormInputs[i].type === "submit" ||
          cFormInputs[i].type === "button")) {
        if (window.addEventListener) {
          cFormInputs[i].addEventListener("click", fnSubmitForm, false);	
        } else if (window.attachEvent) {
          cFormInputs[i].attachEvent("onclick", fnSubmitForm);
        }       
      } else if (typeof cFormInputs[i].type === "string" && 
                 cFormInputs[i].type === "password" && 
                 window.attachEvent && !window.opera) {
        cFormInputs[i].attachEvent("onkeypress", fnIEKeypress);
      }
    }
    
    if (window.addEventListener) {
      oSchoolLoginForm.addEventListener("submit", fnSubmitForm, false);	
    } else if (window.attachEvent) {
      oSchoolLoginForm.attachEvent("onsubmit", fnSubmitForm);
    }
  }
};

// End portal script
  

// Bind fnFireUrchin to onload event;
if (window.addEventListener) {
  window.addEventListener("load", fnFireUrchin, false);
  window.addEventListener("load", fnTempSchoolLogin, false);	
} else if (window.attachEvent) {
  window.attachEvent("onload", fnFireUrchin);
  window.attachEvent("onload", fnTempSchoolLogin);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getElementsByClassName(classname){
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = document.all?document.all:document.getElementsByTagName("*");
  for(var i=0,j=els.length; i<j; i++) {
    if (re.test(els[i].className)) {
      a.push(els[i]);
    }
  }
  return a;
}

function addLoadEvent(func){
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function wrapText(text,limit) {
  var strng = text;
  var newString = '';
  var cutPoint;
  if(text.length>limit){
    var firstString = strng.substr(0, limit);
    cutPoint = 0;
    for (var i = 0; i<firstString.length; i++) {
      if (firstString.charAt(i) == ' ') {
        cutPoint = i;
      }
    }
    if (cutPoint == 0) {
      var secondString = strng.substring(limit, strng.length - 1);
      for (var i = secondString.length - 1; i >= 0; i--) {
        if (secondString.charAt(i) == ' ') {
          cutPoint = i + limit;
        }
      }
    }
    if (cutPoint == 0) {
      cutPoint = limit;
    }
    newString = strng.substring(0, cutPoint) + '...';
  } else {
    newString=text;
  }
  return newString;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
  // NS/Opera version >= 3 check for Flash plugin in plugin array
  var flashVer = -1;
  if (navigator.plugins != null && navigator.plugins.length > 0) {
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
      var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
      var descArray = flashDescription.split(" ");
      var tempArrayMajor = descArray[2].split(".");
      var versionMajor = tempArrayMajor[0];
      var versionMinor = tempArrayMajor[1];
      if ( descArray[3] != "" ) {
        tempArrayMinor = descArray[3].split("r");
      } else {
        tempArrayMinor = descArray[4].split("r");
      }
      var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
      var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
    }
  }
  // MSN/WebTV 2.6 supports Flash 4
  else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
  // WebTV 2.5 supports Flash 3
  else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
  // older WebTV supports Flash 2
  else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
  return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
  reqVer = parseFloat(reqMajorVer + "." + reqRevision);
  // loop backwards through the versions until we find the newest version
  windowMethod='transparent';
  for (i=25;i>0;i--) {
    if (isIE && isWin && !isOpera) {
      versionStr = VBGetSwfVer(i);
    } else {
      versionStr = JSGetSwfVer(i);
    }
    if (versionStr == -1 ) {
      return false;
    } else if (versionStr != 0) {
      if(isIE && isWin && !isOpera) {
        tempArray         = versionStr.split(" ");
        tempString        = tempArray[1];
        versionArray      = tempString .split(",");
      } else {
        versionArray      = versionStr.split(".");
      }
      var versionMajor      = versionArray[0];
      var versionMinor      = versionArray[1];
      var versionRevision   = versionArray[2];
      var versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
      var versionNum        = parseFloat(versionString);
      // is the major.revision >= requested major.revision AND the minor version >= requested minor
      if (versionMajor > reqMajorVer) {
        return true;
      } else if (versionMajor == reqMajorVer) {
        if (versionMinor > reqMinorVer)
          return true;
        else if (versionMinor == reqMinorVer) {
          if (versionRevision >= reqRevision)
            return true;
        }
      }
      return false;
    }
  }
}

function flashCookieCheck(){
  var flashCookie=checkCookie('flashCheck');
  // alert(flashCookie);
  if (flashCookie==true){
    flashSource+='&redirect=true';
  } else {
    flashSource+='&redirect=false';
  }  
}

function checkCookie(index) {
  var answer=false;
  var strCook = document.cookie;
  var cookieArray = strCook.split(';');
  if(cookieArray.length>0){
    for(var i=0;i<cookieArray.length;i++){
      var hashArray= strCook.split('=');
      if(hashArray[0]==index){
        answer=true;
      }
    }
  }
  return answer;
}

function writeCookie(name,value){
  window.document.cookie = name+"="+value;
}

function readCookie(labelName){
  var labelLen = labelName.length;
  var cookieData = document.cookie;
  var cLen = cookieData.length;
  var i = 0;
  var cEnd;
  while (i < cLen){
    var j=i+labelLen;
    if(cookieData.substring(i,j) == labelName) {
      cEnd = cookieData.indexOf(";",j);
      if (cEnd == -1) {
        cEnd = cookieData.length;
      }
      return unescape(cookieData.substring(j+1, cEnd));
    }
    i++;
  }
  return "";
}

function loginActivate(){
  var g=getElementsByClassName('bLink');
  for (var j=0;j<g.length;j++){
    g[j].href="#";
  }
  var interval=setTimeout('deleteEntry()',100);
}

function deleteEntry(){
  if(document.getElementById('userid'))document.getElementById('userid').value='';
}

/* Insertion of RSA Code */
  // Delimiter Variables
  var SEP = '|';
  var PAIR = '=';
  var DEV = '~';
  var ver = 1;

  /*
  Browser Detection
  */  
  ua = navigator.userAgent.toLowerCase();
  opera = ua.indexOf("opera") >= 0;
  ie = ua.indexOf("msie") >= 0 && !opera;
  iemac = ie && ua.indexOf("mac") >= 0;
  moz = ua.indexOf("mozilla") && !ie && !opera;
  os = navigator.platform;

  function goto1(url) {
      window.location.replace(url);
  }

  /*
   * Used for flash fix in IE and shared objects.
   *
   */
  function flashfix(sendUrl, gotoUrl, defaultUrl)
  {
      
      document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1">\n');
      document.write('<param name="movie" value="pmfso.swf" />\n');
      document.write('<param name="quality" value="high" />\n');
      document.write('<param name="bgcolor" value=#FFFFFF />\n');
      document.write('<param name="FlashVars" value="gotoUrl='+gotoUrl+'%26detect%3D2&sendUrl='+sendUrl+'" />\n');
      document.write('<embed src="pmfso.swf" FlashVars="gotoUrl='+gotoUrl+'%26detect%3D3&sendUrl='+sendUrl+'" quality="high" bgcolor="#FFFFFF" width="1" height="1" type="application/x-shockwave-flash" />\n');
      document.write('<noembed>\n');
      document.write('<script>\n');
      document.write('goto1(\''+defaultUrl +'&detect=5\');\n');
      document.write('</script>\n');
      document.write('</noembed>\n');
      document.write('<noobject></noobject>\n');
      document.write('</embed>\n');
      document.write('</object>\n');


  }


  /*
  Misc. Utility Functions
  */  
  function activeXDetect(componentClassID) 
  {
     componentVersion = document.body.getComponentVersion('{'+componentClassID+'}','ComponentID');
     return (componentVersion != null) ? componentVersion : false;
  }
  
  // this method is not used.
  function extractVersions(s) 
  {
    extractedVersions = "";
      // remove all but 0-9 and '.', '_', ',' separators.
    for (var i = 0; i < s.length; i++) {
      charAtValue = s.charAt(i);
      if ((charAtValue >= '0' && charAtValue <= '9') || charAtValue == '.' || charAtValue == '_' || charAtValue == ',')
        extractedVersions += charAtValue;
    }
    return extractedVersions;
    }

  function stripIllegalChars(value) 
  {
    t = "";
    //first we need to escape any "\n" or "/" or "\"
    value = value.toLowerCase();
    for (i = 0; i < value.length; i++) {
      if (value.charAt(i) != '\n' && value.charAt(i) != '/' && value.charAt(i) != "\\")
      {
        t += value.charAt(i);
      }
      else if (value.charAt(i) == '\n')
      {
        t += "n";
      }
    }
    return t;
  }
  
  function stripFullPath(tempFileName, lastDir) 
  {
    fileName = tempFileName;
    //anything before the last lastDir will be lost
    filenameStart = 0;
    filenameStart = fileName.lastIndexOf(lastDir);
    if (filenameStart < 0)
      return tempFileName;
    filenameFinish = fileName.length;    
    fileName = fileName.substring(filenameStart + lastDir.length, filenameFinish);
    return fileName;
  }  
  /*
  Fingerprinting Functions
  */  
  
  /*
  This function captures the User Agent String from the Client Browser
  */  
  function fingerprint_browser () 
  {
    t = ua +SEP+ navigator.appVersion +SEP+ navigator.platform;
    if (ie) 
    {
      t += SEP + navigator.appMinorVersion +SEP+ navigator.cpuClass +SEP+ navigator.browserLanguage;
      t += SEP + ScriptEngineBuildVersion();
    } 
    else if (moz) 
    {
      t += SEP + navigator.language;
    }
    return t;
  }
  
  /*
  This function captures the Client's Screen Information
  */    
  function fingerprint_display () 
  {
    t = "";
    if (self.screen) 
    {
      t += screen.colorDepth +SEP+ screen.width +SEP+ screen.height +SEP+ screen.availHeight;
    }
    return t;
  }

  /*
  This function captures the user's plugin types from the browser.  
  Has undergone a major overhaul for 2.3 for software size reduction
  */      
  function fingerprint_software () 
  {
    t = "";
    isFirst = true;
    
    /*
    Create a Hashtable of mozilla components
    */    
    var ht = new Hashtable();
    ht.put('npnul32.dll','def');      // Default netscape plugin
    ht.put('npqtplugin6.dll','qt6');   // Quicktime 6.5.1
    ht.put('npqtplugin5.dll','qt5');   // Quicktime 6.5.1
    ht.put('npqtplugin4.dll','qt4');   // Quicktime 6.5.1
    ht.put('npqtplugin3.dll','qt3');   // Quicktime 6.5.1
    ht.put('npqtplugin2.dll','qt2');   // Quicktime 6.5.1
    ht.put('npqtplugin.dll','qt1');    // Quicktime 6.5.1  
    ht.put('nppdf32.dll','pdf');      // Adobe Acrobat        
    ht.put('NPSWF32.dll','swf');      // Macromedia Flash 
    ht.put('NPJava11.dll','j11');      // Java 1.4.2_02
    ht.put('NPJava12.dll','j12');      // Java 1.4.2_02
    ht.put('NPJava13.dll','j13');      // Java 1.4.2_02
    ht.put('NPJava32.dll','j32');      // Java 1.4.2_02
    ht.put('NPJava14.dll','j14');      // Java 2 5.0 Update 4
    ht.put('npoji600.dll','j61');      // Java 2 5.0 Update 4
    ht.put('NPJava131_16.dll','j16');   // Java 1.3.1_16 
    ht.put('NPOFFICE.DLL','mso');      // Microsoft Office 2003        
    ht.put('npdsplay.dll','wpm');    // Windows Media Player    
    ht.put('npwmsdrm.dll','drm');      // Windows DRM
    ht.put('npdrmv2.dll','drn');      // Netscape DRM
    ht.put('nprjplug.dll','rjl');      // Real Jukebox  
    ht.put('nppl3260.dll','rpl');      // Real Player Live Connect 
    ht.put('nprpjplug.dll','rpv');      // Real Player Version        
    ht.put('npchime.dll','chm');    // Chime
    ht.put('npCortona.dll','cor');      // Cortina 
    ht.put('np32dsw.dll','dsw');      // Macromedia Director          
    ht.put('np32asw.dll','asw');    // Macromedia Authorware
      
    if (navigator.plugins.length > 0) 
    {      
      // since opera will give the full path of the file, we will
      // just extract the filenames, ignoring descripton and length since filenames are distinguished enough
      temp = "";
      moz = "";
      key = "";
      lastDir = "Plugins";
      for (i = 0; i < navigator.plugins.length; i++) 
      {        
        plugin = navigator.plugins[i];
        moz = stripFullPath(plugin.filename, lastDir);
        if (isFirst==true) 
        {                    
          key = ht.containsKey(moz);
          if(key)
          {
            temp += ht.get(moz);
            isFirst=false;              
          }  
          else
          {  
            temp = "";
            isFirst=false;        
          }          
        }
        else 
        {
          key = ht.containsKey(moz);
          if(key)
          {
            temp += SEP + ht.get(moz);
          }
          else
          {
            temp += "";
          }        
        }
      }
      t = stripIllegalChars(temp);    

    }
    else if (navigator.mimeTypes.length > 0)     
    {    
      key = "";
      for (i = 0; i < navigator.mimeTypes.length; i++) 
      {      
        mimeType = navigator.mimeTypes[i];                        
        if (isFirst==true) 
        {
          key = ht.containsKey(mimeType);
          if(key)
          {
            t += ht.get(mimeType) + PAIR + mimeType;
            isFirst=false;
          }  
          else 
          {
            t += "unknown" + PAIR + mimeType;
            isFirst=false;
          }
        }
        else 
        {
          key = ht.containsKey(mimeType);
          if(key)
          {
            t += SEP + ht.get(mimeType) + PAIR + mimeType;
          }
          else
          {            
            temp += "";
          }        
        }
    }      
    }  
    
    /*
    Create an Array of IE components
    */
    else if (ie) 
    {      
      names = new Array(
      "abk", // Address Book
      "wnt", // Windows Desktop Update NT
      "aol", // AOL ART Image Format Support
      "arb", // Arabic Text Display Support
      "chs", // Chinese (Simplified) Text Display Support
      "cht", // Chinese (traditional) Text Display Support
      "dht", // Dynamic HTML Data Binding 
      "dhj", // Dynamic HTML Data Binding for Java
      "dan", // DirectAnimation
      "dsh", // DirectShow  
      "heb", // Hebrew Text Display Support
      "ie5", // Internet Explorer 5 Browser
      "icw", // Internet Connection Wizard
      "ibe", // Internet Explorer Browsing Enhancements 
      "iec", // Internet Explorer Classes for Java
      "ieh", // Internet Explorer Help
      "iee", // Internet Explorer Help Engine
      "jap", // Japanese Text Display Support  
      "krn", // Korean Text Display Support
      "lan", // Language Auto-Selection
      "swf", // Macromedia Flash
      "shw", // Macromedia Shockwave Director
      "msn", // MSN Messenger Service
      "wmp", // Windows Media Player
      "obp", // Offline Browsing Pack 
      "oex", // Outlook Express 
      "net", // NetMeeting NT
      "pan", // Pan-European Text Display Support
      "thi", // Thai Text Display Support
      "tks", // Task Scheduler
      "uni", // Uniscribe   
      "vtc", // Vector Graphics Rendering (VML)
      "vnm", // Vietnamese Text Display Support
      "mvm", // Microsoft virtual machine
      "vbs", // Visual Basic Scripting Support
      "wfd"  // Web Folders    
      );  
      
      /*
      Create a Hashtable of IE components guids
      */      
      components = new Array(
      "7790769C-0471-11D2-AF11-00C04FA35D02", 
      "89820200-ECBD-11CF-8B85-00AA005B4340", 
      "47F67D00-9E55-11D1-BAEF-00C04FC2D130", 
      "76C19B38-F0C8-11CF-87CC-0020AFEECF20", 
      "76C19B34-F0C8-11CF-87CC-0020AFEECF20",  
      "76C19B33-F0C8-11CF-87CC-0020AFEECF20",  
      "9381D8F2-0288-11D0-9501-00AA00B911A5", 
      "4F216970-C90C-11D1-B5C7-0000F8051515", 
      "283807B5-2C60-11D0-A31D-00AA00B92C03", 
      "44BBA848-CC51-11CF-AAFA-00AA00B6015C", 
      "76C19B36-F0C8-11CF-87CC-0020AFEECF20", 
      "89820200-ECBD-11CF-8B85-00AA005B4383", 
      "5A8D6EE0-3E18-11D0-821E-444553540000", 
      "630B1DA0-B465-11D1-9948-00C04F98BBC9", 
      "08B0E5C0-4FCB-11CF-AAA5-00401C608555", 
      "45EA75A0-A269-11D1-B5BF-0000F8051515", 
      "DE5AED00-A4BF-11D1-9948-00C04F98BBC9", 
      "76C19B30-F0C8-11CF-87CC-0020AFEECF20", 
      "76C19B31-F0C8-11CF-87CC-0020AFEECF20", 
      "76C19B50-F0C8-11CF-87CC-0020AFEECF20", 
      "D27CDB6E-AE6D-11CF-96B8-444553540000",
      "2A202491-F00D-11CF-87CC-0020AFEECF20", 
      "5945C046-LE7D-LLDL-BC44-00C04FD912BE", 
      "22D6F312-B0F6-11D0-94AB-0080C74C7E95", 
      "3AF36230-A269-11D1-B5BF-0000F8051515", 
      "44BBA840-CC51-11CF-AAFA-00AA00B6015C", 
      "44BBA842-CC51-11CF-AAFA-00AA00B6015B", 
      "76C19B32-F0C8-11CF-87CC-0020AFEECF20", 
      "76C19B35-F0C8-11CF-87CC-0020AFEECF20", 
      "CC2A9BA0-3BDD-11D0-821E-444553540000", 
      "3BF42070-B3B1-11D1-B5C5-0000F8051515", 
      "10072CEC-8CC1-11D1-986E-00A0C955B42F", 
      "76C19B37-F0C8-11CF-87CC-0020AFEECF20", 
      "08B0E5C0-4FCB-11CF-AAA5-00401C608500", 
      "4F645220-306D-11D2-995D-00C04F98BBC9", 
      "73FA19D0-2D75-11D2-995D-00C04F98BBC9"     
      );

      document.body.addBehavior("#default#clientCaps")
      for (i = 0; i < components.length; i++) 
      {    
        ver = activeXDetect(components[i]);  
        name = names[i];
        if (ver) 
        {
          if (isFirst==true) 
          {          
            t += name + PAIR + ver;
            isFirst=false;
          } 
          else 
          {
            t += SEP + name + PAIR + ver;
          }
        }
        else 
        {
          t +="";
          isFirst=false;
        }
      }
    }
    return t;
  }
  
  /*
  This function captures the user's timezone in GMT
  */    
  function fingerprint_timezone () {          
    var gmtHours = (new Date().getTimezoneOffset()/60)*(-1);        
    return gmtHours;
  }
    
  /*
  This function captures the user's browser language. 
  Note: this is captured in the User Agent String, 
  but this function provides more detailed information from IE (system language)
  */    
  function fingerprint_language () {          
    var lang;  

    if (typeof(navigator.language) != "undefined")
    {          
      lang = "lang" + PAIR + navigator.language +SEP;            
    }
    else if (typeof(navigator.browserLanguage) != "undefined")
    {      
      lang = "lang" + PAIR + navigator.browserLanguage + SEP;              
    }
    else      
    {
      lang = "lang" + PAIR + "" + SEP;                
    }
    
    (typeof(navigator.systemLanguage) != "undefined") ? lang += "syslang" + PAIR + navigator.systemLanguage + SEP : lang += "syslang" + PAIR + "" + SEP;
    (typeof(navigator.userLanguage) != "undefined") ? lang += "userlang" + PAIR + navigator.userLanguage : lang += "userlang" + PAIR + "";
      
    return lang;    
  }
  
  /*
  This function captures whether or not Java is enabled
  */
  function fingerprint_java () 
  {  
    var javaEnabled;        
    javaEnabled = (navigator.javaEnabled()) ? 1 : 0
    return javaEnabled;
  }  
  
  /*
  This function captures whether or not user enabled cookies or not
  */  
  function fingerprint_cookie () 
  {          
      
    var cookieEnabled=(navigator.cookieEnabled)? 1 : 0
    //if not IE4+ nor NS6+
    if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)
    { 
      document.cookie="testcookie"
      cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? 1 : 0
    }
    return cookieEnabled;  
  }  
  
  
  /*
  Fingerprint Communication - 3 options
  1.  Post Asynchronously
  2.  Post Synchronously
  3.  Query String
  */
    
  /*
  Async Post Helper Method
  */
  function form_add_data(fd, name, value) {
    if (fd && fd.length > 0) {
      fd += "&";
    }
    else {
      fd = "";
    }
    
    fd += name + '=' + escape(value);
    return fd;
  }
  
  function form_add_fingerprint(fd, name, value) {
    fd = form_add_data(fd, name + "d", value);
    return fd;
  }


  /*
  Fingerprint - POST Asynchronously
  */
  function asyncpost_fingerprints(url) {
    var xmlhttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    @end @*/

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
    }
    if (!xmlhttp) return false;
    
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
    var fd;
    fd = form_add_fingerprint(fd, "fp_browser", fingerprint_browser());
    fd = form_add_fingerprint(fd, "fp_display", fingerprint_display());
    fd = form_add_fingerprint(fd, "fp_software", fingerprint_software());
    fd = form_add_fingerprint(fd, "fp_timezone", fingerprint_timezone());
    fd = form_add_fingerprint(fd, "fp_language", fingerprint_language());
    fd = form_add_fingerprint(fd, "fp_java", fingerprint_java());
    fd = form_add_fingerprint(fd, "fp_cookie", fingerprint_cookie());        

    xmlhttp.send(fd); // fire and forget
    return true;
  }  
  
  function submitenter(myfield,e,hitCounterCode){
    var keycode;
    if (window.event){
      keycode = window.event.keyCode;
    } else if (e){
      keycode = e.which;
    } else {
      return true;
    }
    if (keycode == 13){
      var inputFields=myfield.form.getElementsByTagName('input');
      var blankField=false;
      for(var i=0;i<inputFields.length;i++){
        if(((inputFields[i].value=="")||(inputFields[i].value==null))&&((inputFields[i].name=='userid')||(inputFields[i].name=='RACFID')||(inputFields[i].name=='Password')||(inputFields[i].name=='password'))){
          blankField=true;   
        }
      }
      if(blankField==false){
        if((hitCounterCode)&&(hitCounterCode!='')){
          hitCounter(hitCounterCode);   
        }
        myfield.form.submit();
        return false;
      } else {
        return true;   
      }
    } else if(keycode == 8) {
      return true;
    } else if (hitCounterCode='AccountAccess') {
      if (myfield.value.length>11){
        return false;
      } else {
        return true;	
      }
    } else {
      return true;	
    }
  }
              
  /*
  Fingerprint - POST data
  */
  function post_fingerprints() 
  {
      /*
      Uncomment for another version
      
    document.studentLogin.fp_browser.value = fingerprint_browser();
    document.studentLogin.fp_screen.value = fingerprint_display();
    document.studentLogin.fp_software.value = fingerprint_software();
    document.studentLogin.fp_timezone.value = fingerprint_timezone();
    document.studentLogin.fp_language.value = fingerprint_language();
    document.studentLogin.fp_java.value = fingerprint_java();
    document.studentLogin.fp_cookie.value = fingerprint_cookie();        
    */
    document.studentLogin.pm_fp.value = add_deviceprint();
    return true;
  }  

  /*
  Fingerprint - to the query string
  */  

  /*
  Fingerprint - delimited string value where names are in accordance with PassMarkDeviceRequest
  */  
  function add_deviceprint() 
  {
    var t = "version=" + ver +"&pm_fpua=" + fingerprint_browser("") + "&pm_fpsc=" + fingerprint_display("") + "&pm_fpsw=" + fingerprint_software("")
        + "&pm_fptz=" + fingerprint_timezone("")+ "&pm_fpln=" + fingerprint_language("")
        + "&pm_fpjv=" + fingerprint_java("") + "&pm_fpco=" + fingerprint_cookie("");
    return t;
  }  

  /*
  Helper Hashtable implementation 
  */    
  function Hashtable()
  {
      var keysToIndex = {__indexToValue:[],__indexToKeys:[]};
      var activeEnum = [];
      var tableLength = 0;
      var self = this;
    
      /*
      This inner Object constructor is used to implement a Java
      style Enumerator (and Iterator) Object.
      */
      
      function Enumeration(arrNm)
      {
          var lastIndex = null;
          var enumIndex = 0;
          while(typeof activeEnum[enumIndex] == 'number')enumIndex += 1;
          activeEnum[enumIndex] = 0;
        
          /*
          Returns true if this Enumerator/ has another entry to
          return, else returns false.
          */
          this.hasNext = this.hasMoreElements = function(){
            if(activeEnum[enumIndex] < tableLength){
                return true;
            }else{
                if(typeof activeEnum[enumIndex] == 'number'){
                    activeEnum[enumIndex] = null;
                }
                return false;
            }
        };
        
        /*
        Returns the next item from this Enumerator/Iterator (key
        or value, depending on whether it was created with the keys
        or elements methods).
        */
        this.next = this.nextElement = function(){
            if(this.hasNext){
                lastIndex = activeEnum[enumIndex];
                return keysToIndex[arrNm][activeEnum[enumIndex]++];
            }else{
                return null;
            }
        };
        
        /*
        Removes the last entry (key/value pair) accessed with the
        next or nextElement methods of this Enumerator/Iterator
        (if any). The key/value pair is removed regardless of whether
        the Enumerator/Iterator was accessing keys or values.
        */
        this.remove = function(){
            if(typeof lastIndex == 'number'){
                self.remove(keysToIndex.__indexToKeys[lastIndex]);
                lastIndex = null;
            }
          };
      };
      // End Enumeration
    
      /*
      Returns the value mapped to the provided (String) key, or null
      if the key is not mapped to a value.
      */
      this.get = function(key){
        if(typeof keysToIndex[key] == 'number'){
            return keysToIndex.__indexToValue[keysToIndex[key]];
        }else{
            return null;
        }
    };
      /*
      Adds the value provided to this Hashtable mapped to the key
      provided.
      */
      this.put = function(key, value){
      if(typeof keysToIndex[key] == 'number'){
            keysToIndex.__indexToValue[keysToIndex[key]] = value;
        }else{
            keysToIndex[key] = tableLength;
            keysToIndex.__indexToValue[tableLength] = value;
            keysToIndex.__indexToKeys[tableLength++] = key;
        }
      };
      /*
      Removes the key and any value mapped to it from this
      Hashtable.
      */
      this.remove = function(key){
          var remIndex = keysToIndex[key];
          if(typeof remIndex == 'number'){
              delete keysToIndex[key];
              tableLength -= 1;
              for(var c = remIndex;c < tableLength;c++){
                  keysToIndex.__indexToValue[c] =
                                     keysToIndex.__indexToValue[c+1];
                  keysToIndex[(keysToIndex.__indexToKeys[c] =
                                keysToIndex.__indexToKeys[c+1])] = c;
              }
              for(var c = 0;c < activeEnum.length;c++){
                  if((activeEnum[c])&&(remIndex < activeEnum[c])){
                      activeEnum[c] -= 1;
                }
            }
          }
      };

      /*
      Returns the length of this Hashtable.
      */
      this.size = function(){
          return tableLength;
      };
    
      /*
      This method is not intended for external use! use elements
      and keys methods instead.
      */
      this.__enumerate = function(type){
        return new Enumeration(type);
      };

    /*
    Returns an object that is similar to the Java Enumeration
    Interface, having hasMoreElements and nextElement Methods. This
    object also reproduces the Java Iterator interface, having methods
    hasNext, next and remove. This enumeration is of the values stored
    in the Hashtable.
    */
    Hashtable.prototype.elements = function(){
        return this.__enumerate('__indexToValue');
    }

    /*
    Returns an object that is similar to the Java Enumeration
    Interface, having hasMoreElements and nextElement Methods. This
    object also reproduces the Java Iterator interface, having methods
    hasNext, next and remove. This enumeration is of the keys stored
    in the Hashtable.
    */
    Hashtable.prototype.keys = function(){
        return this.__enumerate('__indexToKeys');
    }


    /*
    Removes all entry's from the Hashtable
    */
    Hashtable.prototype.clear = function(){
        var e = this.keys();
        while(e.hasNext()){
            this.remove(e.next());
        }
    }

    Hashtable.prototype.toString = function(){
      var n,e = this.keys();
      var st = '';
      while(e.hasNext()){
          n = e.next();
          st += n+' =&gt; '+this.get(n)+'\r\n';
      }
      return st;

    }

    /*
    Returns true if this Hashtable contains a value that is equal
    to the value provided, else returns false
    */
    Hashtable.prototype.contains = function(testVal){
        var e = this.elements();
        while(e.hasNext()){
            if(e.next() == testVal)return true;
        }
        return false;
    }

    /*
    Returns true if this Hashtable contains a value that is equal
    to the value provided, else returns false.
    */
    Hashtable.prototype.containsValue = Hashtable.prototype.contains;

    /*
    Returns true if this Hashtable contains a value mapped to
    the value provided, else returns false.
    */
    Hashtable.prototype.containsKey = function(testKey){
        return (this.get(testKey) != null);
    }

    /*
    Returns true if this Hashtable has zero entry's.
    */
    Hashtable.prototype.isEmpty = function(){
        return (this.size() == 0);
    }

    /*
    If the parameter provided is another Hashtable object
    then all of the key/value pairs from the provided Hashtable
    are added to this Hashtable.
    */
    Hashtable.prototype.putAll = function(hTable){
      if(hTable.constructor == Hashtable){
          var n,e = hTable.keys();
          while(e.hasNext()){
              n = e.next();
              this.put(n, hTable.get(n));
          }
      }
    }

    /*
    Returns a 'shallow' copy of this Hashtable.
    */
    Hashtable.prototype.clone = function(){
        var ht = new Hashtable();
        ht.putAll(this);
        return ht;
    }

    /*
    Returns true if this Hashtable equals the parameter
    provided, else it returns false.
    */
    Hashtable.prototype.equals = function(o){
      return (o == this);
    }     
}
