// JavaScript Document
jQuery(document).ready(function()
{
//SETTINGS 
$.nyroModalSettings(
	{
	debug: false
	}),
//Formulaire de login
$("#signupform").validate({
	rules :
		{
			password: {
				required: true
				},
			username: {
				required: true
				}
		},
	messages :
		{
			password: {
				required: "Code incorrect"
				},
			username: {
				required: "Login incorrect"
			}				
		},
	
   submitHandler: function(){
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Authentification ...').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("session/check_login.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } , function(data)
        {
	  if(eval(data)==true) //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('Connection ...').addClass('messageboxok').fadeTo(900,1,
                  function()
		  {
  	  	     //redirect to secure page
		     document.location='intranet.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('Acc&egrave;s refus&eacute;...').addClass('messageboxerror').fadeTo(900,1);
		  //$("#msgbox").removeClass();
		  });
        }
       });
       return false;//not to post the  form physically
	   }
});


});