﻿
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */
 
function makeObject(){
var x;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
x = new ActiveXObject("Microsoft.XMLHTTP");
}else{
x = new XMLHttpRequest();
}
return x;
}

var request = makeObject();

function StateSuggestions() {
    this.states = [
"bar stool",
"bed",
"bench",
"cabinet",
"chaise",
"coffee table",
"console",
"custom",
"desk",
"dinning chair",
"dining table",
"dresser",
"end table",
"etagere",
"floor lamp",
"lounge chair",
"mirror",
"nightstand",
"ottoman",
"server",
"sofa",
"stool",
"table lamp",
"wall lamp"
    ];
}

StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
  
    if (sTextboxValue.length > 0){    
        //search for matching states
        for (var i=0; i < this.states.length; i++) { 
            if (this.states[i].indexOf(sTextboxValue.toLowerCase()) == 0) {
                aSuggestions.push(this.states[i]);
            } 
        }
    }

    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};