
function trim(s)
	{
	  return s.replace(/^\s+|\s+$/,'');
	}
        
$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//alert('fsdfsfsd');
        //remove all the class add the messagebox classes and start fading
		$("#loginmsg").removeClass().addClass('messageboxvalid').html('<img align="absmiddle" src="Way2win/images/loader.gif" /> Validating.......').show().fadeTo(1900,1);;
		//check the username exists or not from ajax
		$.post("Way2win/ajax/ajax_login.php",{user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
           // alert('#'+data+'#');
		  if(trim(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='Way2win/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');
	});



	});
