$(document).ready(function()
{
	$("#login_form").submit(function()
	{
	        //remove all the class add the messagebox classes and start fading
	        $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	        //check the username exists or not from ajax
	        $.post("ajax_login.php",{user:$('#user').val(),password:$('#password').val()} ,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('Logging in.....').addClass('messageboxok').fadeTo(900,1,
	                  function()
	                  {
	                     //redirect to secure page
	                    document.location=$('#path').val() + "display.php?client=" + $('#client').val();
	                  });
	                });
	          }
	          else
	          {
	                $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
	                {
	                  //add message and change the class of the box and start fading
	                  if (data=='no') {
	                  	$(this).html('Invalid User or Password...').addClass('messageboxerror').fadeTo(900,1);
                  	  } else if (data=='inactive') {
	                  	$(this).html('User Not Active...').addClass('messageboxerror').fadeTo(900,1);
                  	  } else if (data=='invalid') {
	                  	$(this).html('Please Sign up for <?php echo $clientname; ?> for FREE...').addClass('messageboxerror').fadeTo(900,1);
                  	  } else if (data=='nodb') {
	                  	$(this).html("Sorry we're having technical issues, please try again soon...").addClass('messageboxerror').fadeTo(900,1);
                  	  }
	                });
	          }
	       });
	       return false;//not to post the  form physically
	});
});
