/** ЗАПОЛНЕНИЕ ВЫПАДАЮЩЕГО СПИСКА ЗНАЧЕНИЯМИ **/

function requestError2 (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)
	requestError2 (sid, 'XMLHttpRequest error');

function updateSelect(table, optValue, a_selectId)
{
	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 = '/classifier_info.php?t=' + table + '&v=' + optValue;
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			try
			{
				eval('var select = ' + xmlHttp.responseText);
			}
			catch(e)
			{
				if(optValue == 0)
				{
					requestError2(sid, '--- не имеет значения ---');
					for(var j=1; j < a_selectId.length; j++)
						requestError2(document.getElementById(a_selectId[j]), '--- не имеет значения ---');
				}
				else
				{
					requestError2 (sid, '--- нет информации ---');
				}
				return false;
			}
			
			if((typeof select != 'object')||(select === null))
			{
				requestError2 (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 select)
			{
				sid.options[sid.options.length] = new Option(select[i], i, false, false);
			}
			sid.disabled = false;
		}
	}
	xmlHttp.send(null);
}