$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Login in progress....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("http://www.weissenegger.name/ajax_login.php",{ m:$('#email').val(),p:$('#pass').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='05') 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Redirect in progress.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 window.location.reload();
			  });
			  
			});
		  }
		   else if(data=='00') // eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Fill in email and password').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='01') // eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Currently the system does not login').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='02') // ok dar eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() 
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Please confirm your email address (check email).').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  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('Cannot login.').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#pass").blur(function()
	{
		$("#login_form").trigger('submit');
	});
	
});