﻿/**
* Provides suggestions for product names (USA).
* @class
* @scope public
*/
function SearchSuggestions() {
    this.products = [
    'Banana Cream',
'Blueberry Crumb Cake',
'Cherry Punch Cups',
'Chewy Chocolate Chip',
'Chocolate Deluxe',
'Chocolate Peanut Butter',
'Chocolate Peanut Caramel',
'Cookies',
'Creme',
'Cream',
'Cookies \'n Creme',
'Cookies N Creme',
'Cookies n\' Cream',
'Cookies N\' Creme',
'Country Blueberry Pie',
'Frosty Chocolate',
'Fruit Punch',
'Grape','Green Apple',
'Peanut Butter Caramel Surprise',
'Peanut Butter Cup',
'Peanut Marshmallow Eclipse',
'Protein Revolution',
'Rich Chocolate',
'S`Mores',
'Strawberry',
'Strawberry Cream',
'Strawberry Shortcake',
'Triple Chocolate Shake',
'Tropical Fruit Cups',
'Vanilla',
'Vanilla Cream',
'Vanilla Cream Shake',
'Vanilla Creme'
    ];
}

/**
* 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.toLowerCase();

    if (sTextboxValue.length > 0) {

        //search for matching products
        for (var i = 0; i < this.products.length; i++) {
            if (this.products[i].toLowerCase().indexOf(sTextboxValue) == 0) {
                aSuggestions.push(this.products[i]);
            }
        }
    }

    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
