
window.onload = function() {
	// this function ensures that the proper forms submit when focus us on their fields
	createAccountForm = new submitCreateAccount(document.getElementById('createAccountEmail'),document.getElementById('createAccount'),document.getElementById('btnCreateAccount'));
	SignInEmail = new submitCreateAccount(document.getElementById('SignInEmailAddress'),document.getElementById('SignInFieldset'),document.getElementById('btnSave'));
	SignInPassword = new submitCreateAccount(document.getElementById('signInPassword'),document.getElementById('SignInFieldset'),document.getElementById('btnSave'));

}

function submitCreateAccount(oTextbox,oFieldset,oSubmitButton) {
	this.textbox = oTextbox;
	this.textBoxId = this.textbox.id;
	this.fieldSet = oFieldset;
	this.submitBtn = oSubmitButton;
	this.init();
	
}

submitCreateAccount.prototype.init = function () {
    //save a reference to this object
    var oThis = this;
 
    //assign onkeydown event handler
    this.textbox.onkeydown = function (oEvent) {
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        //call the handleKeyDown() method with the event object
        oThis.handleKeyDown(oEvent);
    };
};
		
submitCreateAccount.prototype.handleKeyDown =  function (oEvent) {
	// if the focus is on the create new account form and enter is pressed, submit the form
	   if (document.activeElement) {
			 if (oEvent.keyCode == 13 && document.activeElement.id == this.textBoxId)  {  //enter
		 			// make sure the btn value gets passed to the page
					var hiddenTextbox = document.createElement('input');
					hiddenTextbox.setAttribute('type','hidden');
					hiddenTextbox.setAttribute('name',this.submitBtn.name);
					hiddenTextbox.setAttribute('value',this.submitBtn.value);
					this.fieldSet.appendChild(hiddenTextbox);
			 }
    }
};






