
$(document).ready(function()
{  
	$("#frmLogin").submit(function()
	//$('#imgLogin').click(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox_index").removeClass().addClass('messagebox_index').text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		
		$.post("WEB/ajax_login.php",{ user_name:$('#txtUserName').val(), pass:$('#txtPwd').val(), rand:Math.random() } ,function(data)
        {
		  //alert(data);
		  if(data=='yes') //if correct login detail
		  {
		      $("#msgbox_index").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='index.php';
			  });
			  
			});
		  }
		  else
		  if(data=='nunActived')
		  {
			  //alert("no tra ve no ne pa cok");
			  $("#msgbox_index").fadeTo(200,0.1,function() //start fading the messagebox
			  { 
				 //add message and change the class of the box and start fading
				 $(this).html('Chưa kích hoạt tài khoản...').addClass('messageboxerror_index').fadeTo(900,1);
			  });	
		  }
		  else 
		  {
			  //alert("no tra ve no ne pa cok");
		  	$("#msgbox_index").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
		  		$('#txtPwd').val(" ");
			  //add message and change the class of the box and start fading
			  $(this).html('Thông tin sai...').addClass('messageboxerror_index').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	
});
