/*
Credits: Bit Repository
URL: http://www.bitrepository.com/web-programming/ajax/login-form.html
*/

// Preload Images

	window.addEvent('domready', function() {

	$('loginform').addEvent('submit', function(e) {
		// Prevents the default submit event from loading a new page.
		e.stop();

		// Show the spinning indicator when pressing the submit button...
		$('ajax_loading').setStyle('display','block');

		// Hide the submit button while processing...
		$('submit').setStyle('display','none');

		// Set the options of the form's Request handler.
		// ("this" refers to the $('login') element).
		this.set('send', { onComplete: function(response) {
			$('ajax_loading').setStyle('display','none');

	if(response == 'OK')
			{              
			location.reload();
			}
			else
			{
			  $('response').set('html', response);
			  // Show the login button
			  $('submit').setStyle('display','block');
			}
		}});

		// Send the form.
		this.send();
	});
});
