$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		$("#msgbox").removeClass().addClass('messagebox').text('Autorizzo...').fadeIn(1000);
		$.post("require/login.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()
			{ 
			  $(this).html('Login effettuato').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 				 
			  });
			});
			$.ajax({
   type: "POST",
   url: "require/Top.php",
   data: "",
   success: function(msg){
   
		

		$("#top_content").html(msg);
   }
 });

 $("#alert").fadeOut('slow', function() {});


			
		  }
		  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('Errore').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});

