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[1];

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

	window.location = "http://www.ridecount.com/browse/user/" + sValue;
}

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

function formatItem(row) {
	return "<strong>"+ row[0] + "</strong>  (" + row[1] + ")";
}

function lookupUser(){
	var oSuggest = $("#userAjax")[0].autocompleter;

	oSuggest.findValue();

	return false;
}


$(document).ready(function() {
	$("#userAjax").autocomplete(
		"/misc/ajax_getusers.php",
		{
			delay:10,
			minChars:1,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:true,
			extraParams: {"time": "<?php echo time(); ?>"}
		}
	);
});
