var XmlReq;
// This page returns the XML Response for the selected choice
var AjaxServerPageName = "http://localhost/Joomlanew/city.php";
//var AjaxServerPageName1 = "state.php";

function CreateXmlReq()
{
	try
	{
		XmlReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) 
	{
		try
		{
			XmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlReq = null;
		}
	}
	if(!XmlReq && typeof XMLHttpRequest != "undefined") 
	{
		XmlReq = new XMLHttpRequest();
		//alert("M");
	}
}

//This fucntion is to send the choice into the AJAX Server page for processing

function changecity()
{
   //alert("Send Called");
	var stateid = document.getElementById("state").value;
	var requestUrl = AjaxServerPageName + "?stateid=" +stateid;
		requestUrl = requestUrl + '&sid=' + Math.random();

	CreateXmlReq();
	
	if(XmlReq)
	{
		XmlReq.onreadystatechange = function(){ HandleResponsestate(); };
		XmlReq.open("GET", requestUrl,  true);
		XmlReq.send(null);		
	}
	
}

function HandleResponsestate()
{
    //alert("callback");
	if(XmlReq.readyState == 4)
	{
		if(XmlReq.status == 200)
		{	
		    city = XmlReq.responseText;		
			document.getElementById("city").innerHTML = city;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}


