function ajax_http()
{
    this.http = null;
    this.working = false;

    this.method = 'GET';
    this.url = '';
    this.go = '';
    this.func_return = null;

    this.init = function()
    {
        if (!this.http)
        {
            this.http = this.get_http();
            this.working = false;
        }
        if (!this.working && this.http)
        {
            this.http.open(this.method, this.url, true);
            this.http.setRequestHeader("Accept-Language", "ru, en");
            this.http.setRequestHeader("Accept-Charset", "windows-1251");
            if (this.func_return != null)
                this.http.onreadystatechange = this.func_return;
            this.working = true;
            this.http.send(null);
        }
        if (!this.http)
        {
            alert('Ошибка при создании XMLHTTP объекта!')
        }
    }

    this.get_http = function()
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        return xmlhttp;
    }
}

/*
id - идентификатор выпадающей плашки
id_control - идентификатор поля ввода
url - адрес, для получение списка (к нему будет добавляться "?value=текст")
*/
function input_popup(id, id_control, url)
{
    this.id = id;
    this.id_control = id_control;
    this.obj = $(this.id);
    this.obj_list = $(this.id + "_list");
    this.obj_control = $(this.id_control);
    this.ax = new ajax_http();
    this.name_input = "";
    this.receiv_data = "";
    this.url = url;

    this.arr = Array(0);

    this.init = function()
    {
        this.obj.setStyle("display", "none");
        this.obj_control.addEvent('keyup', function(a, b, c)
        {
            return function()
            {
                var temp_str = String(a.value);
                if (temp_str.length >= 2)
                {
                    c.get_data(temp_str);
                }
                else
                {
                    b.setStyle("display", "none");
                }
            }

        } (this.obj_control, this.obj, this));

        this.obj_control.addEvent('keydown', function(a)
        {
            return function()
            {
//                if (event.keyCode == 9)
//                    a.setStyle("display", "none");
            }

        } (this.obj));

        if ($(this.id + "_close"))
        {
            $(this.id + "_close").addEvent('click', function()
            {
                var temp_str = String(this.id);
                temp_str = temp_str.replace("_close", "");
                $(temp_str).setStyle("display", "none");
            });
        }

        this.name_input = this.obj_control.name;

    }

    this.submit = function()
    {
        this.obj_control.name = this.name_input;
    }

    this.get_data = function(str)
    {
        this.ax = new ajax_http();
        this.ax.url = this.url + '?value=' + encodeURIComponent(str);
        this.ax.func_return = function(a, b)
        {
            return function()
            {
                if (a.http.readyState == 4)
                {
                    b.receiv_data = new String(a.http.responseText);
                    b.write_data();
                }
            }
        } (this.ax, this);
        this.ax.init();
        
//        this.receiv_data = new String("дизайнер|программист|директор|повар");
//        this.write_data();
    }

    this.write_data = function()
    {
        var arr_str = this.receiv_data.split("|");
        if(arr_str.length > 10)
        {
            this.obj.setStyle('height', '200px');
            this.obj.setStyle('overflow', 'auto');
        }
        else
        {
            this.obj.setStyle('height', 'auto');
            this.obj.setStyle('overflow', 'auto');
        }

        this.obj_list.innerHTML = '';
        this.arr = Array(0);
        var i = 0;
        var temp_obj = null;
        for (i = 0; i < arr_str.length; i++)
        {
            temp_obj = new Element('a', {
                'id': this.id + '_item_' + i,
                'href': '#'
            });
            temp_obj.innerHTML = arr_str[i];

            temp_obj.addEvent("click", function() {
                    var temp_str = String(this.id);
                    var temp_arr = temp_str.split("_");
                    $("f_st").value = $(this.id).innerHTML;
                    $(temp_arr[0] + "_" + temp_arr[1]).setStyle("display", "none");
                    return false;
            });

            this.arr[this.arr.length] = temp_obj;
            this.obj_list.appendChild(temp_obj);
        }
        if (this.receiv_data != "")
            this.obj.setStyle("display", "block")
        else
            this.obj.setStyle("display", "none")
    }
    this.init();
}

