///////////////////////////////////////////////////////////////////////////////
// Main script for www.ftdi.com/advertising/nationalads/default.asp
///////////////////////////////////////////////////////////////////////////////

// This function is executed when the client presses a key on the keyboard.
// If the "enter" key is pressed, then the answer form is submitted.
function keyPressHandler(e) {
	// Netscape 4.x.
	if (document.layers) {
		key = e.which;
	}
	// IE.
	else {
		key = window.event.keyCode;
	}

	// Check if the "enter" key was pressed.
	if (key == 13) {
		// Submit the form.
		submitLogin();

		// Prevent the keypress event from bubbling-up (stops annoying beeping noise).
		return false; 
	}
	else {
		// The "enter" key was not pressed; allow the keypress event to bubble-up.
		return true;
	}
}

// This function is executed when the page initially loads.
function windowOnload()
{
	// Set up the keypress handlers.
	document.frmLogin.txtAccount.onkeypress = keyPressHandler;
	document.frmLogin.txtUserID.onkeypress = keyPressHandler;
	document.frmLogin.txtPassword.onkeypress = keyPressHandler;
	
	// Set focus to the user id text box.
	document.frmLogin.txtAccount.focus();	
	return;
}

// This function validates the user's login information.
function validateLogin()
{ 				
	// Check if an account was entered.
	if (document.frmLogin.txtAccount.value.trim().length == 0)
		{
			alert("Please enter your Account Number.")
			document.frmLogin.txtAccount.focus();										
			return false;
		}
							
	// Check if a user id was entered.
	else if (document.frmLogin.txtUserID.value.trim().length == 0)
		{
			alert("Please enter your User ID.")
			document.frmLogin.txtUserID.focus();
			return false;
		}
		
	// Check if a password was entered.
	else if (document.frmLogin.txtPassword.value.trim().length == 0)
		{
			alert("Please enter your Password.")
			document.frmLogin.txtPassword.focus();
			return false;
		}
		
	else
		{
			// The validations succeeded.
			return true;
		}
}

// This function submits the user's login information.
function submitLogin()
{
	if (validateLogin() == true)
	{
		document.frmLogin.submit();
	}
	return;
}