
var cityRequest, cityPara;

function updateCityName()
{
	var cityXml = cityRequest.getResponseXML();
	var cities = cityXml.getElementsByTagName("city");
	var cityText = "No city found.";
	
	if(cities.length > 0 && cities[0].firstChild && cities[0].firstChild != null)
		cityText = cities[0].firstChild.nodeValue;
	
	if(cityPara == null)
		cityPara = document.getElementById("cityName");
	
	cityPara.innerHTML = cityText;
}

function findCityName(zipCode)
{
	if(cityRequest != null
		&& cityRequest.getReadyState() < MicroRequest.STATE_COMPLETE)
	{
		cityRequest.abort();
	}
	
	if(zipCode != null && zipCode.length == 5)
	{
		cityRequest = new MicroRequest("GET", "example/findCity.php", true);
		cityRequest.registerStateListener(updateCityName,
			MicroRequest.STATE_COMPLETE);
		cityRequest.addParameter("zip", zipCode);
	
		cityRequest.send();
	}
}
