var xmlHttp;
var listid;	//variable to store the listbox id which is passed.

function GetXmlHttpObject() {
	try	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		// Internet Explorer
		try	{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function getCorrsArea(objlstCtry, lstId, front) {
	GetXmlHttpObject();

	var countryId = objlstCtry.value;
	listId = lstId;
	if(front) {
		path = '';
	}
	else {
		path = '../';
	}

	url = "getareas_ajax.php";
	url = path + url + "?countryId=" + countryId;

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		
		// Storing result into a variable
		strResponseText = xmlHttp.responseText;
			
		//Splitting airports from respose text and store it into an array
		arrAreas = strResponseText.split("##");	

		// Get the object of listbox in which options to be changed
		objListbox = document.getElementById(listId);
		
		// Removing the exisiting options one by one.
		optLength = objListbox.options.length;
		for(i=1; i<optLength; i++) {
			eval("objListbox.options[1]=null");
		}

		// Check whether the response text is blank or not
		if(strResponseText != "") {
			
			// Adding the new set of options one by one.
			for(i=0; i<arrAreas.length-1; i++) {
				//Spliting the airport recid and name
				arrAreaInfo = arrAreas[i].split("@@");
				objOption = new Option(arrAreaInfo[1], arrAreaInfo[0]);
				eval("objListbox.options[i+1]=objOption");
			}
		}
	}
}