

function getCountriesAndStates(url)
{
	var theHttpRequest = getNewHttpObject();

	if (theHttpRequest.overrideMimeType)
	{
		theHttpRequest.overrideMimeType('text/xml');
	}

	theHttpRequest.onreadystatechange = function()
	{
		if (theHttpRequest.readyState == 4 && theHttpRequest.status == 200)
		{
			var countries = theHttpRequest.responseXML.getElementsByTagName("countries")[0].getElementsByTagName("item");
			var states = theHttpRequest.responseXML.getElementsByTagName("states")[0].getElementsByTagName("item");

			for (var i = 0; i < countries.length; ++i)
			{
				var newOption = document.createElement('option');
				newOption.value = countries[i].getAttribute('code');
				var textNode = document.createTextNode(countries[i].firstChild.nodeValue);
				newOption.appendChild(textNode);
				document.getElementById('country').appendChild(newOption);
			}

			for (var i = 0; i < states.length; ++i)
			{
				var newOption = document.createElement('option');
				newOption.value = states[i].getAttribute('code');
				var textNode = document.createTextNode(states[i].firstChild.nodeValue);
				newOption.appendChild(textNode);
				document.getElementById('state').appendChild(newOption);
			}
		}
	};

	theHttpRequest.open("GET", url);
	theHttpRequest.send(false);
}

function getNewHttpObject()
{
    var objType = false;
    try
    {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(e)
    {
        try
        {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e)
        {
            objType = new XMLHttpRequest();
        }
    }
    return objType;
}