
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */
 
function StateSuggestions(q) {
	if(q.length > 1) this.q = q.substring(0, q.length-1);
else this.q = null;
this.states = new Array();
if(q) {
arr=this.q.split("&");
for(var i=0; i < arr.length; i++) {
	
this.states[i] = arr[i];
	}
	}
    
}

/*function citySuggestions(q) {
	if(q.length > 1) this.q = q.substring(1, q.length-1);
else this.q = null;
this.states = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.states[i] = this.q.split("&")[i];
	}
	}
    
}*/

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                          bTypeAhead /*:boolean*/) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    
    if (sTextboxValue.length > 0){
    
        //convert value in textbox to lowercase
        var sTextboxValueLC = sTextboxValue.toLowerCase();

        //search for matching states
        for (var i=0; i < this.states.length; i++) { 

            //convert state name to lowercase
            var sStateLC = this.states[i].toLowerCase();
           
            //compare the lowercase versions for case-insensitive comparison
            if (sStateLC.indexOf(sTextboxValueLC) == 0) {

                //add a suggestion using what's already in the textbox to begin it                
                aSuggestions.push(sTextboxValue + this.states[i].substring(sTextboxValue.length));
            } 
        }
    }

    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
