$(document).ready(function()
{
	$("#login_form").submit(function()
	{

	
		//remove all the class add the messagebox classes and start fading
		$("#loginmsg").removeClass().addClass('messagebox').text('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
		  {
		  	$("#loginmsg").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....').removeClass().addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='mlm_index.php';
			  });
			  
			});
		  }
		  else if(data=='no')
		  {
		  	$("#loginmsg").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Incorrect User Name or Password...').removeClass().addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
				
		else
		  {
		  	$("#loginmsg").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Check database connectivity...').removeClass().addClass('messageboxerror').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('submit');
	});

	$("#submit").click(function()
	{
	
	//alert('submmit');
		$("#login_form").trigger('submit');
	});
	
		$("#username").blur(function()
	{
		document.login_form.password.focus();
		console.log('niju');
	});

	
	
	});