// ajax_login.js v0.8
// copyright 2008
// Easy2play BV

$(document).ready(function() {
	
	// Authenticate user
	$("#login_form").submit(function() {
		$("#msgbox").removeClass().addClass('ajaxerror').html('<img src="img/loading_red_small.gif" width="15" height="15"> Validating...').fadeIn(1000);
		$.post("inc/functions/ajax_login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,
			function(data) {
			  if(data=='yes') {
			  	$("#msgbox").fadeTo(200,0.1,
			  	function() { 
			 			$("#loginbox").fadeTo(900,0.1,
			 			function() {
				 			$("#loginbox").load("tpl_menu_user.php").fadeTo(900,1,
				  			function(){ 
				  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				  			});	
						});
					});
					if(jQuery.browser.msie) $("#loginbox").style.removeAttribute('filter');
			  } else {
			  	$("#msgbox").fadeTo(200,0.1,
			  		function() { 
				  		$(this).html('Wrong email or password.').addClass('ajaxerror').fadeTo(900,1,
				  			function(){ 
				  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				  			});	
						});		
				}
			});
 		return false;
	});
	
});
