$(document).ready(function()
{
	$("#signin").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/login/load.gif" alt="validando ..." style="margin-top: 5px;"/>').fadeIn(2000);
		//chqeueo de usuario
		$.post("mod/login.php",{ usuario:$('#usuario').val(),clave:$('#clave').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('<span style="color:#000;font-size:1.1em;"> Comprobando usuario ...</span>').addClass('messageboxok').fadeTo(900,1,
					function()
					{
						//redirecion
						//document.location='index.php';
						document.location.reload();
					});
				});
			} 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('').addClass('messageboxerror').fadeTo(900,1);
					$(this).html('<span style="color:#000;font-size:1.1em;"> Datos incorrectos! </span>').addClass('messageboxerror').fadeTo(900,1);
				});
			}
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from
	$("#clave").blur(function()
	{
		$("#signin").trigger('submit');
	});
});

