// <![CDATA[
/*
* Copyright: 2005 - 2007 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 func.tions() and scri.pts()
* 
* Note: All functions below are to make sure that we are sticking to standards and are mainly
* for visual effects and loading events and handlers.
*
* Small little script that loads on the login
* @page login.js
* @version 1.1
* @author Greg Shiers, Jarratt Ingram (SI Works Internet)
* @copyright: SI Works Internet Solutions 2005 - this.year();
*/
/*
* Function to show and hide some elements on the loading on the inital page.
* @usage showLoginBoxOnLoad( );
* @returns Array
* @version 1.1
*/
function showLoginBoxOnLoad () {
	$('cover').hide();
	$('dialog').hide();
	$('container').show();
}
/*
* Function to validate the login form
* @usage validateLogin( );
* @returns Array
* @version 1.1
*/
function validateLogin ( event ){
	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') ) )) {
		$('message').update(error[0]).removeClassName('none').addClassName('red');
		$('Username').focus();
		Event.stop( event );
	}
	// If password is filled in but username isn't throw this error
	if ( ( validation.empty ( $('Username') ) ) && ( !validation.empty ( $('Username') ) ) ) {
		$('message').update( error[1] ).removeClassName('none').addClassName('red');
		focus_el = focus_el || $('Username');
		$('Username').focus();
	}
	// If username is filled in, but password isnt, throw this error
	if ( ( validation.empty ( $('Password') ) ) && ( !validation.empty ( $('Username') ) ) ) {
		$('message').update( error[2] ).removeClassName('none').addClassName('red');
		$('Username').focus();
		Event.stop( event );
	}
	// If all validations are correct, then we log the user into the system
	if ( ( !validation.empty ( $('Username') ) ) && ( !validation.empty ( $('Password') ) ) ) {
		$('message').update( message[0] ).removeClassName('none').removeClassName('red');
	}
}
/**
* Use Event.observe to load the above function to the browser once all the code has downloaded
* Note we'll set up a drag event
*/
Event.observe ( window , 'load',
	// Add the validation function to the submit form
	function ( event ) {
		Event.observe('login_form', 'submit', function ( event ) {
			validateLogin ( event );
		});
	// once the page is loaded then we'll load the login box
//	showLoginBoxOnLoad();
	// Set up a drag event using scripto to drag the login box
	new Draggable( 'login_box', { handle: 'login_handler'} );
	$('Username').focus();
});
// ]]>