var xmlhttp;

function showStates(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="GetStates.php";
url=url+"?q="+str;
xmlhttp.onreadystatechange=stateChangedCountries;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function showRetailers(state,country)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="GetRetailers.php";
url=url+"?q="+state+"&c="+country;
xmlhttp.onreadystatechange=stateChangedStates;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChangedCountries()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("txtStates").innerHTML=xmlhttp.responseText;
		if (document.getElementById("countries").options[document.getElementById("countries").selectedIndex].value=="International")
		{
			showRetailers("","International")
			document.getElementById("txtStates").innerHTML="";
		}else
		{
			var myselect=document.getElementById("states")
			try{
				myselect.add(new Option("Select a State or Province", "0"), myselect.options[0]) 
				myselect.options.selectedIndex=0;
			}catch(e)
			{ //in IE, try the below version instead of add()
				myselect.add(new Option("Select a State or Province", "0"), 0) 
				myselect.options.selectedIndex=0;
			}
			document.getElementById("txtRetailers").innerHTML="";
		}
	}
}

function stateChangedStates()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtRetailers").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
