
//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;
		}
	}//23
	//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 CityListOnChange() 
{

	var cityList = document.getElementById("drpcity");

	//Getting the selected country from country combo box.
	var selectedcity = cityList .options[cityList .selectedIndex].value;
	
	//this below line used for loading img display
	document.getElementById('loading1').innerHTML="<table cellSpacing=0 cellPadding=0 border=0 ><tr><td><img src=images/loader.gif width =16 height=16></td></tr></table>";

        
           
	
	//Visible true= others
	//if (selectedcity=="others")
	//{
 	 //document.getElementById('txtCityOthers').style.display = 'block';
 	 //document.getElementById('txtLocalOthers').style.display = 'block';
	// For Focus
	 //document.getElementById('txtCityOthers').focus();

	//}

	//else


	// For Except Others
	//{	
		
	//document.getElementById('txtCityOthers').style.display = 'none';
 	 //document.getElementById('txtLocalOthers').style.display = 'none';

	//}

	// End for Except others


	// URL to get states for a given country
	var requestUrl = AjaxServerPageNameFilter + "?city=" + encodeURIComponent(selectedcity);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponsecity;

		//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);
	}
//this below line used for loading img display
  document.getElementById('loading1').innerHTML="";

}
 

//Gets called when city combo box selection changes
function areaListOnChange() 
{

	var cityList = document.getElementById("drpcity");

	//Getting the selected country from country combo box.
	var selectedcity = cityList.options[cityList.selectedIndex].value;

	// alert(selectedcity);	
	var areaList = document.getElementById("drplocalarea");


	//Getting the selected country from country combo box.

	var selectedarea = areaList.options[areaList.selectedIndex].value;
           	
          
	//Visisble true= others
	//if (selectedarea=="Others")
	//{
 	 //document.getElementById('txtLocalOthers').style.display = 'block';

	// For Focus
	 //document.getElementById('txtLocalOthers').focus();

           //	}

	//else


	// For Except Others
	//{	
	
	
	   //document.getElementById('txtLocalOthers').style.display = 'none';
	
	//}

	// End for Except others
	
	Form1.hidlocalarea.value=selectedarea;
		
}

//Called when response comes back from server
function HandleResponsecity()
{
	// 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)
		{	

		
			ClearAndSetarea(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 ClearAndSetarea(xmlResponseList)
{

    var areaList = document.getElementById("drplocalarea");
    
   
    
	//Clears the state combo box contents.
	for (var count = areaList.options.length-1; count >-1; count--)
	{
		areaList.options[count] = null;
	}
	
	

	var areaNodes = xmlResponseList.getElementsByTagName('areavalue');
	var textValue; 
	var optionItem;
	//Add new states list to the state combo box.
   	textValue = "";

	//optionItem = new Option( textValue, textValue,  false, false);
	//cityList.options[cityList.length] = optionItem;
	for (var count = 0; count < areaNodes.length; count++)
	{
   		textValue = GetInnerText(areaNodes[count]);
		optionItem = new Option( textValue, textValue,  false, false);
		areaList.options[areaList.length] = optionItem;
		if (count ==0) 
		{
			Form1.hidlocalarea.value=textValue;
		}
	}

}


//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}
