$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//removemos todas las clases y aņadimos la claxe de messagebox para comenzar el fading
		$("#msgbox").removeClass().addClass('messagebox').html('<img src="img/load.gif" alt="validando ..." />').fadeIn(2000);
		//chqeueo de usuario
		$.post("mod/mod_acceso.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('accediendo ...').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirecion
				 document.location='index.php';
			  });
			  
			});
		  }
		  else 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<span style="color: #800000">Datos incorrectos </span>').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});
