function findValue(li) 
{
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the Id as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, use the text as the value
	else var sValue = li.selectValue;
}

function search(searchField, searchUrl, idField)
{	
	$("#"+searchField).autocomplete(searchUrl,
	{
		delay:10,
		minChars:2,
		matchSubset:10,
		onItemSelect:function selectItem(li) 
		{
			findValue(li);
			// set the id value based on the ajax call and selected item
			// some searches may not need an id result back so check if field name was passed
			if (typeof(idField) != "undefined")
			{
				if (idField != "")
				{
					document.getElementById(idField).value = li.extra[0];
				}
			}
		},
		onFindValue:findValue,
		maxItemsToShow:5,
		autoFill:false
	});
}