/*
 * $Id$
 * Copyright (c) 2008 Orbis Technology Ltd. All rights reserved.
 */

// this is to stop login submit being call twice (which appears to happen when button is clicked)
var LoginSubmitted = false;

// Variable to store the function we want to call before login. Basically the first reason why
// it has been added is to save game selections before login to avoid loosing all the selection
// when a customer forgot to login before starting playing a game.
var pre_login_function = "";

// on pressing any key within the login password field
function login_on_enter(e) {
	// on pressing enter within the login password field e.which or e.keyCode = 13
	if(e && e.which) {
		if(e.which == 13) {
			go_login();
		}
	}
	else {
		if(e && e.keyCode == 13) {
			go_login();
		}
	}
}


// Login
function go_login() {

	if (!LoginSubmitted) { 
		var f = document.forms['login'];
		var n_errs = 0;

		reset_error();

		n_errs += ck_mandatory(f.username.value, getXlation("NAV_USERNAME"),
				1, 16, true);
		n_errs += ck_mandatory(f.pwd.value, getXlation("NAV_PASSWORD"), 1, 16,
				true);

		if(n_errs > 0) {
			alert(error_list);
		}
		else {
			// Lock the login
			LoginSubmitted = true;
			
			// Perform the pre-login action if defined
			if(pre_login_function != "") {eval(pre_login_function);}

			// Do the Login
			submit_form('login','GoLogin', 'post');
		}
	}
}