jQuery(function($) {
	$("#home_zip").keydown(function(e){
	        if (e.keyCode == 13) {
	            geoLocateUser();
				return false;
	        }
	    });
});

function geoLocateUser() {
	var geo_ajax_url = src_dir + 'ajax/geo_locate_user.php';
	var home_zip = $("#home_zip").val();

	if (home_zip.match(/\d+/) && home_zip.length == 5) {
		$("#modalBody").hide(); // this belongs to callme widget
		$("#modalBodyProcessing").show(); // this is the animated icon
		revealModal('modalPage');
		
		var payload = {};
		payload.zip = home_zip;
		$.post(geo_ajax_url, payload, showGeoResult, "text");
	} else {
		alert('Please enter a 5 digit zip code!');
		return false;
	}
}

function showGeoResult(data, textStatus) {
	if (textStatus == 'success') {
		document.geo_form.action = data;
		//alert(data);
	} else {
		alert("Hm, must not be connected to the Internet!");
		hideModal('modalPage');		
		return false;
	}
	document.geo_form.submit();
}
