
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */
function StateSuggestions() {
    this.states = [ ];
}

/**
 * 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*/,
                                                          pCountry /*:Country*/,
                                                          pState /*:State*/,
                                                          pURLFolder/*:Folder*/) {
    
    var sTextboxValue = oAutoSuggestControl.textbox.value;
    var sCountry = document.getElementById(pCountry).value;
    var sState = document.getElementById(pState).value;
    
	if (sTextboxValue.length > 1)
	{
    	xmlhttp=null;

		if (window.XMLHttpRequest)
		{// code for Firefox, Opera, IE7, etc.
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp!=null)
		{
			switch(pURLFolder)
			{
				case 1:
					URL = "adminclude/ajaxvalidation.asp?for=Suggestions&z=" + sTextboxValue + "&s="+ sState +"&c="+sCountry;
					break;    
				case 2:
					URL = "../admin/adminclude/ajaxvalidation.asp?for=Suggestions&z=" + sTextboxValue + "&s="+ sState +"&c="+sCountry;
					break;
				default:
					URL	= "";
					break;
			}
			xmlhttp.onreadystatechange=function(){ state_Change_Suggestions(sTextboxValue,oAutoSuggestControl,bTypeAhead); };
			xmlhttp.open("POST",URL);
			xmlhttp.send();
		}
		else
		{
			alert("Your browser does not support XMLHTTP.");
		}
	}
};

function state_Change_Suggestions(pval,p1,p2)
{
	if (xmlhttp.readyState==4)
	{
		if (xmlhttp.status==200)
		{
			//if(xmlhttp.responseText != "")
			//{
				var aSuggestions = [];
				var zip = xmlhttp.responseText 
				var zipArray = zip.split(",")
				if (pval.length > 0)
				{
					for (var i=0; i < zipArray.length; i++) 
					{ 
						if (zipArray[i].toUpperCase().indexOf(pval.toUpperCase()) == 0) 
						{
						    aSuggestions.push(zipArray[i]);
						} 
					}
				}
				p1.autosuggest(aSuggestions, p2);
			//}
		}
		else
		{
			alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
}
