//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').html('<img src=/images/spinner.gif />&nbsp;<em>Processing...</em>').fadeIn(2000);
		//check the username exists or not from ajax
		$.post("login.php",{ username:$('#username').val(),userpass:$('#userpass').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') {
		  	
			$("#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='/admin/members/safari_leader/index.php';
			  });
			  
			});
		  
		  
		  //}else if (data=='noleader') {
		  
		 // $("#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='basic_member/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('Sorry we could not find this member, try again!').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#userpass").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});