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