jQuery(document).ready(function(){
	function liFormat (row, i, num) {
		var result = row[0];
		if(row[2]) result = result + '<p class="qnt"><img src="/files/team/' + row[2] + '" width="14" /></p>';
		return result;
	}
	function selectItemLeft(li) {
		if( li == null ) alert('Выберите команду1!');
		else if( !!li.extra ) jQuery('#team1').attr('value',li.extra[0]);
		else alert('Ошибка при выборе команды1!');
	}
	function selectItemRight(li) {
		if( li == null ) alert('Выберите команду2!');
		else if( !!li.extra ) jQuery('#team2').attr('value',li.extra[0]);
		else alert('Ошибка при выборе команды2!');
	}
	jQuery("#t2t1").autocomplete("/xml/teamslist.php", {
		delay:10,
		minChars:2,
		matchSubset:1,
		autoFill:true,
		matchContains:2,
		cacheLength:10,
		selectFirst:true,
		formatItem:liFormat,
		maxItemsToShow:12,
		onItemSelect:selectItemLeft
	});
	jQuery("#t2t2").autocomplete("/xml/teamslist.php", {
		delay:10,
		minChars:2,
		matchSubset:1,
		autoFill:true,
		matchContains:2,
		cacheLength:10,
		selectFirst:true,
		formatItem:liFormat,
		maxItemsToShow:12,
		onItemSelect:selectItemRight
	});
});
