
/**
 * Provides suggestions for search
 * @class
 * @scope public
 */
function RemoteSearchSuggestions( category ) {

    if (typeof XMLHttpRequest != "undefined") {
        this.http = new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined") {
        this.http = new ActiveXObject("MSXML2.XmlHttp");
    } else {
        alert("No XMLHttpRequest object available. This functionality will not work.");
    }
    
    this.category = category;

}

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
RemoteSearchSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {

	var oHttp = this.http;
                                                             
    //if there is already a live request, cancel it
    if (oHttp.readyState != 0) {
        oHttp.abort();
    }                 
    
   //build the URL
    var sURL = "/searchHint?word=" + encodeURIComponent(oAutoSuggestControl.textbox.value) + "&category="+encodeURIComponent(this.category);
    
    //open connection to states.txt file
    oHttp.open("get", sURL , true);
    oHttp.onreadystatechange = function () {
        if (oHttp.readyState == 4) {
           //evaluate the returned text JavaScript (an array)
           var aSuggestions = oHttp.responseText.split(",");
 
           //provide suggestions to the control
           oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);        
            
        }    
    };
    oHttp.send(null);
    

};