var SITE_URL = 'http://www.magnet.co.uk/';

$(document).ready(function() {
	// We want to disable the submit button using JS
	// This way non JS users can still use the form
	$('#submit').attr('disabled', 'disabled');
	
	$('#postcode').blur(function() {
		var postcode = $(this).val();
		var status = $('#submit-status');
		status.text('Validating postcode');
		
		$.ajax({
			type: 'GET',
			url: SITE_URL+'ajax.php?action=validate_postcode&postcode='+postcode,
			success: function(response) {
				// We get a 1 for valid and 0 for invalid
				// So see what we got
				if(response == '1') {
					$('#submit').attr('disabled', '');
					status.text('');
				} else {
					status.text('Sorry, that postcode appears to be invalid, please try again');
				}
			}
		});
	});
});
