function get_http(){
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new
                ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
        xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}


function ajax(fileway, select_id, data, value, fill_type) {
	// Получаем объект XMLHTTPRequest
	this.http = get_http();
	this.working = false;
	var url = '/inc/' + fileway;
	// Запрос
	if (!this.working && this.http) {
	   	var http = this.http;
	    //создаём запрос
	    url = url + '?';
	    var arr_data = data.split('::');
	    var arr_value = value.split('::');
	    for(i=0; i<arr_data.length; i=i+1) {
        	url = url + arr_data[i] + '=' + encodeURIComponent(arr_value[i]) + '&';
    	}
    	this.http.open("GET", url, true);
	    //прикрепляем к запросу функцию-обработчик событий
		this.http.onreadystatechange = function() {
			// 4 - данные готовы для обработки
    	    if (http.readyState == 4) {
        	   	if (fill_type == 'select') fill_select(select_id, http.responseText);
        	   	else fill(select_id, http.responseText, 'select');
                this.working = false;
	        }
    	}
        this.working = true;
	    this.http.send(null);
	}
	if(!this.http) {
    	alert('Ошибка при создании XMLHTTP объекта!')
	}
}

function fill (select_id, data, type) {
	// поле SELECT в переменную в виде объекта
    var insert = document.getElementById(select_id);
	// если данных нет - не делаем больше ничего
    if (type == 'value') insert.value = data;
    else insert.innerHTML = data;
}

function fill_select (select_id, data) {
	var select = document.getElementById(select_id);
    select.options.length = 0;
    if(data.length == 0) return;
    var arr = data.split('--|--');
    for(var i in arr){
        val = arr[i].split('---');
        select.options[select.options.length]=new Option(val[1], val[0], false, false);
    }
}
