
//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function getQuoteResponse() 
{
	var requestUrl = 'XMLRequest.aspx';
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}


//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
//			test = XmlHttp.responseXML.documentElement
//			alert(test.tagName)
			ShowSelectedFlight(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ShowSelectedFlight(ResponseNode)
{
   //var resortList = document.getElementById("ctl00_cph1_Inc_iq1_resort");
   var textValue;

   var selectedFlightNodes = ResponseNode.getElementsByTagName('SelectedFlight');
   var flightNodes = ResponseNode.getElementsByTagName('Flights');
   var hotelNodes = ResponseNode.getElementsByTagName('Hotels');

   textValue = GetInnerText(selectedFlightNodes[0]);
   alert(textValue);
   //sf.innerHTML = textValue;

}

//Returns the node text value 
function GetInnerText (node)
{
	//alert('node: ' + node.textContent) 
	return (node.textContent || node.innerText || node.text) ;
}









