if(typeof ultimania=="undefined"){var ultimania={'trac':{}};}

function split( val ) {
    return val.split( /,\s*/ );
}
function extractLast( term ) {
    return split( term ).pop();
}

ultimania.trac.setAutoComplete = function(id, url, multi){
    if(multi){
	$( "#"+id ).autocomplete({
		source: url,
		minLength: 2,
                delay:100,
                multiple: true,
                multipleSeparator: ",",
                focus: function(){ return false; },
		select: function( event, ui ) {
	                var terms = split(this.value);
			terms.pop();
			terms.push( ui.item.value );
			terms.push( "" );
			this.value = terms.join( ", " );
			return false;
		}
	});
    } else {
	$( "#"+id ).autocomplete({
		source: url,
		minLength: 2,
                delay:100
	});
    }
}
