
// 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 or onClick event of the continent dropdown list
function CountryListOnChange() 
{
	if(document.main.cityList){
		document.main.cityList.disabled = true;
	}
	var countryList = document.getElementById("countryList");

// get selected continent from dropdown list
//    countryList.options[countryList.selectedIndex].value = "Australia1" ;
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
     //alert(selectedCountry);
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
//	requestUrl = "http://www.hotelrentalgroup.com/hotel_populate_xml.php" + "?filter1=" + encodeURIComponent(selectedCountry);
	var myURL = document.URL;
	var pairs = myURL.split("/");
	var domain_name;
	domain_name = pairs[2];
	if ((pairs[0]+pairs[1]+pairs[2]) == "http://hotelrentalgroup.com") {
		requestUrl = "http://www." + domain_name + "/hotel_populate_xml.php" + "?filter1=" + encodeURIComponent(selectedCountry);
	} else {
		requestUrl = "http://" + domain_name + "/hotel_populate_xml.php" + "?filter1=" + encodeURIComponent(selectedCountry);
	}
	// use the following line if using php
    // requestUrl = "hotel_populate_xml.php" + "?filter=" + encodeURIComponent(selectedContinent);
    
	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);		
		setTimeout('document.main.cityList.disabled = false;', 2000);
		setTimeout('document.main.cityList.focus();', 2000);
	}
}


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

// populate the contents of the country dropdown list
function PopulateCityList(cityNode)
{
	document.main.cityList.disabled=true;
	var cityList = document.getElementById("cityList");
	// clear the country list 
	var locationList = document.getElementById("locationList");

	for (var count = locationList.options.length-1; count >-1; count--)
	{
		locationList.options[count] = null;
	}
	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");
		//alert(textValue);
//		alert(textValue);
		optionItem = new Option( textValue, idValue,  false, false);
		cityList.options[cityList.length] = optionItem;
	}
//	document.main.cityList.disabled=false;
}

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


//////////////////For Locations Populating/////////////////////////
// called from onChange or onClick event of the continent dropdown list

function CityListOnChange() 
{
    var cityList = document.getElementById("cityList");
	var countryListQ = document.getElementById("countryList");
    var country_selected = countryListQ.options[countryListQ.selectedIndex].value;

// get selected continent from dropdown list
    var selectedCity = cityList.options[cityList.selectedIndex].value;
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
//    requestUrl = "http://www.hotelrentalgroup.com/hotel_populate_xml.php" + "?filter3=" + encodeURIComponent(selectedCity);
//	requestUrl = document.URL + "/hotel_populate_xml.php" + "?filter3=" + encodeURIComponent(selectedCity);
	var myURL = document.URL;
	var pairs = myURL.split("/");
	var domain_name;
	domain_name = pairs[2];
	if ((pairs[0]+pairs[1]+pairs[2]) == "http://hotelrentalgroup.com") {
		requestUrl = "http://www." + domain_name + "/hotel_populate_xml.php" + "?filter3=" + encodeURIComponent(selectedCity) + "&active_country=" + country_selected;
	} else {
		requestUrl = "http://" + domain_name + "/hotel_populate_xml.php" + "?filter3=" + encodeURIComponent(selectedCity)  + "&active_country=" + country_selected;
	}
//	alert(requestUrl);
 //alert(requestUrl)    
// use the following line if using php
    // requestUrl = "hotel_populate_xml.php" + "?filter=" + encodeURIComponent(selectedContinent);
    
	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 = StateChangeHandler2;
		
		// 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);		
	}
}


// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
function StateChangeHandler2()
{
	// 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)
		{			
			PopulateLocationList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the country dropdown list
function PopulateLocationList(locationNode)
{

	var locationList = document.getElementById("locationList");
	// clear the country list 


for (var count = locationList.options.length-1; count >-1; count--)
	{
		locationList.options[count] = null;
	}

	var locationNodes = locationNode.getElementsByTagName('location');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < locationNodes.length; count++)
	{
   		textValue = GetInnerText(locationNodes[count]);

	idValue = locationNodes[count].getAttribute("id");

		optionItem = new Option( textValue, idValue,  false, false);
	
	locationList.options[locationList.length] = optionItem;
	}
			
}

function OnCountryLoad() 
{
    var countryList = document.getElementById("countryList");
	// get selected continent from dropdown list
	//  var selectedCity = cityList.options[cityList.selectedIndex].value;
    // url of page that will send xml data back to client browser
    var requestUrl;
    // use the following line if using asp
	//  requestUrl = "http://www.hotelrentalgroup.com/hotel_populate_xml.php" + "?filter2=" + encodeURIComponent("World");
	//	requestUrl = document.URL + "/hotel_populate_xml.php" + "?filter2=" + encodeURIComponent("World");
	var myURL = document.URL;
	var pairs = myURL.split("/");
	var domain_name;
	domain_name = pairs[2];
	if ((pairs[0]+pairs[1]+pairs[2]) == "http://hotelrentalgroup.com") {
		requestUrl = "http://www." + domain_name + "/hotel_populate_xml.php" + "?filter2=" + encodeURIComponent("World");
	} else {
		requestUrl = "http://" + domain_name + "/hotel_populate_xml.php" + "?filter2=" + encodeURIComponent("World");
	}
	//alert(requestUrl)    
	// use the following line if using php
    // requestUrl = "hotel_populate_xml.php" + "?filter=" + encodeURIComponent(selectedContinent);
	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 = StateChangeHandler3;	
		// 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);
	}
}

function PopulateCountryList(countryNode)
{

	var countryList = document.getElementById("countryList");
	// clear the country list 


for (var count = countryList.options.length-1; count >-1; count--)
	{
		countryList.options[count] = null;
		cityList.options[count] = null;
		locationList.options[count] = null;
	}


for (var count = countryList.options.length-1; count >-1; count--)
	{
		locationList.options[count] = null;
	}





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

function StateChangeHandler3()
{
	// 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)
		{			
			PopulateCountryList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}