// Autocomplete stuff.
YAHOO.example.RemoteCustomRequest = initAutoComplete();

function initAutoComplete()
{
	
   // Use an XHRDataSource 0
    var oDS0= new YAHOO.util.XHRDataSource("autoComplete.do");
    // Set the responseType
    oDS0.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
    // Define the schema of the JSON results
    oDS0.responseSchema = {
        resultsList : "ResultSet.Result",
        fields : ["ResultString"]//, "townPOIId"]
    };
    
    // Instantiate the AutoComplete 1
    var oAC0 = new YAHOO.widget.AutoComplete("searchString", "townSearchContainer", oDS0);
    // Throttle requests sent
    //oAC1.queryDelay = .5;
    // Require user to type at least 3 characters before triggering a query 
    oAC0.minQueryLength = 3; 
    // The webservice needs additional parameters
    oAC0.generateRequest = function(sQuery) 
    {
        return "?itemType=town&searchString=" + sQuery ;
    };
    
    oAC0.itemSelectEvent.subscribe(function(sType, aArgs) 
                                   { 
                                      var oMyAcInstance = aArgs[0]; // your AutoComplete instance 
                                      var elListItem = aArgs[1]; // the <li> element selected in the suggestion 
                                                               // container 
                                      var oData = aArgs[2]; // object literal of data for the result
                                      
                                      //var townPOIId = oData[1];
                                      //document.getElementById("townPOIId").value = townPOIId;
                                   }); 
    return {oDS0: oDS0,oAC0: oAC0};
}