
// 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();
	}
}



// One
function CountryListOnChange() 
{
    var countryList = document.getElementById("countryList");
    
    // get selected country from dropdown list
    var selectedCountry = countryList.options[countryList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getstates.php" + "?filter=" + encodeURIComponent(selectedCountry);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function StateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateStateList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateStateList(stateNode)
{
    var stateList = document.getElementById("stateList");
	// clear the state list 
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = stateNode.getElementsByTagName('state');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
		idValue = stateNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

// One
function StateListOnChange() 
{
    var stateList = document.getElementById("stateList");
    
    // get selected state from dropdown list
    var selectedState = stateList.options[stateList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getcounties.php" + "?filter=" + encodeURIComponent(selectedState);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = CountyChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function CountyChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateCountyList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateCountyList(countyNode)
{
    var countyList = document.getElementById("countyList");
	// clear the county list 
	for (var count = countyList.options.length-1; count >-1; count--)
	{
		countyList.options[count] = null;
	}

	var countyNodes = countyNode.getElementsByTagName('county');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < countyNodes.length; count++)
	{
   		textValue = GetInnerText(countyNodes[count]);
		idValue = countyNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		countyList.options[countyList.length] = optionItem;
	}
}

// One
function CountyListOnChange() 
{
    var countyList = document.getElementById("countyList");
    
    // get selected county from dropdown list
    var selectedCounty = countyList.options[countyList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getcities.php" + "?filter=" + encodeURIComponent(selectedCounty);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = CityChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function CityChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateCityList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateCityList(cityNode)
{
    var cityList = document.getElementById("cityList");
	// clear the city list 
	for (var count = cityList.options.length-1; count >-1; count--)
	{
		cityList.options[count] = null;
	}

	var cityNodes = cityNode.getElementsByTagName('city');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < cityNodes.length; count++)
	{
   		textValue = GetInnerText(cityNodes[count]);
		idValue = cityNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		cityList.options[cityList.length] = optionItem;
	}
}



// Look values

// One
function LookCountryListOnChange() 
{
    var countryList = document.getElementById("lookcountryList");
    
    // get selected country from dropdown list
    var selectedCountry = countryList.options[countryList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getstates.php" + "?filter=" + encodeURIComponent(selectedCountry);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = LookStateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function LookStateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateLookStateList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateLookStateList(stateNode)
{
    var stateList = document.getElementById("lookstateList");
	// clear the state list 
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = stateNode.getElementsByTagName('state');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
		idValue = stateNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

// One
function LookStateListOnChange() 
{
    var stateList = document.getElementById("lookstateList");
    
    // get selected state from dropdown list
    var selectedState = stateList.options[stateList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getcounties.php" + "?filter=" + encodeURIComponent(selectedState);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = LookCountyChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function LookCountyChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateLookCountyList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateLookCountyList(countyNode)
{
    var countyList = document.getElementById("lookcountyList");
	// clear the county list 
	for (var count = countyList.options.length-1; count >-1; count--)
	{
		countyList.options[count] = null;
	}

	var countyNodes = countyNode.getElementsByTagName('county');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < countyNodes.length; count++)
	{
   		textValue = GetInnerText(countyNodes[count]);
		idValue = countyNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		countyList.options[countyList.length] = optionItem;
	}
}

// One
function LookCountyListOnChange() 
{
    var countyList = document.getElementById("lookcountyList");
    
    // get selected county from dropdown list
    var selectedCounty = countyList.options[countyList.selectedIndex].value;
    
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
    //requestUrl = "xml_data_provider.asp" + "?filter=" + encodeURIComponent(selectedContinent);
    // use the following line if using php
    requestUrl = "getcities.php" + "?filter=" + encodeURIComponent(selectedCounty);
    
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = LookCityChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}

// Two
function LookCityChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			PopulateLookCityList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// Three
function PopulateLookCityList(cityNode)
{
    var cityList = document.getElementById("lookcityList");
	// clear the city list 
	for (var count = cityList.options.length-1; count >-1; count--)
	{
		cityList.options[count] = null;
	}

	var cityNodes = cityNode.getElementsByTagName('city');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < cityNodes.length; count++)
	{
   		textValue = GetInnerText(cityNodes[count]);
		idValue = cityNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		cityList.options[cityList.length] = optionItem;
	}
}













// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}
