/*
Credits: Bit Repository
URL: http://www.bitrepository.com/web-programming/ajax/login-form.html
*/


// Preload Images
img1 = new Image(16, 16);  
img1.src="images/ajax-loader.gif";

img2 = new Image(220, 19);  
img2.src="images/ajax-loader.gif";

	window.addEvent('domready', function() {
			//							 alert("start domready ");
										 

	$('login').addEvent('submit', function(e) { 
										   
										   //alert("start submit ");
										   
		// 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');
//alert(response);
	if(response =='OK')
			{
	//			alert("start post ok ");
              $('status').set('html', '<div id="logged_in" align="center">Authentification R&eacute;ussie<br /><br /><br />' +
              '<img align="absmiddle" src="images/ajax-loader.gif"><br /><br />' +
              '<br />Veuillez patienter pendant l\'actualisation de la page...</div>');
				//go_to_private_page();
			setTimeout('go_to_private_page()', 3000);
			}
			else
			{
		//		alert("start not ok ");
			  $('login_response').set('html', response);
			  // Show the login button
			  $('submit').setStyle('display','block');
			}
		}});

		// Send the form.
		this.send();
	});
});

function go_to_private_page()
{
window.location = 'packs.php'; // Members Area
}

