
//  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()
{
 $("#msgbox").hide();
	$("#autenticacaodemembro").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#autenticacaodemembro").hide("slow");
		$("#msgbox").addClass('messagebox').text('Validando....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax_login.php",{ logout:$('#logout').val(),membro:$('#membro').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
	$("div.msgbox").show("slow");
		if(data=='logout') //if correct login detail
		  {
			  document.location='index.php';
		  }
			  
		  if(data=='Login Aceite') //if correct login detail
		  {
		  $("#msgbox").addClass('messageboxok').fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Dados aceites.....').addClass('formulariologin').fadeTo(2000,1,
              function()
			  { 
			  			   	 //redirect to secure 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(data).addClass('messageboxerror').fadeTo(3000,1,function(){
			   $("#msgbox").hide();
			  $("#autenticacaodemembro").show("slow");
			  });
			 
			/*$("#msgbox").hide("slow");*/
			});		
				
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	/*$("#password").blur(function()
	{
		$("#autenticacaodemembro").trigger('submit');
	});*/
});
