
function showAutocompleteBox(aInput,dataUrl,inputString) {

	// clicking anywhere closes Tempsug box...
	$('body').click( function() {
		$('#Tempsug').remove();
	});

	// ...except when clicking in the box itself.
	$('#Tempsug').click(function(event){
	    event.stopPropagation();
	});
	
	if(inputString.length < 3) {
		
		$('#Tempsug').remove();
		
	} else {
		// alert(dataUrl + "&searchterm=" + inputString );
		$.post(
			dataUrl + "&searchterm=" + inputString, 
			function(data){
				// Output must contain clickable items, otherwise there are no matches 
				// and it must be hidden.
				if(data.length > 0 && data.indexOf('fill(')>-1) {
					// create a Tempsug div, if it's not already there
					if ($('#Tempsug').length == 0) $(aInput).after('<div id="Tempsug" style="position:absolute"></div>');
					$('#Tempsug').html(data);
				}
				else $('#Tempsug').remove();
			}
		);
	}
}

function fill(thisValue,oLi) {
	
	// move listed value to corresponding input
	var oDiv = $(oLi).parentsUntil('#Tempsug').parent();
	$(oDiv).prev('input').val(thisValue);
	$(oDiv).remove();
}


