<!--

var request;
var response;
var City;
var m_cityCode;
var otherDest;
var preSelectDest;


//function to disable city list popup
function checkOrig(){
	var origLocation = document.getElementById('origLocation');
	var link = document.getElementById('cityListLink');
	if (origLocation.selectedIndex==0){
			link.disabled=false;
	}else{
			link.disabled=true;
	}
}

function populateOtherDestCity(preSelectCityCode){
	var origCountry = document.getElementById("origLocation");
	var textbox1 = document.getElementById("Textbox1");
	var ArriveTextbox = document.getElementById("ArriveTextbox");
	if (!textbox1){
		textbox1 = ArriveTextbox;
	}
	
	preSelectDest = preSelectCityCode;
	otherDest = document.getElementById("otherDest");
	checkOrig();
	if(origCountry.selectedIndex>0)
	//Check if the selectedItem as not "--Select--"
	{
		otherDest.style.display='';
		textbox1.style.display='none';					
		return SendRequestDest(origCountry.options[origCountry.selectedIndex].value);
	}	else{
		otherDest.style.display='none';
		textbox1.style.display='';			
	}
}	

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, 1);//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 SendRequestDest(ID)
{
	InitializeRequest();//Call InitializeRequest to set request object
	var url = "destlist.aspx?citycode="+ID;//Create the url to send the request to
	request.onreadystatechange = ProcessRequestDest;//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 ProcessRequestDest()
{
	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
			{
				populateListDest(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(otherDest, 0);//Call clearSelect function
			}
		}
	}
	return true;//return
}



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, 1);//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, 1);//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 populateListDest(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(otherDest, 0);//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(otherDest, CityElem[i].getElementsByTagName("CityCode")[0].childNodes[0].nodeValue, textNode, i, CityElem.length);//Call appendToSelect to append the text elements to the City dropdown

		}
		if (otherDest.options.length == 1){
				otherDest.selected = true;
		}
		if (preSelectDest!=""){
			for (i=0; i<otherDest.length; i++){
				if (otherDest[i].value == preSelectDest){
					if (document.all){
							otherDest[i].setAttribute('selected', true);						
					}else{
							otherDest[i].selected=true;						
					}
				}
			}							
		}	
	}
}


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, optionCount)
{
	select.options.length = optionCount;//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	
}

//-->
