$(document).ready(function()
	{
		$("#login").submit(function()
		{
			// remove all the class add the messagebox classes and start fading
			$("#msgbox").removeClass().addClass('messagebox').text('Validating Login...').fadeIn(1000);
			// check the data exists or not from ajax
			$.post("/auth_user.php",{ username:$('#username').val(),password:$('#password').val() },function(data)
			{
			  if(data=='authorized') // if login authorized successfully
			  {
				$("#msgbox").fadeTo(200,0.1,function()  // start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('Login Authorized').addClass('messageboxok').fadeTo(900,1);
				  //setTimeout("window.location.reload()",2000);
				  setTimeout("location.href = 'http://www.oak.co.uk/online-support.php'",2000);
				});
			  }
			  else if(data=='user-invalid')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('That username does not exist!').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			  else if(data=='pw-invalid')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('That password is not correct!').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			  else if(data=='expired')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('Maintenance has expired, call 0845 1362 625').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			  else if(data=='no-information')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('Please enter a Username and Password!').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			  else if(data=='no-username')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('Please enter a Username!').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			  else if(data=='no-password')
			  {
				$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				  //add message and change the class of the box and start fading
				  $(this).html('Please enter a Password!').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
			});
			return false; // not to post the form physically
		});
	});
