//AJAX

function lookup(do_it, select_id, url) {
  // Получаем объект XMLHTTPRequest
  this.http=null;
  if(!this.http){
      this.http = get_http();
      this.working = false;
  }
  // Запрос
  if (!this.working && this.http) {
    var http = this.http;
    //добавляем закодированный текст
    //в URL запроса
    url = url + "?bb="+encodeURIComponent(select_id);
    //создаём запрос
    this.http.open("GET", url, true);
    //прикрепляем к запросу функцию-обработчик
    //событий
    this.http.onreadystatechange = function() {
      // 4 - данные готовы для обработки
      if (http.readyState == 4) {
          fill(do_it, http.responseText);
          this.working = false;
      }else{
          document.getElementById(do_it).innerHTML="Загрузка...";
      }
    }
    this.working = true;
    this.http.send(null);
  }
  if(!this.http){
    alert('Ошибка при создании XMLHTTP объекта!')
  }
}

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 fill (do_it, data){
  // поле SELECT в переменную в виде объекта	
  var crossobj = document.getElementById(do_it);
  crossobj.innerHTML=data;
}

function load_search_result(idd) {

  if (!document.getElementById("item_name").value) {
    document.getElementById("items_div").style.visibility='hidden';
  } else {
    //idd = "{$id}";
    if (idd) {
      lookup('items_div', document.getElementById("item_name").value, '/catalog/ajax_search');
    } else {
      lookup('items_div', document.getElementById("item_name").value, '/catalog/ajax_search');
    }
    document.getElementById("items_div").style.visibility='visible';
  }
}

function load_search_result2(idd) {

  if (!document.getElementById("item_name2").value) {
    document.getElementById("items_div2").style.visibility='hidden';
  } else {
    //idd = "{$id}";
    if (idd) {
      lookup('items_div2', document.getElementById("item_name2").value, '/catalog/ajax_search');
    } else {
      lookup('items_div2', document.getElementById("item_name2").value, '/catalog/ajax_search');
    }
    document.getElementById("items_div2").style.visibility='visible';
  }
}

function ShowOrHide(d1, d2) {
  if (d1 != '') DoDiv(d1);
  if (d2 != '') DoDiv(d2);
}

function DoDiv(id) {
  var item = null;
  if (document.getElementById) {
    item = document.getElementById(id);
  } else if (document.all){
    item = document.all[id];
  } else if (document.layers){
    item = document.layers[id];
  }
  if (!item) {
  }
  else if (item.style) {
    if (item.style.display == "none"){ item.style.display = ""; }
    else {item.style.display = "none"; }
  }else{ item.visibility = "show"; }
}

	function OF(where_is, what_is){
		if (where_is.value==what_is) {
			where_is.value=''; 
			where_is.style.color = '#000000';
		}
	}
	
	function OB(where_is, what_is){
		if (where_is.value=='') {
			where_is.value=what_is; 
			where_is.style.color = '#CCCCCC';
		}
	}

