/**
* Copyright: 2005 - this.year() SI Works Internet Solutions
* If you have come across this page, its cause you are snooping through code, and are generally a developer as such
* If you would like to use some of the code on this page, please simply email support@siworks.co.za and ask permission
* it would be much appreciated, as we have worked very hard on these fucntions and scripts
* 
* Validation code for forgot password module
* @version 1.0
* @author Greg Shiers, Jarratt Ingram (SI Works Internet)
* @copyright: SI Works Internet Solutions 2005 - 2007
* 
*/
/**
* Initialize the login validator
* @param 
* @author Greg Shiers
* @version 1.0
*/
function initialize ( ) {
	// Attatch event listeners to buttons using attatchEventListener()
	// First check if the element exsists, then add the event listener if it is
	if ( $('login_form') ) { attachEventListener (  $('login_form') , "submit" , function( event ) { validateLogin( event ) }  , false); }	
}
/**
* Validates the adding and editing of a new dealer registration
* @param ( e ) which form to process this validation through
* @return N/A
* @author Greg Shiers
* @version 1.0
*/
function validateLogin ( event ) {
	// Turn JS validation on or off;
	var validate = true;
	// Make sure we have an event within this function
	if (typeof event == "undefined") {
    	event = window.event;
	}
	if ( validate ) {	
		var focus_el = null, 
		    msg = '';
		// If both username and password are not filled in, then thow this errror
		if ( ( validation.empty ( $('login_email') ) ) && ( validation.empty ( $('login_password') ) )) {
			msg = error[11];
			focus_el = focus_el || $('login_email');
		}
		// If password is filled in but username isn't throw this error
		if ( ( validation.empty ( $('login_email') ) ) && ( !validation.empty ( $('login_password') ) ) ) {
			msg = error[12];
			focus_el = focus_el || $('login_email');
			focus_el = focus_el || $('login_email');
		}
		// If username is filled in, but password isnt, throw this error
		if ( ( validation.empty ( $('login_password') ) ) && ( !validation.empty ( $('login_email') ) ) ) {
			msg = error[13];
			focus_el = focus_el || $('login_password');
		}
		// Script has found some one or more errors, now we run the alert
		if ( msg != '' ) {
			$('message').innerHTML = msg;
			if ( focus_el.focus ) {
				focus_el.focus();
			}
			stopDefaultAction( event )
		}
		else {
			$('message').innerHTML = "loggin in, please wait...";
			$('message').style.color = "#666";
		}
	}
}
addLoadListener( function ( event ) {
	initialize ( event );
} );
// ]]>
