//WHITEHAT MOD************************************************************
var who_has_focus;
var producers = new Array();
var varieties = new Array();
var site_url = "http://www.cava-kazakos.gr/";

function formatItem(row) {
	if(who_has_focus == 'producer') {producers.push(row[0]);}
	if(who_has_focus == 'variety') {varieties.push(row[0]);}

	return row[0] + " (id: " + row[1] + ")";
}
function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;
	
	//alert(who_has_focus);
	$('#'+who_has_focus).val(sValue);
	//alert("The value you selected was: " + sValue);
}
function selectItem(li) {
	findValue(li);
}

function test(id){
	if(id == 'producer_name') who_has_focus = 'producer';
	if(id == 'variety_name') who_has_focus = 'variety';
}
	
$(document).ready(function() {
	var producer = $('#producer_name').val();
	var variety = $('#variety_name').val();
	if(producer) producers.push(producer);
	if(varieties) varieties.push(variety);
	
	$("#producer_name").autocomplete(
		site_url + "ecom/index.php",
		{
			delay:100,
			minChars:1,
			matchSubset:1,
			matchContains:1,
			maxItemsToShow: 50,
			cacheLength:10,
			extraParams: {ajax : 1,t : "producer"},
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:true
		}
	);
	
	$("#variety_name").autocomplete(
		site_url + "ecom/index.php",
		{
			delay:100,
			minChars:1,
			matchSubset:1,
			matchContains:1,
			maxItemsToShow: 10,
			cacheLength:10,
			extraParams: {ajax : 1,t : "variety"},
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:true
		}
	);
});
//WHITEHAT MOD************************************************************	
	
