

var XmlHttp;
var _st;
var _di;
var _vi;


function CreateXmlHttp()
{
	//for IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//for Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}


function CountryListOnChange(st,di,vi) 
{
	
	_st=st;
	_di=di;
	_vi=vi;
	
	
		
	_vi.style["display"]="";
	_di.style["display"]="none";
	document.getElementById('txtSubmit').disabled=true;
	
	var countryList = _st;
		
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	
	
	var requestUrl = "revent_server.aspx?SelectedCountry=" + encodeURIComponent(selectedCountry);
	CreateXmlHttp();
	
	
	if(XmlHttp)
	{
		
		XmlHttp.onreadystatechange = HandleResponse;
		
	
		XmlHttp.open("GET", requestUrl,  true);
		
		
		XmlHttp.send(null);		
	}
}



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)
{
    var stateList = _di;
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}
	
	_vi.style["display"]="none";
	_di.style["display"]="";
	document.getElementById('txtSubmit').disabled=false;
	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]);
		optionItem = new Option( textValue, textValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	
}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) 
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}





