function findValue(li) {
	if( li == null ) return alert("No match!");
  	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;

	$("#ZoekArtikelId").attr("value", li.extra);
	$("#laadLink").show();
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0] + " (id: " + row[1] + ")";
}

$(document).ready(function(){
	$("#ZoekArtikel").autocomplete(
		"get.artikel.asp?rId=" + Math.random(),
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			autoFill:true
		}
	);
	$("#loadingDiv").ajaxStart(function(){
		$(this).show();
	});
	$("#loadingDiv").ajaxStop(function(){
		$(this).hide();
	});
});
