
$(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/ajax-loader.gif"> Controleren....').fadeIn(1000);
		//check the username exists or not from ajax
		var rememberval = 0;
		if($("#rememberme").attr('checked')) rememberval = 1;
		$.post("auth.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random(), rememberme: rememberval} ,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('Inloggen.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 location.reload(true);
			  });
			  
			});
		  }
		  else if(data == 'activate'){
			$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('U dient uw account nog te activeren. Bekijk uw email.').addClass('messageboxerror').fadeTo(900,1);
			});	
		  }
		  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('Uw gegevens zijn onjuist...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	
	
	$("#logout_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').html('<img src="images/ajax-loader.gif"> Controleren....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("auth.php?logout=1",{} ,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('U wordt nu uitgelogd.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 location.reload(true);
			  });
			  
			});
		  }
		  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('U bent niet ingelogd...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});

});
