const GetCityList = function (callback) {
	let request = new XMLHttpRequest();
	let url = 'http://localhost:8080/?action=GetCityList';
	request.open('GET', url, true);
	request.onreadystatechange = function (e) {
		if (request.readyState == 4)
		{
			if (request.status == 200)
			{
				callback(JSON.parse(request.responseText));
			}
		}
	};
	request.send(null);
};

const GetCityData = function (cityId, callback) {
	let request = new XMLHttpRequest();
	let url = 'http://localhost:8080/?action=GetCityData&cityId=' + cityId;
	request.open('GET', url, true);
	request.onreadystatechange = function (e) {
		if (request.readyState == 4)
		{
			if (request.status == 200)
			{
				callback(JSON.parse(request.responseText));
			}
		}
	};
	request.send(null);
};

const GetTop = function (statName, callback) {
	let request = new XMLHttpRequest();
	let url = 'http://localhost:8080/?action=GetTop&statName=' + statName;
	request.open('GET', url, true);
	request.onreadystatechange = function (e) {
		if (request.readyState == 4)
		{
			if (request.status == 200)
			{
				currentTop = statName.charAt(0).toUpperCase() + statName.slice(1);
				callback(JSON.parse(request.responseText));
			}
		}
	};
	request.send(null);
};