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

ultimania.trac.setAutoComplete = function(id, url, multi){
    var container = "__"+id;
    $("#"+id).after('<div id="'+container+'"></div>');

    oACDS = new YAHOO.widget.DS_XHR(url, ["UserList","Id"]);
    oACDS.maxCacheEntries = 10;
    oACDS.queryMatchSubset = true;
    oACDS.queryMatchContains = true;
    oAutoComp = new YAHOO.widget.AutoComplete(id,container, oACDS);
    if(multi==true){
       oAutoComp.delimChar = ",";
    }
    oAutoComp.alwaysShowContainer = false;
    oAutoComp.minQueryLength = 2;
    oAutoComp.queryDelay = ultimania.trac.POPUP_DELAY;
    oAutoComp.maxResultsDisplayed = 30;
    oAutoComp.prehighlightClassName = "yui-ac-prehighlight";
    oAutoComp.typeAhead = true;
    oAutoComp.useShadow = true;
    oAutoComp.animSpeed = 0.1;

    oAutoComp.formatResult = function(oResultItem, sQuery) {
        return oResultItem[1].Id + " &lt;" + oResultItem[1].Name + "&gt;";
    };
/*
    oAutoComp.dataReturnEvent.subscribe(
        function(sType, aArgs) {
            var oAutoComp = aArgs[0];
            var sQuery = aArgs[1];
            var aResults = aArgs[2];
            if(aResults.length == 0) {
                oAutoComp.setBody("<div id=\"statescontainerdefault\">No matching results</div>");
            }
         } 
     );
*/
}
