﻿//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("image_col").style.visibility='hidden';
    document.getElementById("image_col").innerHTML="";
    strat_fotos_slogans();
  } else {
    //idd = "{$id}";
    if (idd) {
      lookup('image_col', document.getElementById("item_name").value, '/catalog/ajax_search');
    } else {
      lookup('image_col', document.getElementById("item_name").value, '/catalog/ajax_search');
    }
    document.getElementById("image_col").style.visibility='visible';
  }
}

function strat_fotos_slogans() {
 init('image_col', 'slogans_container',[
			'/image2.jpg',
			'/image3.jpg',
			'/image4.jpg',
			'/image5.jpg',
			'/image2.jpg'
			], ['<span class="png slider-text"> <a href="/	perevozki_negabaritnih_gruzov" style="color: #FFF;">Вывоз снега с территории</a></span>','<span class="png slider-text"> <a href="/	perevozki_negabaritnih_gruzov" style="color: #FFF;">Уборка строительного мусора</a></span>','<span class="png slider-text" style="color: #FFF;"><a href="/	perevozki_negabaritnih_gruzov">Уборка и вывоз производственных отходов</a></span>','<span class="png slider-text"><!--Горящие предложения: подробности по тел. +7(343)251-54-44, +7(343)376-74-40--></span>','<span class="png slider-text"><!--Горящие предложения: подробности по тел. +7(343)251-54-44, +7(343)376-74-40--></span>',]
	  
	  , '/images','navigate');
}

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';
		}
	}


