
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 lookupx(text, select_id, url, tp) {
   if(text!='') {
      if(tp == "help"){fillx(select_id, '<div style="text-align: center; padding: 5px;"><img src="/images/ajax-loaderh.gif"></div>');}
      else{fillx(select_id, '<div style="background: #f0f0f0 url(../images/s_tl.gif) left top no-repeat;"><div style="background: url(../images/s_tl.gif) left top no-repeat;"></div></div><div style="text-align: center; padding: 5px;"><img src="/images/ajax-loader.gif"></div><div style="background: #f0f0f0 url(../images/s_bl.gif) left bottom no-repeat;"><div style="background: url(../images/s_br.gif) right bottom no-repeat;"><br /></div></div>');}
   }


		if(!this.http){
            this.http = get_http();
            this.working = false;
        }
		else{
			this.working = false;
		}


        if (!this.working && this.http) {
//			alert("x");
            var http = this.http;
            if (text.length <1 ) return;
            url = url + "?ajax=" + tp +"&text="+encodeURIComponent(text);
//alert(url);
            this.http.open("GET", url, true);
            this.http.onreadystatechange = function() {
                if (http.readyState == 4) {
//                    alert(http.responseText);
                    fillx(select_id, http.responseText);
                    this.working = false;
                }else{
					//alert("wait");
                     // данные в процессе получения,
                     // можно повеселить пользователя
                     //сообщениями
                     // ЖДИТЕ ОТВЕТА
                }
            }
            this.working = true;
            this.http.send(null);
        }
        if(!this.http){
              alert('Ошибка при создании XMLHTTP объекта!')
        }
}

function fillx (select_id, data){
    var select = document.getElementById(select_id);
    select.innerHTML = data;
}



function hdiv(dID) { 
	if (document.getElementById) { 
		document.getElementById(dID).style.visibility = 'hidden'; 
	} 
} 

function sdiv(dID) { 
	if (document.getElementById) {
		document.getElementById(dID).style.visibility = 'visible'; 
	} 
} 
