addLoadEvent(function () {

  document.getElementById("username").value = ""; //ensures that the username is blank if the user moves to another page and then hits the Back button;
  
  document.getElementById("studentLogin").onsubmit = function () {
	aesLogin({theForm: this, hitCounter: "account_access"});
  };
  
  document.getElementById("createAnAccount").onclick = function () {
	aesLogin({theForm: document.studentLogin, hitCounter: "account_access", requestAction: "enroll"});
  };
  
  document.getElementById("forgotYourUsername").onclick = function () {
	aesLogin({theForm: document.studentLogin, hitCounter: "account_access", requestAction: "forgotUsername"});
  };
  
  document.getElementById("schoolLogin").onsubmit = function () {
	return aesLogin({theForm: this, hitCounter: "school_login"});
  };

  //FF is able to submit the form by pressing Enter when the inputs have the focus, but IE needs to have an event handler attached to each input field (I don't know why, the form *should* submit in IE, also);
  if (document.attachEvent) {
    var inputs = document.getElementById("schoolLogin").getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
      if (inputs[i].getAttribute("type") == "password") {
        inputs[i].attachEvent("onkeypress",
	      function () {
	        if (window.event.keyCode == 13) { //if the "enter" key was pressed;
		      document.getElementById("schoolLogin").onsubmit();
		    }
	      }
	    )
	  }
    }
  }

  document.getElementById("changeYourPassword").onclick = function () {
	aesLogin({hitCounter: "school_password"});
  };
  
  document.getElementById("ezReset").onclick = function () {
	aesLogin({hitCounter: "school_login"});
	openPortalChild("https://host98.aessuccess.org/ezreset.cgi");
  };
  
  document.getElementById("viewSchoolMessages").onclick = function () {
	aesLogin({hitCounter: "school_messages"});
  };
  
});

function aesLogin(obj) {
/*
the obj can contain:
  obj.theForm = Object object,
  obj.hitCounter = String string,
  obj.requestAction = String string

Ex.
  {
    theForm: this,
	hitCounter: "account_access",
	requestAction: "forgotUsername"
  }
  
Note:
  1. the order of the properties doesn't matter
  2. the number of properties can vary

Trigger load balancing by placing "" as the form's action.
Otherwise, the form will post to whatever url is in its action attribute.
*/

  /*gather the "webtrends" info by changing the src attribute and therefore forcing the browser to download another file, thus it will be seen in the logs*/
  if (obj.theForm && obj.theForm.id == "studentLogin") {
    document.getElementById("counter").src = "/links/hm_js_account_access.htm";
  } else if (obj.theForm && obj.theForm.id == "schoolLogin") {
	document.getElementById("counter").src = "/links/hm_js_school_login.htm";
  } else {
	document.getElementById("counter").src = "/links/hm_js_" + obj.hitCounter + ".htm";
  }
  
  /*setting this hidden field's attribute enables db to direct the user to the appropriate page (this hidden value will be posted along with the form's other values*/
  if (obj.requestAction) { //set the value of the hidden requestAction element, if present;
    document.studentLogin.requestAction.value = obj.requestAction;
  } else { //make sure to reset to an empty string or the user could be sent back to a previously-visited page (i.e. "create an account");
	document.studentLogin.requestAction.value = "";
  }
  
  /*enable the primitive load balancing*/
  if (obj.theForm && obj.theForm.id == "studentLogin" && obj.theForm.action == "") {
    var theTime = new Date();
    var captureTime = theTime.getMilliseconds();

    /*change these two urls if load balancing*/
    if (captureTime % 2 == 0) { //if captureTime ends with an even number;
      obj.theForm.action = "https://login.aessuccess.org/auth/index.cfm";
    } else { //if captureTime ends with an odd number;
	  obj.theForm.action = "https://login.aessuccess.org/auth/index.cfm";
    }
    obj.theForm.submit();

  /*else the form's action has a url (i.e., don't perform load balancing), so just submit the form*/
  } else if (obj.theForm && obj.theForm.id == "studentLogin" && obj.theForm.action != "") {
	obj.theForm.submit();
  }

  if (obj.theForm && obj.theForm.id == "schoolLogin") {
	if (document.getElementById("RACFID").value == "") {
	  document.getElementById("RACFID").focus();
	  alert('Please enter a value for the "School Portal Username" field.');
	  return false;
	} else if (document.getElementById("Password1").value == "") {
	  alert('Please enter a value for the "School Portal Password" field.');
	  document.getElementById("Password1").focus();
	  return false;
	} else { //submit the form if both password fields contain characters;
	  obj.theForm.submit();
	}
  }
  
}