$().ready(function() {

	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	$("#fromcity").autocomplete("searchcity.php", {
		width: 207,
		selectFirst: true
	});
	$("#fromcity").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
	});
	
	
	$("#cabin").change(function() { 
		var cabinval = $("#cabin option:selected").val();
		$("#tocity").val('');   
		
		$("#tocity").autocomplete("searchdest.php?cab="+cabinval, {
		width: 207,
		selectFirst: true
	});
	})
	var cabinval = $("#cabin option:selected").val();  
	
	
	
	$("#tocity").autocomplete("searchdest.php?cab="+cabinval, {
		width: 207,
		selectFirst: true
	});

	
	
	$("#clear").click(function() {
		$(":input").unautocomplete();
	});
});