$().ready(function(){
	$('#email').focus();
	$('#LoginForm').submit(function(){
		
		$("#error_email").html('');
		$("#error_password").html('');
		$("#error_hint").html('');
		//check email
		var email = $('#email').val();
		if(!$().isEmail(email))
		{
			$("#error_email").html('Please enter a valid email address.');
			$('#email').focus();
			return false;
		}

		//check password
		var password = $('#password').val();
		if($().isEmpty(password))
		{
			$("#error_password").html('Please enter your password.');
			$('#password').focus();
			return false;
		}

		var refer = $('#refer').val();
		var collect_data = {'email':email,'password':password,'refer':refer};
		$("#error_hint").html('Processing...');
		$.post('/login/login', collect_data, function(data)
		{
			
			var msg = data;
			
			switch(data)
			{
				case "SUCCESS":
					$("#error_hint").html('Login success.');
					setTimeout(location.href=refer,200);
				break;
				
				case "ERROR":
					msg = 'invalid user name or password.';
					$("#error_hint").html(msg);
				break;
			}
		});
		return false;
	})
})
