
/**
 * Provides suggestions for state names (IND).
 * @class
 * @scope public
 */
var sts= new Array();
var oTextbox;
function StateSuggestions(){
	//  document.getElementById("txt1").value = "";
	//  document.getElementById("div_suggest").innerHTML = "";
	 
	  this.states = sts;
}//statesuggestions

function showWaiting(){
	 document.getElementById("txt1").innerHTML = "<img src='http://hotels.rediff.com/images/loader.gif' />Loding Cities.....";
}//showwaiting

function StateSuggestionsAjax() {
	var url ="http://hotels.rediff.com/suggest/suggestion.php";
	var x = new RemoteProcedure(url, showCities,'');
	var dbvalue;
	function showCities(xhrObj){
		var tempStr = xhrObj.responseText;
		var arr = tempStr.split(",");
		for(i=0; i<arr.length; i++ ){
				sts[i] =  trim(arr[i]);
		}//for
		//document.getElementById("div_suggest").innerHTML =
		oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new StateSuggestions()); 
		return false;
	}//inner fucntion
	return false;
}//statesuggestionsAjax


function trim(str) {
	var stri
	var re = /\s*((\S+\s*)*)/;
	return str.replace(re, "$1");
}//trimfunction

/**
 * 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 cnt=0;
    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) {
				cnt=cnt+1;
                //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);
};

