
var loaded=0;

function change(Name,No) {
  if (loaded == 1) {
   	document[Name].src = eval(Name + No + ".src");
  }
}

function popup_window(URLStr, width, height) {
     window.open(URLStr, "popUpWin", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width="+width+", height="+height);
}



function get_http(){
    var xmlhttp;

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    } else {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            xmlhttp = false;
        }
    }
    this.act = 0;

    if(!xmlhttp){
        message('<font color="red"><b>Невозможно инициализировать XMLHttpRequest!</b></font>'    );
    } else {
        return xmlhttp;
    }

}


function lookup(text, select_id, url) {

		if(!this.http){
            this.http = get_http();
            this.working = false;
        }
		else{
			this.working = false;
		}


        if (!this.working && this.http) {
            var http = this.http;
            if (text.length <1 ) return;
            url = url + "?ajax=1&text="+encodeURIComponent(text);
            this.http.open("GET", url, true);
            this.http.onreadystatechange = function() {
                if (http.readyState == 4) {
                    fill(select_id, http.responseText);
                    this.working = false;
                }else{
					//alert("wait");
                     // данные в процессе получения,
                     // можно повеселить пользователя
                     //сообщениями
                     // ЖДИТЕ ОТВЕТА
                }
            }
            this.working = true;
            this.http.send(null);
        }
        if(!this.http){
              alert('Ошибка при создании XMLHTTP объекта!')
        }
}

function fill (select_id, data){


    var select = document.getElementById(select_id);
    if(data.length == 0) return;
    select.innerHTML = data;

}