var onPostcodeChange = function () {
	var prefix = '#';
	if ($(this).attr('rel') != undefined && $(this).attr('rel').length > 0) {
		prefix += $(this).attr('rel') + '_';
	}

	$.ajax({
		url: '/config/xml.php?method=get_postcode_locations'+"&"+'country_id='+$(prefix + 'country_id').val()+"&"+'param='+$(prefix + 'post_code').val(),
		processData: false,
		dataType: "html",
		success: function(html){
			if (html.length > 0) {
				if (html.match(/Not Applicable/)) {
					$('.select_location').fadeOut();
				} else {
					$(prefix + 'location_id').html(html).fadeIn();
					$('.select_location').fadeIn();
				}
			}
		}
	});
};

$(document).ready(function(){
	$('.postcode').change(onPostcodeChange);
	$('.country').change(onPostcodeChange);
	$('#location-select').show();
	$('.country-submit').change(function () {

		var elem = $(this).parents('form:first');
		var rel = $(this).attr('rel');
		if (rel != undefined)
		{
			$(elem).append('<input type="hidden" name="' + rel + '" value="1" />');
		}
		$(elem).submit();
	})
	$('.no-js').hide();
	// Set the option to checked whenever one of the suboptions is focused
	$('#side_radius, #side_postcode, #side_location_id').focus(function () {
		$('#side_search_type_radius').attr('checked', true);
	});
	// Set the option to checked whenever one of the suboptions is focused
	$('#side_hybrid_id').focus(function () {
		$('#side_search_type_area').attr('checked', true);
	});
});



