//Для исчезновения

function mySelect(form){
    form.select();
}
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 addSelectedToList_( frmName, srcListName, tgtListName, fieldform ) {
  var form = eval( 'document.' + frmName );
  var srcList = eval( 'form.' + srcListName );
  var tgtList = eval( 'form.' + tgtListName );
  var fieldform_ = eval( 'document.'+frmName+'.' + fieldform );

  var srcLen = srcList.length;
  var tgtLen = tgtList.length;
  var tgt = "x";

  //build array of target items
  for (var i=tgtLen-1; i > -1; i--) {
    tgt += "," + tgtList.options[i].value + ","
  }

  //Pull selected resources and add them to list
  for (var i=srcLen-1; i > -1; i--) {
    if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
      name_resh=srcList.options[i].text.replace('-----','');
      name_resh=name_resh.replace('+++','');
      name_resh=name_resh.replace('----------','');
      opt = new Option( name_resh, srcList.options[i].value );
      tgtList.options[tgtList.length] = opt;						
      fieldform_.value=fieldform_.value+srcList.options[i].value+'|';
    }
  }
}

function delSelectedFromList_( frmName, srcListName, fieldform ) {
  var form = eval( 'document.' + frmName );
  var fieldform_ = eval( 'document.'+frmName+'.' + fieldform );
  var srcList = eval( 'form.' + srcListName );

  var srcLen = srcList.length;

  for (var i=srcLen-1; i > -1; i--) {
    if (srcList.options[i].selected) {
      fieldform_.value=fieldform_.value.replace(srcList.options[i].value+'|','');
      srcList.options[i] = null;
    }
  }
}

//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 + "?id="+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;
}
