
//Global XMLHTTP Request object
var XmlHttp;
var currentCntrl = 0
var firstgo = 0
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{	firstgo = 0
	//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() 
{   
	//show1(100,100);
	currentCntrl = 0
	
	//document.getElementById("Apartment_for_rent1_tdSate").style.display="None";
	//document.getElementById("Apartment_for_rent1_tdSateimages").style.display="Block";
	//document.getElementById("Apartment_for_rent1_tdSate").innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0>" ;
	
	var countryList = document.getElementById("Apartment_for_rent1_ddlCountry");
	////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);		
	}
	
	//document.getElementById("Apartment_for_rent1_tdSate").innerHTML= document.getElementById("Apartment_for_rent1_tdSate").innerHTML;
}



//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." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
	
	//if(currentCntrl < 1)
	//{
	   // stateList = document.getElementById("Apartment_for_rent1_ddlState");
	   // document.getElementById("Apartment_for_rent1_ddlCity").options.length= 0 ;
	//}
	//else
	//{	
		stateList = document.getElementById("Apartment_for_rent1_ddlCity");
	//}
		
	//Clears the state combo box contents.
	
	if(stateList.options.length)
	{	
		stateList.options.length = 0;
	}

	var stateNodes = countryNode.getElementsByTagName('item');
	// alert(countryNode.getElementsByValue('item'));
	
	var textValue; 
	var optionItem;
	var val;
	var option1 = new Option('Select City' ,0 ,  false, false);
	    document.getElementById("Apartment_for_rent1_ddlCity").options[0] = option1;
	/*var option2 = new Option('All State' ,0 ,  false, false);
	document.getElementById("Apartment_for_rent1_ddlState").options[0] = option2;*/
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		var value1 = stateNodes[count].getAttribute('value');
   		optionItem = new Option(textValue ,value1 ,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	//remove_loading();
	//document.getElementById("Apartment_for_rent1_tdSate").style.display="Block";
	//document.getElementById("Apartment_for_rent1_tdSateimages").style.display="None";
}

//Returns the node text value 
function GetInnerText (node)
{	
	 return (node.textContent || node.innerText || node.text) ;
	
}

function CityListOnChange()
{
  document.getElementById("Apartment_for_rent1_ddlCity1").value =  document.getElementById("Apartment_for_rent1_ddlCity").options[document.getElementById("Apartment_for_rent1_ddlCity").selectedIndex].value;
}


