// <![CDATA[
/******************************************************************************************
* Project: BSP2.5 (BankSeachPlus Version 2.5)
* Module: validate.login.js
* Version: 1.2
* Description: Validate the following: 
* - BankSearchPlus
* 
* CBNet Ltd
* 
* Copyright: this.year() CBNet Ltd
* 
* Email:  support@cbnet.info
* Author: Greg Shiers, Jarratt Ingram

* Note: We do no browser support check within this namespace, as we will do browser support
* check in the validation page.
* error[] comes from errors/errors.js store them in a common place
******************************************************************************************/

// Function to validate the login process	
function validateLogin ( e ) {
	// Set this to false to bypass the JS validation
	var validate = true;
	if ( validate ) {	
		var focus_el = null, 
		    msg = '';
		// If both username and password are not filled in, then thow this errror
		if ( ( validation.empty ( $('username') ) ) && ( validation.empty ( $('username') ) )) {
			msg = error[5];
			focus_el = focus_el || $('username');
		}
		// If password is filled in but username isn't throw this error
		if ( ( validation.empty ( $('username') ) ) && ( !validation.empty ( $('password') ) ) ) {
			msg = error[0];
			focus_el = focus_el || $('email');
		}
		// If username is filled in, but password isnt, throw this error
		if ( ( validation.empty ( $('password') ) ) && ( !validation.empty ( $('username') ) ) ) {
			msg = error[1];
			focus_el = focus_el || $('password');
		}
		// Script has found some one or more errors, so we update the error
		if ( msg != '' ) {
			$('validate').removeClassName('note').addClassName('error').update( msg );
			if ( focus_el.focus ) {
				focus_el.focus();
			}
			Event.stop( e )
		}
		else {
			$('validate').removeClassName('error').removeClassName('note').addClassName('progress').update('logging in ' + $F("username") + ', please wait...');
		}
	}
}
// Lets laod the validation to the browser using prototype's Event.observe method
Event.observe (window, "load", function ( e ) {
	Event.observe ( $('login_form'), "submit", function ( e ) {
		validateLogin ( e );
	})
})
// ]]>