/*
** search suggestions class
**/
function SearchSuggestions()
{
}

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
SearchSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    //var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    var sSearchType= oAutoSuggestControl.searchtype.value;

    // I don't want type ahead
    bTypeAhead = false;
    
    if (sTextboxValue.length > 0){
         //var aSuggestions = [];
         //oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
         //consider, setting a timer to clear current suggestions
                
         $.ajax({url: "/cb/SearchSuggestions.ashx" ,
            cache: false, 
            data: {phrase:[ sTextboxValue ], type:[sSearchType] },
            dataType: "text",
            success: function(result){
                var aSuggestions = [];
                if ( oAutoSuggestControl.textbox.value == sTextboxValue )
                {
                    if ( result.length > 2 )
                    {
                        aSuggestions = result.split( "\n" );   
                    }
                    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);  
                }     
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                var aSuggestions = [];
                oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
            }
          });      
    }
    else
    {
        var aSuggestions = [];
        //provide suggestions to the control
        oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
    }
};