﻿AsyncSearchRefine = function()
{
    this.containers = [];
    this.containerIndex = 0;
    this.urlIndex = 0;
    
    this._onRequestCompleted$delegate = Function.createDelegate(this, this._onRequestCompleted);
}

AsyncSearchRefine.prototype = {
    refineSearch: function() {
        // valide les paramètres
        if (this.containerIndex >= this.containers.length)
            return;
        
        // requête
        var request =  new Sys.Net.WebRequest();
        request.set_url(this.containers[this.containerIndex].urls[this.urlIndex]);
        request.add_completed(this._onRequestCompleted$delegate);

        var executor = new Sys.Net.XMLHttpExecutor();
        request.set_executor(executor); 
        executor.executeRequest();
    },

    _onRequestCompleted: function(executor, e) {
        // met à jour la liste
        if(executor.get_responseAvailable())
        {
            var data = executor.get_responseData();
            if (data && 0 != data.length)
            { 
                this.containers[this.containerIndex].titleElement.style.display = "inline";
                this.containers[this.containerIndex].element.innerHTML += data;
            }
        }
        
        // suivant
        ++this.urlIndex;
        if (this.urlIndex == this.containers[this.containerIndex].urls.length) 
        {   
            ++this.containerIndex;
            this.urlIndex = 0;
        }
        if (theForm.__EVENTTARGET.value == "")
            window.setTimeout('window["RefineSearch"].refineSearch()', 50);
        else
            window.setTimeout('window["RefineSearch"].refineSearch()', 5000);
            
    }
}