var objValidXMLString;

function PopulateCity()
{
	
	
	if(document.getElementById("UCFindHotel:ddlCountryList")!=null)
	{		
		var idx = document.getElementById("UCFindHotel:ddlCountryList").selectedIndex;
		
		if(idx > -1)		
			getCityListForFindHotelUC();
		
	}

}

function getCityList()
{
	obj_ddlCountryList = window.document.getElementById("ddlCountryList");
	//alert(obj_ddlCountryList.value);
	obj_ddlCityList = window.document.getElementById("ddlHotOffDestinationList");
	obj_ddlCityList.selectedIndex = 0;
	var ccode=obj_ddlCountryList.value;
	
	if (ccode != "0")
	{
		//alert(navigator.appName);
		if (document.implementation && document.implementation.createDocument)
		{
			var xmlHttp = new XMLHttpRequest();
			xmlHttp.open("GET", "GetCityList.aspx?ccode="+ccode, false);
			xmlHttp.send(null);
			
			objValidXMLString = jsXML.createDOMDocument();
			objValidXMLString.loadXML(xmlHttp.responseText);
	    
			//need to format for printing
			var reLT = /</g;
			var reGT = />/g;
			var reAmp = /&/g;
	    
			var strXML = objValidXMLString.xml.replace(reAmp, "&amp;");
			strXML = strXML.replace(reLT, "&lt;");
			strXML = strXML.replace(reGT, "&gt;");
	    
			var objcitylist = objValidXMLString.getElementsByTagName('CD');
			//alert(objcitylist.length);
			
			obj_ddlCityList.length = objcitylist.length;
			
			for(var i=0;i < objcitylist.length;i++)
			{
				var CityIDNode = objcitylist[i].childNodes[0];
				var CityNameNode = objcitylist[i].childNodes[1];
				if(CityIDNode.hasChildNodes())
				{
					//alert("i = "+ i);
					var j = 0;
					var xmlChildNode, nodeVal, nodeText;
					while(CityIDNode.childNodes[j])
					{
						// get node
						//xmlChildNode = CityNode.childNodes[i];
						//alert(CityIDNode.childNodes[j].nodeValue);
						
						// check nodetype	
						//if(xmlChildNode.nodeType != 3) // #text == 3
						//{					
							nodeVal = CityIDNode.childNodes[j].nodeValue;
							//CityNode.LastChild;
							nodeText = CityNameNode.childNodes[j].nodeValue;
							obj_ddlCityList.options[i].value = nodeVal;
							obj_ddlCityList.options[i].text = nodeText;
							//alert(CityIDNode.childNodes[j].nodeValue);
							//alert(CityNameNode.childNodes[j].nodeValue);
							//if (i == 0){obj_ddlCityList.options[i].selected = true;}
						//}
						j++;
					}
					// set control value to nodeValue
					
					//obj_ddlCityList.options[j].text = nodeVal;
				}
			}		
		}
			
		else if (window.ActiveXObject)
		{
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
			xmlHttp.open("GET", "GetCityList.aspx?ccode="+ccode, false)
			xmlHttp.send()			
			var xmlcity = new ActiveXObject("Microsoft.XMLDOM")
			xmlcity.async=false
			xmlcity.loadXML(xmlHttp.responseText)
			var objcitylist = xmlcity.selectNodes("//CD")
			
			obj_ddlCityList.length = objcitylist.length;
				
			if (objcitylist.length > 0)
			{			
				for(var i=0;i < objcitylist.length;i++)
				{					
					obj_ddlCityList.options[i].value=objcitylist.item(i).selectSingleNode("C").text;
					obj_ddlCityList.options[i].text=objcitylist.item(i).selectSingleNode("N").text;
				}
			}
		}
	}
	else
	{
		for(var i=obj_ddlCityList.options.length;i >= 0;i--)
		obj_ddlCityList.options[i] = null;
	}	
}

function getCityListForFindHotelUC()
{
	obj_ddlCountryList = window.document.getElementById("UCFindHotel_ddlCountryList");
	//alert(obj_ddlCountryList.value);
	obj_ddlCityList1 = window.document.getElementById("UCFindHotel_ddlCityList");
	obj_ddlCityList1.selectedIndex = 0;
	
	obj_hidCountryID = window.document.getElementById("UCFindHotel_hidCountryID");
	obj_hidCountryName = window.document.getElementById("UCFindHotel_hidCountryName");
	
	obj_hidCountryID.value = obj_ddlCountryList.value;			
	obj_hidCountryName.value = obj_ddlCountryList.options[obj_ddlCountryList.selectedIndex].text;
	
	var ccode=obj_ddlCountryList.value;
	
	//alert(navigator.appName);
	if (document.implementation && document.implementation.createDocument)
	{
		var xmlHttp = new XMLHttpRequest();
		xmlHttp.open("GET", "GetCityList.aspx?ccode="+ccode, false);
		xmlHttp.send(null);
		
		objValidXMLString = jsXML.createDOMDocument();
		objValidXMLString.loadXML(xmlHttp.responseText);
    
		//need to format for printing
		var reLT = /</g;
		var reGT = />/g;
		var reAmp = /&/g;
    
		var strXML = objValidXMLString.xml.replace(reAmp, "&amp;");
		strXML = strXML.replace(reLT, "&lt;");
		strXML = strXML.replace(reGT, "&gt;");
    
		var objcitylist1 = objValidXMLString.getElementsByTagName('CD');
		//alert(objcitylist.length);
		
		obj_ddlCityList1.length = objcitylist1.length;
		
		for(var i=0;i < objcitylist1.length;i++)
		{
			var CityIDNode = objcitylist1[i].childNodes[0];
			var CityNameNode = objcitylist1[i].childNodes[1];
			if(CityIDNode.hasChildNodes())
			{
				//alert("i = "+ i);
				var j = 0;
				var xmlChildNode, nodeVal, nodeText;
				while(CityIDNode.childNodes[j])
				{
					// get node
					//xmlChildNode = CityNode.childNodes[i];
					//alert(CityIDNode.childNodes[j].nodeValue);
					
					// check nodetype	
					//if(xmlChildNode.nodeType != 3) // #text == 3
					//{					
						nodeVal = CityIDNode.childNodes[j].nodeValue;
						//CityNode.LastChild;
						nodeText = CityNameNode.childNodes[j].nodeValue;
						obj_ddlCityList1.options[i].value = nodeVal;
						obj_ddlCityList1.options[i].text = nodeText;
						//alert(CityIDNode.childNodes[j].nodeValue);
						//alert(CityNameNode.childNodes[j].nodeValue);
						//if (i == 0){obj_ddlCityList.options[i].selected = true;}
					//}
					j++;
				}
				// set control value to nodeValue
				
				//obj_ddlCityList.options[j].text = nodeVal;
			}
		}	
	}
		
	else if (window.ActiveXObject)
	{
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
		xmlHttp.open("GET", "GetCityList.aspx?ccode="+ccode, false)
		xmlHttp.send()			
		var xmlcity = new ActiveXObject("Microsoft.XMLDOM")
		xmlcity.async=false
		xmlcity.loadXML(xmlHttp.responseText)
		var objcitylist1 = xmlcity.selectNodes("//CD")
		
		obj_ddlCityList1.length = objcitylist1.length;
			
		if (objcitylist1.length > 0)
		{			
			for(var i=0;i < objcitylist1.length;i++)
			{					
				obj_ddlCityList1.options[i].value=objcitylist1.item(i).selectSingleNode("C").text;
				obj_ddlCityList1.options[i].text=objcitylist1.item(i).selectSingleNode("N").text;
			}
		}
	}	
	
	// Re-select the city which the user had entered for a previous search.
	// The city name which the user had chosen for a previous search is stored in "hidCityName".
	var obj_hidPreviousSearchCityName = window.document.getElementById("UCFindHotel_hidCityName");	

	if (obj_hidPreviousSearchCityName.value != "")
	{
    for(i=0;i<obj_ddlCityList1.length;i++)
    {
      if (obj_ddlCityList1.options[i].text == obj_hidPreviousSearchCityName.value)
      {
        obj_ddlCityList1.selectedIndex = i;
        break;
      }
    }

	}
	
	// If the user changes the city, change the hotel name textbox text back to "[Hotel Name]".
	// Whether the user searches for a specific hotel or not, set the text back to "[Hotel Name]".
	//var obj_txtSrcHotelName = window.document.getElementById("UCFindHotel_txtSrcHotelName");
	//obj_txtSrcHotelName.value = "[Hotel Name]";
}
		
function getSelectedCityID()
{
	obj_ddlCityList1 = window.document.getElementById("UCFindHotel_ddlCityList");
	obj_hidCityID = window.document.getElementById("UCFindHotel_hidCityID");			
	obj_hidCityName = window.document.getElementById("UCFindHotel_hidCityName");			
	obj_hidCityID.value = obj_ddlCityList1.value;			
	obj_hidCityName.value = obj_ddlCityList1.options[obj_ddlCityList1.selectedIndex].text;
	// If the user changes the city, change the hotel name textbox text back to "[Hotel Name]".
	// Whether the user searches for a specific hotel or not, set the text back to "[Hotel Name]".
	var obj_txtSrcHotelName = window.document.getElementById("UCFindHotel_txtSrcHotelName");
	obj_txtSrcHotelName.value = "[Hotel Name]";								
}
