$(document).ready(function(){
	$("#loginFrm").submit(function(){
		var user_name = $('#username').val();
		var password = $('#password').val();
		user_name = $.trim(user_name);
		password = $.trim(password);
		if ((user_name == '') || (password == '')){
			$("#msgbox").removeClass().addClass('messageboxerror').text('username/password are required!').fadeIn(1000);
			return false;
		}
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('authenticating...').fadeIn(1000);

		//check the username exists or not from ajax
		$.post(ajaxSiteUrl+"admin/ajaxLogin.php",{
			user_name:$('#username').val(),password:hex_md5($('#password').val()),rand:Math.random()
				},
		function(data){
		  if(data=='yes') {
				$("#msgbox").fadeTo(200,0.1,function() {
				  //add message and change the class of the box and start fading
				  $(this).html('User verified! Logging in...').addClass('messageboxok').fadeTo(900,1,
				  function(){
					 //redirect to index page
					 document.location='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('Invalid login credentials!').addClass('messageboxerror').fadeTo(900,1);
				});
		  }
	   });
	   return false;//not to post the  form physically
	});
});

//now call the ajax also focus move from
	/*$("#password").blur(function()
	{
		$("#loginFrm").trigger('submit');
	});*/



