function autocomplete(field, idField, data, params, resultFunction)
{
	$(field).unbind('focus');
	
	$(field).autocomplete(
		data,
		{
			extraParams:params,
			cacheLength:0,
			selectFirst:false
		}
	);
	
	//Clean up the vals if we're entering a different item.
	$(field).change(function()
	{
		idField.val('');
	});

	$(field).result(function(event, data, formatted)
	{	
		var textValue = data[0].replace(/\&amp;/g,'&');
		textValue = textValue.replace(/\&apos;/g, '\'');
		textValue = textValue.replace(/\&quot;/g, '"');
		if(typeof data[1] != 'undefined' && data[1].length > 0){
			idField.val(data[1]);
			$(field).attr('value', textValue);
			if(typeof resultFunction != 'undefined')
				resultFunction(data, idField);
		}else{
			idField.val('');
			$(field).attr('value', '');
		}
	});	
}
