$(document).ready(function() {

    $("#txtSearch").autocomplete({
	 source: function(request, response) {
	     $.ajax({
		  url: apiDomain + "regions/autocomplete/" + apiKey + ".json",
		  dataType: "jsonp",
		  data: {
		      featureClass: "P",
		      style: "full",
		      maxRows: 20,
		      term: request.term
		  },
		  success: function(data) {
		      response($.map(data, function(item) {
			   return {
				label: item.label,
				id: item.id,
				value: item.value
			   }
		      }));
		  }
	     });
	 },
	 minLength: 2,
	 autoFocus: true,
	 select: function(event, ui) {
	     $('#i').val(ui.item.id);
	     $('#t').val(false);
	     $('#frmSearch').submit();
	 }
    });

    $('#btnSearchNear').click(function() {
	 $('#t').val(true);
	 $('form#frmSearch').submit();
    })
});