
/** Search functions block **/

function clear_search_input() {
	if ($('#SearchInput').val() == 'enter keyword') {
		$('#SearchInput').val('');
	}
}

function search_form_submit() {
	clear_search_input();
	location.href= '/store/search/word/'+escape(encodeURIComponent($('#SearchInput').val()));
}

function set_narrow_category() {
	$('#NarrowSearchCategory').val('');
	$("#NarrowSearchForm").find("input.SearchCategory").each(function(i) {
		if ($(this).attr('checked')) {
			$('#NarrowSearchCategory').val(
				$('#NarrowSearchCategory').val() + $(this).attr('id').replace('CategoryNarrowCheckbox', '') + ','
			);
		} 
	});
}

function set_narrow_price() {
	$('#NarrowSearchPrice').val('');
	$("#NarrowSearchForm").find("input.SearchPrice").each(function(i) {
		if ($(this).attr('checked')) {
			$('#NarrowSearchPrice').val(
				$('#NarrowSearchPrice').val() + $(this).attr('id').replace('PriceNarrowCheckbox', '') + ','
			);
		} 
	});
}

$(function(){
	$('ul#NarrowSearchGroup a.Unselected').hover(function(event){
		$(this).addClass('Selected');
	}, function(event){
		$(this).removeClass('Selected');
	});
});

/** Search suggest functions block **/

jQuery(function() {
	jQuery("#SearchInput").suggest(
		"/store/search/suggest/?ajax", {
			onSelect: function() {
				var re = /\w+\s-\s/;
				$("#SearchInput").val(
					$("#SearchInput").val().replace(
						new RegExp(re), 
						''
					)
				);
				search_form_submit();
			}
	});
});
