<!--

var request;
var response;
var City;
var m_cityCode;

function populateCity()
{
	var Country = document.getElementById("country");
	City = document.getElementById("city");
	
	if(Country.options[Country.selectedIndex].value != '')
	//Check if the selectedItem as not "--Select--"
	{
		return SendRequest(Country.options[Country.selectedIndex].value);
	}
	else
	{
		clearSelect(City);//Clear the City dropdown
	}
}

function checkCity(cityCode){
	m_cityCode = cityCode;
	populateCity();
}

function checkSelectBox(selectBoxObj, myvalue){
	for (i=0;i<selectBoxObj.options.length;i++){
		if (selectBoxObj.options[i].value==myvalue){
			selectBoxObj.options[i].selected = true;
		}
	}
}

function InitializeRequest()
{
	try
	{
		if (window.XMLHttpRequest) {
			request = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}else{
			request = null;					
		}
	}
	catch(Ex)
	{
		try
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");//First failure, try again creating an XMLHTTP Object
		}
		catch(Ex)
		{
			request = null;//Else assign null to request
		}
	}

	if(!request&&typeof XMLHttpRequest != 'undefined')
	{
		request = new XMLHttpRequest();
	}
}

function SendRequest(ID)
{
	InitializeRequest();//Call InitializeRequest to set request object
	var url = "CityList.aspx?countrycode="+ID;//Create the url to send the request to
	request.onreadystatechange = ProcessRequest;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
	request.open("GET", url, true);//Open a GET request to the URL
	request.send(null);//Send the request with a null body.
}

function ProcessRequest()
{
	if(request.readyState == 4)//If the readyState is in the "Ready" state
	{
		if(request.status == 200)//If the returned status code was 200. Everything was OK.
		{
			if(request.responseText != "")//If responseText is not blank
			{
				populateList(request.responseText);//Call the populateList fucntion
				//status.innerText = "Territories Loaded";//Set the status to "Territories Loaded"
			}
			else
			{
				//status.innerText = "None Found";//Set the status to "None Found"
				clearSelect(City);//Call clearSelect function
			}
		}
	}
	return true;//return
}

function populateList(response)
{
	if (window.ActiveXObject){
		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");//Create the XMLDOM object
		xmlDoc.async = false;
		xmlDoc.loadXML(response);//Load the responseText into the XMLDOM document
	}else if (document.implementation &&
	document.implementation.createDocument)
	{
		var parser=new DOMParser();
		xmlDoc=parser.parseFromString(response,"text/xml");
	}
	else
	{
		alert('Your browser cannot handle this script');
	}

	var opt;
	var CitysElem = xmlDoc.getElementsByTagName("CityInfo");//Create the EmployeeTerritories element
	var CityElem = CitysElem[0].getElementsByTagName("City");//Create the TERRITORIES element

	clearSelect(City);//Clear the dropdown before filling it with new values
	if(CitysElem.length > 0)//If there are one or more TERRITORIES nodes
	{
		for (var i = 0; i < CityElem.length; i++)//Loop through the XML TERRITORIES nodes
		{
			var textNode = document.createTextNode(CityElem[i].getElementsByTagName("CityName")[0].childNodes[0].nodeValue);//Create a TextNode
			appendToSelect(City, CityElem[i].getElementsByTagName("CityID")[0].childNodes[0].nodeValue, textNode, i, CityElem.length);//Call appendToSelect to append the text elements to the City dropdown

		}
		if (City.options.length == 1){
				City.selectedIndex = 1;
		}
	
	}
}

function appendToSelect(select, value, content, i, optionCount)
{
	var opt;
	opt = document.createElement("option");//Create an Element of type option
	if (optionCount==1 && i==0){
		opt.selected = true;
	}
	if (m_cityCode == value){
		opt.selected = true;		
	}
	opt.value = value;//Set the option's value
	opt.appendChild(content);//Attach the text content to the option
	select.appendChild(opt);//Append the option to the referenced [City] select box
}

function clearSelect(select)
{
	select.options.length = 1;//Set the select box's length to 1 so only "--Select--" is availale in the selection on calling this function.
								//You may want to write your own clearSelect logic	
}

//-->
