var res = "http://readysteadydate.com/demo/";
// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

// called from onChange event of the country dropdown list
function populateState(country) {
	var selectedCountry = country;
	var requestUrl;
   requestUrl ="xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedCountry);
	CreateXmlHttpObj();
	if(XmlHttpObj){
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		XmlHttpObj.open("GET", requestUrl,  true);
		XmlHttpObj.send(null);		
	}
}
// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
function StateChangeHandler(){
	if(XmlHttpObj.readyState == 4){
		if(XmlHttpObj.status == 200){			
			PopulateStateList(XmlHttpObj.responseXML.documentElement);
		}else{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the state dropdown list
function PopulateStateList(countryNode){
	var regionList = document.getElementById("varState");
	regionList.options.length=0;
	regionList.options[0] = new Option("- Choose -",0);
	var countryNodes = countryNode.getElementsByTagName('region');
	var idValue;
	var textValue; 
	var optionItem;
	for (var count = 0; count < countryNodes.length; count++){
  		textValue = GetInnerText(countryNodes[count]);
		idValue = countryNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		regionList.options[regionList.length] = optionItem;
	}
}

// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}











