$(function() {
		   
//autocomplete init		   
$( "#xcode" ).autocomplete({
minLength: 2, 						   
source: availabletags,
autoFocus: true,
change: function(){
$("#search_results_caption").html('<img src="_images/ajax-loader.gif" width="16" height="16" alt="loading" /> Updating results...');
var sendstr = "ajax=true&xterms=";
sendstr += $("#xterms").val();
sendstr += "&xcode=";
sendstr += $("#xcode").val();
sendstr += "&xmiles=";
sendstr += $("#xmiles").val();
//
$.ajax({
type: "POST",
url: "ajax/returncount.php",
data: sendstr,
success: function(html){
$("#search_results_caption").html(html);
//is postcode naughty???
if(html.indexOf('<!-- POSTCODE ERROR -->') != -1){
var errormsg = "Sorry '" + $("#xcode").val() + "' is not a postcode we recognise";
alert(errormsg);
$("#xcode").val("");
$("#xmiles").val("0");
}
}
});
}
});

$('#xterms,#xmiles').change(function() {
$("#search_results_caption").html('<img src="_images/ajax-loader.gif" width="16" height="16" alt="loading" /> Updating results...');
var sendstr = "ajax=true&xterms=";
sendstr += $("#xterms").val();
sendstr += "&xcode=";
sendstr += $("#xcode").val();
sendstr += "&xmiles=";
sendstr += $("#xmiles").val();
//
$.ajax({
type: "POST",
url: "ajax/returncount.php",
data: sendstr,
success: function(html){
$("#search_results_caption").html(html);
//is postcode naughty???
if(html.indexOf('<!-- POSTCODE ERROR -->') != -1){
var errormsg = "Sorry '" + $("#xcode").val() + "' is not a postcode we recognise";
alert(errormsg);
$("#xcode").val("");
$("#xmiles").val("0");
}
}
});
});



});//end load function


