$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Authentification....').fadeIn(2000);
		//check the username exists or not from ajax
		$.post("views/rep/ajax/ajax_login.php",{ user_name:$('#user_name').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Opening .....').addClass('messageboxok').fadeTo(2500,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='index.php?rt=intra/intra';
			  });
			  
			});
		  }
		  
		else if(data=='yess') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Account not actif ').addClass('messageboxerror').fadeTo(2500,1,
              function()
			  { 
			  });
			  
			});
		  }
		  
		 else if(data=='yess') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Opening .....').addClass('messageboxok').fadeTo(2500,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='index.php?rt=intra/intra';
			  });
			  
			});
		  }
		  
		  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('Incorrect Informations !!').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
});

