$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messageboxlogin').text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax/ajax_login.php",{ username:$('#username').val(),password:$('#password').val(),remember:$('#remember').val() } ,function(data)
        {
		  if(data=='address') //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('Logging in...').addClass('messageboxloginok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='member/create_address.php';
			  });
			  
			});
		  }
		  else if(data=='member') //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('Logging in...').addClass('messageboxloginok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='member/index.php';
			  });
			  
			});
		  }
		  else if(data=='admin') //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('Logging in...').addClass('messageboxloginok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='admin/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('Check your login details...').addClass('messageboxloginerror').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('login');
	});
});

