﻿(function ($) {

$(document).ready(function(){
	function liFormat (row, i, num) {
		var result = row[0];
		return result;
	}
	function selectItem(li) {
		if( li == null ) { var sValue = 'Ничего не выбрано!'; $("#searchtip").focus(); }
		if( !!li.extra ) { var sValue = li.extra[2]; $("#searchtip").focus(); }
		else var sValue = li.selectValue; $("#searchtip").focus();
	}
	$("#searchtip").autocomplete("/search/autocomplete/", {
		delay:300,
		width: 278,
		minChars:2,
		matchSubset:1,
		autoFill:false,
		matchContains:1,
		cacheLength:10,
		selectFirst:false,
		formatItem:liFormat,
		maxItemsToShow:15,
		onItemSelect:function(){jQuery('form.search').submit();}
	});
	$("#searchtip").attr("value", "Поиск по товарам");
	var text = "Поиск по товарам";
	$("#searchtip").focus(function() {
		$(this).addClass("active");
		if (($(this).attr("value") == text) || ($(this).attr("value") == "Введите поисковый запрос в эту форму")) {
			$(this).attr("value", "").css('color','black');
		}
	});
	$("#searchtip").blur(function() {
		$(this).removeClass("active");
		if($(this).attr("value") == "") $(this).attr("value", text);
	});
});

})(jQuery);  
