$(document).ready(function() {
// --- Автозаполнение ---
	function liFormat(row, i, num, numword) {
// changed by nIxOiD
		//var result = row[0] + '<p class=qnt>' + row[1];
		var strongstring = row[0].substr(0, numword);
		var nonstrongstring = row[0].substr(numword);
		var result = '<strong>' + strongstring + '</strong>' + nonstrongstring + '<p class=qnt>' + row[1];
// end changed
		return result;
	}


	function selectItem(li) {
		if (li == null) {
	//А ничего не выбрано!
		} else {
			if (!!li.extra) {
				var sValue = li.extra[2];
				var sCity = li.extra[1];
			} else {
				var sValue = li.selectValue;
			}
			var pos = sValue.indexOf('#')
			_('horse21Form', 'Country').value = sValue.substring(0, pos);
			_('horse21Form', 'CountryCode').value = sValue.substring(pos+1);
			_('horse21Form', 'CityEng').value = sCity;
		}
		//_('horse21Form','Country').value =
		//alert("Выбрана запись с ID: " + sValue);
		_('horse21Form', 'submitSearch').focus();
	}

	// --- Автозаполнение2 ---
	$("#example").autocomplete("autocomplete.php", {
		delay:s_delay,
		minChars:s_minChars,
		matchSubset:s_matchSubset,
		autoFill:s_autoFill,
		matchContains:s_matchContains,
		cacheLength:s_cacheLength,
		selectFirst:s_selectFirst,
		formatItem:liFormat,
		maxItemsToShow:s_maxItemsToShow,
		onItemSelect:selectItem
	});
// --- Автозаполнение2 ---
});



function changeCity(e) {
	var code = e.which||e.keyCode;
	if ((code != 27)&&(code != 13)&&(code != 9)&&(code != 20)) {
		_('horse21Form', 'CountryCode').value = '';
		_('horse21Form', 'Country').value = '';
		_('horse21Form', 'CityEng').value = '';
	}
}

