
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */

var flagtest=0;
var inittimer=0;
var dummyresult=[];
function StateSuggestions() 
{

	    var searchvalue="";
        var type= document.getElementById('drpSearch').value;		
	
	    this.SearchResults=[];
		InitAutoCompleteList(type); 
		inittimer=setTimeout("callinit()",1000);		
}

function callinit()
{
	if(flagtest==1)
	{
		clearTimeout(inittimer);		
		/**
 * 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;
    var sDropdownValue = oAutoSuggestControl.dropdown.value;
	
    if (sTextboxValue.length > 0)
	{
    
        //search for matching states
				
		this.SearchResults=dummyresult;
        for (var i=0; i < this.SearchResults.length; i++)
		{ 
        	if (this.SearchResults[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) == 0) 	
			{ 
                aSuggestions.push(this.SearchResults[i].toLowerCase());
            } 
        }
    }

    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
	}
	else
	{
		inittimer=setTimeout("callinit()",1000);
	}
}


/* Auto Complete ---------------------*/
function InitAutoCompleteList(type) 
{	
	if (window.XMLHttpRequest) {
		
			// branch for IE/Windows ActiveX version
			AJAXForms = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");
		}		
		AJAXForms.onreadystatechange = AutoCompleteListProcessChange;		
		AJAXForms.open("Get", "library/sellerautocomplete.php?op=ajax&queryString=" + type);
		AJAXForms.send(null);	
}

function AutoCompleteListProcessChange() {
  if (AJAXForms.readyState == 4) 
  {    	  
	if(AJAXForms.responseText.length >0) 
	{				
		var splittxt=AJAXForms.responseText.split(',');
		dummyresult = [ splittxt.length ];
		for(i=0;i<splittxt.length;i++)
		{			
			dummyresult[i]=splittxt[i];
		}
		flagtest=1;	
		
	}
  }
}
