
//Global XMLHTTP Request object
var XmlHttp;
var FlagPermissionDenied;


//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 AstroCountryListOnChange() 
{
	var countryList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlAstroCountry");
	var textCity = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_txtAstroCity");
	var btnCity = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_btnVerifyAstroCity");

	textCity.disabled=false;
	btnCity.disabled=false;
	//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 = HandleAstroCountryResponse;

		//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);
				
			
	}
}

function RegAstroCountryListOnChange() 
{
	var countryList = document.getElementById("ctl00_ContentPlaceHolder1_ddlAstroCountry");
	var textCity = document.getElementById("ctl00_ContentPlaceHolder1_txtAstroCity");
	var btnCity = document.getElementById("ctl00_ContentPlaceHolder1_btnVerifyAstroCity");
	textCity.disabled=false;
	btnCity.disabled=false;
	//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 = HandleRegAstroCountryResponse;


		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		try
		{
			XmlHttp.open("GET", requestUrl,  true);
		}
		catch(e)
		{

			requestUrl = AjaxServerPageNameTwo + "?SelectedCountry=" + encodeURIComponent(selectedCountry);
			XmlHttp.open("GET", requestUrl,  true);
		}
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

function CountryListOnChange() 
{
	var countryList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_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 = HandleCountryResponse;
		
		//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);		
	}
}


//Gets called when country combo box selection changes
function AstroStateListOnChange() 
{

        var textCity = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_txtAstroCity");
	    var btnCity = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_btnVerifyAstroCity");
	    textCity.disabled=false;
	    btnCity.disabled=false;

        var stateList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlAstroState");
        var hiddenValue = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_hfAstroState");
        var hiddenText = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_hfAstroStateText");
        var selectedState = stateList.options[stateList.selectedIndex].value;
        var selectedStateText = stateList.options[stateList.selectedIndex].text;
        hiddenValue.value = selectedState;
        hiddenText.value = selectedStateText;
	}

function RegAstroStateListOnChange() 
{

        var textCity = document.getElementById("ctl00_ContentPlaceHolder1_txtAstroCity");
	    var btnCity = document.getElementById("ctl00_ContentPlaceHolder1_btnVerifyAstroCity");
	    textCity.disabled=false;
	    btnCity.disabled=false;

        var stateList = document.getElementById("ctl00_ContentPlaceHolder1_ddlAstroState");
        var hiddenValue = document.getElementById("ctl00_ContentPlaceHolder1_hfAstroState");
        var hiddenText = document.getElementById("ctl00_ContentPlaceHolder1_hfAstroStateText");
        var selectedState = stateList.options[stateList.selectedIndex].value;
        var selectedStateText = stateList.options[stateList.selectedIndex].text;
        hiddenValue.value = selectedState;
        hiddenText.value = selectedStateText;
}

function StateListOnChange() 
{
        var stateList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlState");
        var hiddenValue = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_hfState");
        var selectedState = stateList.options[stateList.selectedIndex].value;
        hiddenValue.value = selectedState;
}


//Called when response comes back from server
function HandleAstroCountryResponse()
{

	// 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)
		{			
			ClearAndSetAstroStateListItems(XmlHttp.responseXML.documentElement);
		}

		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function HandleRegAstroCountryResponse()
{

	// 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)
		{			
			ClearAndSetRegAstroStateListItems(XmlHttp.responseXML.documentElement);
		}

		else
		{
			alert("There was a problem retrieving data from the server." + 'status='+XmlHttp.status);
		}
	}
}

function HandleCountryResponse()
{

	// 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 HandleAstroStateResponse()
{

	// 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)
		{			
			ClearAndSetAstroCityListItems(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}


function HandleStateResponse()
{

	// 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)
		{			
			ClearAndSetCityListItems(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 ClearAndSetAstroStateListItems(countryNode)
{

    var stateList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlAstroState");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('StateName');
	var stateCodes = countryNode.getElementsByTagName('StateCode');
	var textValue;
	var codeValue; 
	var optionItem;
	var opt = document.createElement("Option");
	stateList.options.add(opt);
	opt.text = "Select";
	opt.value = 0;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		
   		codeValue = GetInnerText(stateCodes[count]);
		optionItem = new Option( textValue,codeValue, false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

function ClearAndSetRegAstroStateListItems(countryNode)
{

    var stateList = document.getElementById("ctl00_ContentPlaceHolder1_ddlAstroState");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('StateName');
	var stateCodes = countryNode.getElementsByTagName('StateCode');
	var textValue;
	var codeValue; 
	var optionItem;
	var opt = document.createElement("Option");
	stateList.options.add(opt);
	opt.text = "Select";
	opt.value = 0;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		
   		codeValue = GetInnerText(stateCodes[count]);
		optionItem = new Option( textValue,codeValue, false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

function ClearAndSetStateListItems(countryNode)
{

    var stateList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlState");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = countryNode.getElementsByTagName('StateName');
	var stateCodes = countryNode.getElementsByTagName('StateCode');
	var textValue;
	var codeValue; 
	var optionItem;
    var opt = document.createElement("Option");
	stateList.options.add(opt);
	opt.text = "Select";
	opt.value = 0;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		
   		codeValue = GetInnerText(stateCodes[count]);
		optionItem = new Option( textValue,codeValue, false, false);
		stateList.options[stateList.length] = optionItem;
	}
}


//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetAstroCityListItems(StateNode)
{
    var cityList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlAstroCity");
	//Clears the state combo box contents.
	for (var count = cityList.options.length-1; count >-1; count--)
	{
		cityList.options[count] = null;
	}

	var cityNodes = StateNode.getElementsByTagName('CityName');
	var cityCodes = StateNode.getElementsByTagName('CityCode');
	var textValue; 
	var codeValue;
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < cityNodes.length; count++)
	{
   		textValue = GetInnerText(cityNodes[count]);
   		
   		codeValue = GetInnerText(cityCodes[count]);
		optionItem = new Option( textValue, codeValue,  false, false);
		cityList.options[cityList.length] = optionItem;
	}
}


function ClearAndSetCityListItems(StateNode)
{
    var cityList = document.getElementById("ctl00_ContentPlaceHolder1_Wizard1_ddlCity");
	//Clears the state combo box contents.
	for (var count = cityList.options.length-1; count >-1; count--)
	{
		cityList.options[count] = null;
	}

	var cityNodes = StateNode.getElementsByTagName('CityName');
	var cityCodes = StateNode.getElementsByTagName('CityCode');
	var textValue; 
	var codeValue;
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < cityNodes.length; count++)
	{
   		textValue = GetInnerText(cityNodes[count]);
   		
   		codeValue = GetInnerText(cityCodes[count]);
   		
		optionItem = new Option( textValue, codeValue,  false, false);
		cityList.options[cityList.length] = optionItem;
	}
}



//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}









