	$(document).ready(function() {
		$("form").submit(function() {
		var verified;
		// I've made the ajax syncronous to wait for the validation result!
		$("span").text("");
		
		$.ajax({
          url: 'hat_register_ajax.php',
		  async: false, 
          data: 'action=check_capture&capture=' + $("#capture").val(),
          dataType: 'json',
          type: 'post',
		  cache: false,
          success: function (j) {
			if (j.msg == "true") {
			//	$("span").text(j.msg).show();
				verified = 1;
				return true;
			}
			else {
				$("span").text("Please check you've correctly entered the verification characters and try again...").show();
				verified = 0;
				return false;
			}
          }
		  
        });
		
		if (verified==1) {
			//alert('I am true');
			return true;
		}
		else {
		//	alert('I am false');
			return false;
		}
		});
	});