
//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 CountryListOnChange() 
{

	var countryList = document.getElementById("OtlobClipEn1_drpCountry");

	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	

	
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?SelectedCountry=" + encodeURIComponent(selectedCountry);
	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)
		{			
			ClearAndSetStateListItems(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}
function SearchClick()
{
var countryList = document.getElementById("OtlobClipEn1_drpCountry");
var stateList = document.getElementById("OtlobClipEn1_drpState");
var catList = document.getElementById("OtlobClipEn1_drpCat");

if(countryList.selectedIndex==0 || stateList.options[stateList.selectedIndex].text=="Select State" || countryList.options[countryList.selectedIndex].text=="Select Country" || catList.options[catList.selectedIndex].text=="Select Category")
{
	alert('Please select a country');
	return;
}


var countryValue = countryList.options[countryList.selectedIndex].value;
var stateValue = stateList.options[stateList.selectedIndex].value;
var catValue = catList.options[catList.selectedIndex].value;
var stateText = stateList.options[stateList.selectedIndex].text;
var catText = catList.options[catList.selectedIndex].text;
countryList.selectedIndex=0;
window.location.href="http://msn.otlob.com/SearchResult.aspx?lang=en&Area="+stateValue+"&Cat="+catValue;

}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
    var stateList = document.getElementById("OtlobClipEn1_drpState");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('state');
	var textValue; 
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count].childNodes[0]);
   		textName = GetInnerText(stateNodes[count].childNodes[1]);
		optionItem = new Option(  textValue,textName,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	
	
	
	var CatList = document.getElementById("OtlobClipEn1_drpCat");
	//Clears the Category combo box contents.
	for (var count = CatList.options.length-1; count >-1; count--)
	{
		CatList.options[count] = null;
	}

	var CatNodes = countryNode.getElementsByTagName('Category');
	var textValue;
	var textName;
	var optionItem;
	//Add new Cat list to the Cat combo box.
	for (count = 0; count < CatNodes.length; count++)
	{
   		textValue = GetInnerText(CatNodes[count].childNodes[0]);
   		textName = GetInnerText(CatNodes[count].childNodes[1]);
		optionItem = new Option(  textValue,textName,  false, false);
		CatList.options[CatList.length] = optionItem;
	}
}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}









