$(document).ready(function()
{
	$("#login_form").submit(function()
	{var getcurrentpagename = $('#currentpagename').val();
	
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').html('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax_login.php",{ user_name:$('#username').val(),password:$('#password').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('Logging in.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				  document.location='management/' + getcurrentpagename ;
			  });
			  
			});
		  }
		  if(data == 'no') //if correct login detail

		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{
			
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			var emailVal = $("#username").val();
			if(!emailReg.test(emailVal)) {	
				$(this).html('Your username is invalid...').addClass('messageboxerror').fadeTo(900,1);} else {		
			
			  	$(this).html('Your username is not registered...').addClass('messageboxerror').fadeTo(900,1);

			  	  }		
				   
			  //add message and change the class of the box and start fading
			});		
          }
				
		  if(data == 'passwordwrong') //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('Your password is invalid...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
								
				
				
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 

});
