function requestError (sid, msg)
{
	sid.options.length = 0;
	sid.disabled = true;
	sid.options[sid.options.length] = new Option(msg, 0, false, false);
}

var xmlHttp = false;

try {
 	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
 	try {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e2) {
		xmlHttp = false;
	}
}

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}

if (!xmlHttp) {
	requestError (sid, 'XMLHttpRequest error');
}

function updateSelect (a_selectId, optValue, fs)
{
	if (!xmlHttp)
		return false;
	selectId = a_selectId[0];
	sid = document.getElementById(selectId);
	sid.options.length = 0;
	sid.disabled = true;
	sid.options[sid.options.length] = new Option("--- подождите, идет загрузка ---", 0, false, false);
	var url = "/select/" + fs + "_" + optValue + "/";
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{
			try {
				eval("var geo = " + xmlHttp.responseText);
			}catch(e){
				if(optValue == 0)
				{
					requestError (sid, '--- не имеет значения ---');
					for(var j=1; j < a_selectId.length; j++)
						requestError (document.getElementById(a_selectId[j]), '--- не имеет значения ---');
				}
				else
					requestError (sid, '--- нет информации ---');
				return false;
			}
			if ((typeof geo != 'object')||(geo === null))
			{
				requestError (sid, '--- ошибка на сервере ---');
				return false;
			}
			sid.options.length = 0;
			sid.options[sid.options.length] = new Option("--- не имеет значения ---", 0, false, false);
			for(var j=1; j < a_selectId.length; j++)
			{
				document.getElementById(a_selectId[j]).options.length = 0;
				document.getElementById(a_selectId[j]).options[document.getElementById(a_selectId[j]).options.length] = new Option("--- не имеет значения ---", 0, false, false);
				document.getElementById(a_selectId[j]).disabled = true;
			}
			for(var i in geo)
			{
				sid.options[sid.options.length] = new Option(geo[i], i, false, false);
			}
			sid.disabled = false;
		}
	}
	xmlHttp.send(null);
}
