function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

	//alert("The value you selected was: " + sValue);
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	//return row[0] + " (id: " + row[1] + ")";
	return row[0];
}


function lookupAjax(){
	var oSuggest = $("input.ajax")[0].autocompleter;

	oSuggest.findValue();

	return false;
}

$(document).ready(function() {
	$("input.ajax").autocomplete(
		"autocomplete_ajax.php",
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:false,
			maxItemsToShow:10
		}
	);
});


function lookupAjax_ground(){
	var oSuggest = $("input.ajax_ground")[0].autocompleter;

	oSuggest.findValue();

	return false;
}

$(document).ready(function() {
	$("input.ajax_ground").autocomplete(
		"autocomplete_ajax_ground.php",
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:false,
			maxItemsToShow:10
		}
	);
});


function formValidator(){
	// Make quick references to our fields
	var destination0 = document.getElementById('destination0');
	var passengers = document.getElementById('passengers');
	var air = document.getElementById('air');

	// Check each input in the order that it appears in the form!
	if (((air.checked && isAlphabet(destination0, "Please enter where are you coming from.")) || !air.checked) && isNumeric(passengers, "Please enter number of travellers.")) return true;

	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;

	if (elem.value.match(numericExpression)) return true;
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /[A-Z]*, [A-Z]*/;

	if (elem.value.match(alphaExp)) return true;
	//if (elem.value.length > 3) return true;
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}