/*
 * Funzioni per caricare il motore di ricerca veloce
 */

function load_autocomplete()
{
YAHOO.example.ACFlatData = new function(){
    // Define a custom formatter function
    this.fnCustomFormatter = function(oResultItem, sQuery) {
        var sKey = oResultItem[0];
        var nQuantity = oResultItem[1];
        var sKeyQuery = sKey.substr(0, sQuery.length);
        var sKeyRemainder = sKey.substr(sQuery.length);
        var aMarkup = ["<div class='sample-result'><div class='sample-quantity'>",
            nQuantity,
            "</div><span class='sample-query'>",
            sKeyQuery,
            "</span>",
            sKeyRemainder,
            "</div>"];
        return (aMarkup.join(""));
    };

    // Instantiate one XHR DataSource and define schema as an array:
    //     ["Record Delimiter",
    //     "Field Delimiter"]
    this.oACDS = new YAHOO.widget.DS_XHR("/motore_ric_txt.php", ["\n", "\t"]);
    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
    this.oACDS.maxCacheEntries = 60;
    this.oACDS.queryMatchSubset = true;

    // Instantiate first AutoComplete
    var myInput = document.getElementById('ysearchinput0');
    var myContainer = document.getElementById('ysearchcontainer0');
    this.oAutoComp0 = new YAHOO.widget.AutoComplete(myInput,myContainer,this.oACDS);
    this.oAutoComp0.delimChar = "";
    this.oAutoComp0.queryDelay = 0.3;
    this.oAutoComp0.formatResult = this.fnCustomFormatter;
	this.oAutoComp0.animHoriz = true;
	this.oAutoComp0.animSpeed = 0.3; 
	this.oAutoComp0.maxResultsDisplayed = 10;
	this.oAutoComp0.minQueryLength = 2;
	this.oAutoComp0.useShadow = true; 
	this.oAutoComp0.forceSelection = true;
	this.oAutoComp0.allowBrowserAutocomplete = false; 
	this.oAutoComp0.typeAhead = true; 
	

};


  var oPushButton4 = new YAHOO.widget.Button("pushbutton4"); 
  var oPushButton5 = new YAHOO.widget.Button("pushbutton5"); 




}


// Instantiate and configure Loader:
var loader = new YAHOO.util.YUILoader({

    // Identify the components you want to load.  Loader will automatically identify
    // any additional dependencies required for the specified components.
    require: ["autocomplete", "button"],
	
	base: '/js_yahoo/',

    // Configure loader to pull in optional dependencies.  For example, animation
    // is an optional dependency for slider.
    loadOptional: true,

    // The function to call when all script/css resources have been loaded
    onSuccess: function() {
		load_autocomplete();		
    }
});

// Load the files using the insert() method. The insert method takes an optional
// configuration object, and in this case we have configured everything in
// the constructor, so we don't need to pass anything to insert().
loader.insert();
