 post = function() {
     var url = '';
     var point = '';
     for (var _list = getById('form').getElementsByTagName('SELECT'), i = 0; i < _list.length; i++) {
         url = _list[i].name+"="+_list[i].value+point+url;
         point = '&';
     }
     for (var _list = getById('form').getElementsByTagName('INPUT'), i = 0; i < _list.length; i++) {
         url = _list[i].name+"="+_list[i].value+point+url;
     }
     if (!getById('cat')) {
        getById('formPost').submit();
        return 1;
     }
     _req = new xmlHttp.create();
     _req.onreadystatechange = post.result; 
     _req.open("POST", '/ajax/index.php?'+url+'&r'+Math.random(), true);
     _req.send(null);


 }
 post.uri = function(_href) {
     _req = new xmlHttp.create();
     _req.onreadystatechange = post.result; 
     _req.open("POST", '/ajax/index.php?'+_href, true);
     _req.send(null);

 }

 post.result  = function() {
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('cat').innerHTML = _req.responseText;
     }
  }
 }

 var vbLeft = '';
 var vbRight = '';
 var _stopMovePriceLine = '';
 var _select_area = '';
 var _select_type = '';
 var _kf = '';
 var _loadAreaId = '';
 var _loadTypeId = '';
 var _loadNumId = '';
 var _kf = '';
 var _select_nType = '';
 var _loadNTypeId = '';
 var sEl_x='';
 disabled = function(div) {
  for (var _list = getById(div).getElementsByTagName('SELECT'), i = 0; i < _list.length; i++) _list[i].disabled = true;
  for (var _list = getById(div).getElementsByTagName('INPUT'), i = 0; i < _list.length; i++) _list[i].disabled = true;
 }

 enable = function(div) {
  for (var _list = getById(div).getElementsByTagName('SELECT'), i = 0; i < _list.length; i++) _list[i].disabled =false;
  for (var _list = getById(div).getElementsByTagName('INPUT'), i = 0; i < _list.length; i++) _list[i].disabled =false;
 }

 enable.li = function(div) {
  for (var _list = getById('li_select').getElementsByTagName('LI'), i = 0; i < _list.length; i++) _list[i].className = '';
  getById(div).className = "hover";
 }



 db = function(){
 }






 db.select = function(_command, id){
 //Загородная недвижимость
   if (_command == 'select_zn') {
      vbLeft=0;
      vbRight=0;
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_zn; 
      _req.open("GET", '/ajax/index.php?command='+_command+'&r'+Math.random(), true);
      _req.send(null);
      enable.li('li_select_zn');
      if (getById('cat')) getById('cat').innerHTML = "";
      _kf = 100000;
   }
   if (_command == 'select_zn_area') {
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_zn_area; 
      if (id == 14 || id == 16) {
         _kf = 1000000;
      }
      if (id == 15 || id == 17) {
         _kf = 1000;
      }
      _select_area = id;
      _req.open("GET", '/ajax/index.php?command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);

   }






 //Квартиры
   if (_command == 'select_kv') {
      vbLeft=0;
      vbRight=0;
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_kv; 
      _req.open("GET", '/ajax/index.php?command='+_command+'&r'+Math.random(), true);
      _req.send(null);
      enable.li('li_select_kv');
      if (getById('cat')) getById('cat').innerHTML = "";
      _kf = 1000000;
   }

   if (_command == 'select_kv_area') {
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_kv_area; 
      _select_area = id;
      if (id == 1 || id == 11) {
       _kf = 1000000;
      }
      if (id == 10) {
       _kf = 1000;
      }
      _req.open("GET", '/ajax/index.php?command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);

   }
   if (_command == 'select_kv_kk') {
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_kv_kk; 
      _req.open("GET", '/ajax/index.php?_select_area='+_select_area+'&command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);
   }



 //Земля

   if (_command == 'select_zm') {
      vbLeft=0;
      vbRight=0;
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_zm; 
      _req.open("GET", '/ajax/index.php?command='+_command+'&r'+Math.random(), true);
      _req.send(null);
      enable.li('li_select_zm');
      if (getById('cat')) getById('cat').innerHTML = "";
      _kf = 1000000;
   }
   if (_command == 'select_zm_area') {
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_zm_area; 
      _select_area = id;
      _req.open("GET", '/ajax/index.php?command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);
   }

 //Коммерческая недвижиомсть
   if (_command == 'select_kn') {
      vbLeft=0;
      vbRight=0;

      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_kn; 
      _req.open("GET", '/ajax/index.php?command='+_command+'&r'+Math.random(), true);
      _req.send(null);
      enable.li('li_select_kn');
      if (getById('cat')) getById('cat').innerHTML = "";
      _kf = 1000000;
   }
   if (_command == 'select_kn_area') {
      if (id == 12) {
       _kf = 1000000;
      }
      if (id == 13) {
       _kf = 1000;
      }
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_kn_area; 
      _select_area = id;
      _req.open("GET", '/ajax/index.php?command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);
   }


 //Гаражи
   if (_command == 'select_gr') {
      vbLeft=0;
      vbRight=0;

      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_gr; 
      _req.open("GET", '/ajax/index.php?command='+_command+'&r'+Math.random(), true);
      _req.send(null);
      enable.li('li_select_gr');
      if (getById('cat')) getById('cat').innerHTML = "";
      _kf = 100000;
   }
   if (_command == 'select_gr_area') {
      _req = new xmlHttp.create();
      _req.onreadystatechange = db.select.select_gr_area; 
      _select_area = id;
      _req.open("GET", '/ajax/index.php?command='+_command+'&id='+id+'&r'+Math.random(), true);
      _req.send(null);

   }

 }



db.select.select_zm = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('form').innerHTML = _req.responseText;
        disabled('form');
        enable('select_zm_type');

     // загрузить тип
        if (_loadTypeId != '') {
           db.select.index('select_zm_type', _loadTypeId);
           db.select('select_zm_area', _loadTypeId);
           _loadTypeId='';
        }



     }
  }
}

db.select.select_zm_area = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('select_zm_area').innerHTML = _req.responseText;
        disabled('form');
        enable('select_zm_type');
        enable('select_zm_area');
        enable('search');
        drowNum();
        price.move();
     // загрузить район
        if (_loadAreaId != '') {
           db.select.index('select_zm_area', _loadAreaId);
           _loadAreaId='';
        }



     }
  }
}







db.select.select_zn = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('form').innerHTML = _req.responseText;
        disabled('form');
        enable('select_zn_type');


     // загрузить тип
        if (_loadTypeId != '') {
           db.select.index('select_zn_type', _loadTypeId);
           db.select('select_zn_area', _loadTypeId);
           _loadTypeId='';
        }



     }
  }
}

db.select.select_zn_area = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('select_zn_area').innerHTML = _req.responseText;
        disabled('form');
        enable('select_zn_type');
        enable('select_zn_area');
        enable('search');
        drowNum();
        price.move();
     // загрузить район
        if (_loadAreaId != '') {
           db.select.index('select_zn_area', _loadAreaId);
           _loadAreaId='';
        }



     }
  }
}













db.select.select_gr = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('form').innerHTML = _req.responseText;
        disabled('form');
        enable('select_gr_type');

     // загрузить тип
        if (_loadTypeId != '') {
           db.select.index('select_gr_type', _loadTypeId);
           db.select('select_gr_area', _loadTypeId);
           _loadTypeId='';
        }



     }
  }
}

db.select.select_gr_area = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('select_gr_area').innerHTML = _req.responseText;
        disabled('form');
        enable('select_gr_type');
        enable('select_gr_area');
        enable('search');
        drowNum();
        price.move();
     // загрузить район
        if (_loadAreaId != '') {
           db.select.index('select_gr_area', _loadAreaId);
           _loadAreaId='';
        }



     }
  }
}

























db.select.select_kn = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('form').innerHTML = _req.responseText;
        disabled('form');
        enable('select_kn_type');

     // загрузить тип

        if (_loadTypeId != '') {
           db.select.index('select_kn_type', _loadTypeId);
           db.select('select_kn_area', _loadTypeId);
           _loadTypeId='';
        }



     }
  }
}

db.select.select_kn_area = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('select_kn_area').innerHTML = _req.responseText;
        disabled('form');
        enable('select_kn_type');
        enable('select_kn_area');
        enable('search');
        drowNum();
        price.move();
     // загрузить район
        if (_loadAreaId != '') {
           db.select.index('select_kn_area', _loadAreaId);
           _loadAreaId='';
        }



     }
  }
}


















db.select.select_kv_area = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {

        getById('select_kv_area').innerHTML = _req.responseText;
        disabled('form');
        enable('select_kv_type');
        enable('select_kv_area');
        db.select('select_kv_kk', 0);
        drowNum();
        price.move();
     // загрузить район
        if (_loadAreaId) {
           db.select.index('select_kv_area', _loadAreaId);
           db.select('select_kv_kk', _loadAreaId);
           _loadAreaId='';
        }

     }
  }
}
db.select.select_kv = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('form').innerHTML = _req.responseText;
        disabled('form');
        enable('select_kv_type');

     // загрузить тип
        if (_loadTypeId) {
           db.select.index('select_kv_type', _loadTypeId);
           db.select('select_kv_area', _loadTypeId);
           _loadTypeId='';
        }


     }
  }
}
db.select.select_kv_kk = function(){
  if (_req.readyState == 4) {
     if (_req.status == 200) {
        getById('select_kv_kk').innerHTML = _req.responseText;
        enable('search');

     // загрузить кк
        if (_loadNumId != '') {
           db.select.index('select_kv_kk', _loadNumId);
           _loadNumId = '';

        }

     }
  }
}



db.select.index = function(div, value){
 for (var _list = getById(div).getElementsByTagName('SELECT'), i = 0; i < _list.length; i++) {
     var count = 0;
     var selectedIndex = 0;
     for (var _listOptions = _list[i].getElementsByTagName('OPTION'), iO = 0; iO < _listOptions.length; iO++) {

         if (_listOptions[iO].value == value) selectedIndex = count;
         count++;
     }
     _list[i].selectedIndex = selectedIndex;

 }
}

















  function showImg(_id, _img, $file, $width, $height) {
           window.open("/file.php?img="+$file,'Tip','menubar=no,location=no,toolbar=no,resizable=no,scrollbars=no,status=no,width='+$width+',height='+$height+'');
  }


  function showPrint(url) {
           window.open(url,'Tip','menubar=no,location=no,toolbar=no,resizable=no,scrollbars=yes,status=yes,width=700,height=600');
  }


 function getById(id) {
          if (id && document.getElementById(id)) return document.getElementById(id);
 }

 function pp_hidden_all() {
          for (var _list_div = getById('cld').getElementsByTagName('DIV'), i = 0; i < _list_div.length; i++) {
               if (_list_div[i].className == 'img') {
                  _list_div[i].style.visibility = "hidden";
                  //getById('logoVS').innerHTML += _list_div[i].className;
               }
          } 
 }
 function pp_show(id, href) {
          pp_hidden_all();
          if (id) getById(id).style.visibility = "";
          if (!href) href='#';
          getById('p_line').href = href;



 }





 function t_hidden_all() {
          for (var _list_div = getById('m').getElementsByTagName('DIV'), i = 0; i < _list_div.length; i++) {
               if (_list_div[i].className == 'oDesc') {
                  _list_div[i].style.display = "none";
                  //getById('logoVS').innerHTML += _list_div[i].className;
               }
          } 
 }

 function t_show(id) {
          h_id = "oN"+id;
          id="oD"+id;

          if (getById(id).style.display == 'none') {
             getById(id).style.display = "";
             getById(h_id).className="lh";
          } else {
             getById(id).style.display = "none";
             getById(h_id).className="la";

          }
          return false;

 }




 cat = function(){
   _cat_area  = getById('cat_area');
   _cat_table = getById('cat_table');
   _cat_left  = getById('cat_left');
   _cat_right = getById('cat_right');
   _cat_old_link_id="";
   _cat       = getById('cat');
   _cat_sm_x  = 0;
   _cat_x_start = 0;
   _cat_x_end   = 0;
   _cat_go      = 0;
   _cat_num_row_view  = 1;
   _cat_row_width = 0;
 }

 cat.inRight = function() {
   _cat_sm_x--;
 }

 cat.inLeft = function() {
   _cat_sm_x++;
 }

 cat.calc = function() {
   _cat_row_width = parseInt(_cat_area.offsetWidth/_cat_num_row_view);
   for (var _cat_list_div = getById('cat_list').getElementsByTagName('DIV'), i = 0; i < _cat_list_div.length; i++) {
       _cat_list_div[i].style.width = _cat_row_width+"px"; 
   } 

   _cat_x_start = parseInt(_cat_table.style.left) || 0;
   _cat_x_end   = _cat_row_width * _cat_sm_x;
   _cat_go      = Math.ceil((_cat_x_start + _cat_x_end)/2);
   _cat_table.style.left = _cat_go;

   if (_cat_sm_x == 0) {
      _cat_left.style.visibility = "hidden";
   } else  {
      _cat_left.style.visibility = "visible";
   }
   if (_cat_list_div.length-_cat_num_row_view == _cat_sm_x * -1) {
     _cat_right.style.visibility = "hidden";
   } else  {
    _cat_right.style.visibility = "visible";
   }
   setTimeout("cat.calc()", 1);

 }



xmlHttp = function() {}
xmlHttp.create = function(){
if (window.XMLHttpRequest) { 
var oXmlHttp = new XMLHttpRequest();
return oXmlHttp;
} else {
var aVersions = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i = 0; i < aVersions.length; i++) {
try {
var oXmlHttp = new ActiveXObject(aVersions[i]);
return oXmlHttp;
} catch (oError) {
//Do nothing
}
}
throw new Error("MSXML is not installed.");
}
}







  function mouseDown(event, _this, prefix){

           registerEvent('mousemove', mouseMove);
           registerEvent('mouseup', mouseUp);
           if (prefix == 'left') {
              min_x=0;
              max_x=parseInt(getById('bRight').offsetLeft)-10;
           }
           if (prefix == 'right') {
              min_x=parseInt(getById('bLeft').offsetLeft)+10;
              max_x=215;
           }




           sEl = _this;
           sEl_x = parseInt(sEl.style.left) || 0;

           start_x=event.clientX;

           if (window.event) return false; else event.preventDefault();

  }


 function mouseUp(event){
           unregisterEvent('mousemove', mouseMove);
           unregisterEvent('mouseup', mouseUp);


 }
 function drowNum() {
       getById('pStart').value="0";
       getById('pEnd').value=">"+number_format(_kf*10, 0, '', ' ');
 }

 price = function() {
  _price = getById('bLeft').offsetLeft+"|"+getById('pStart').value+"|"+getById('bRight').offsetLeft+"|"+getById('pEnd').value+"|"+_kf;
  getById('priceLine').value = _price;

 }
 price.move = function() {

 
     if (vbLeft || vbRight) {
        getById('bLeft').style.left = vbLeft;
        getById('bRight').style.left = vbRight;
        getById('iLine').style.left  = parseInt(vbLeft)+4;
        getById('iLine').style.width = parseInt(vbRight)-parseInt(getById('bLeft').offsetLeft);


        _pStartV = Math.ceil(parseInt(getById('iLine').style.left)/215 * 100)/10;
        if (_pStartV <= '0.2') _pStartV = 0;
        getById('pStart').value = number_format(_pStartV*_kf, 0, '', ' ');



        _pEndV = Math.ceil(parseInt(getById('bRight').offsetLeft)/215 * 100)/10;
        if (_pEndV >= '10') {
           _r = ">";
        } else {
           _r = "";
        }
        getById('pEnd').value = _r+number_format(_pEndV*_kf, 0, '', ' '); 



       _stopMovePriceLine=1;
 

  }

 }


 function mouseMove(event) {
           if (window.event) event = window.event;
              _x=sEl_x + event.clientX - start_x;
              if (_x > max_x) _x=max_x;
              if (_x < min_x) _x=min_x;
              if (!_kf) _kf=1;
              if (_x) sEl.style.left=_x;


           vbLeft=getById('bLeft').offsetLeft;
           vbRight=getById('bRight').offsetLeft;
           getById('iLine').style.left  = parseInt(getById('bLeft').offsetLeft)+4;
           getById('iLine').style.width = parseInt(getById('bRight').offsetLeft)-parseInt(getById('bLeft').offsetLeft);

           _pStartV = Math.ceil(parseInt(getById('iLine').style.left)/215 * 100)/10;
           if (_pStartV <= '0.2') _pStartV = 0;
           getById('pStart').value = number_format(_pStartV*_kf, 0, '', ' ');

           _pEndV = Math.ceil(parseInt(getById('bRight').offsetLeft)/215 * 100)/10;
           if (_pEndV >= '10') {
              _r = ">";
           } else {
              _r = "";
           }

           getById('pEnd').value = _r+number_format(_pEndV*_kf, 0, '', ' '); 

           if (window.event) return false; else if (event)  event.preventDefault();
 }




  function registerEvent(eventName, functionName) {
           if (document.attachEvent) {
              document.attachEvent ('on' + eventName, functionName);
           } else if (document.addEventListener) {
              document.addEventListener (eventName, functionName, true);
           }
  }

  function unregisterEvent(eventName, functionName) {
           if (document.detachEvent) {
              document.detachEvent ('on' + eventName, functionName);
           } else if (document.removeEventListener) {
              document.removeEventListener(eventName, functionName, true);
           }
  }

  function number_format( number, decimals, dec_point, thousands_sep ) {
      var i, j, kw, kd, km;
      if( isNaN(decimals = Math.abs(decimals)) ){
          decimals = 2;
      }
      if( dec_point == undefined ){
          dec_point = ",";
      }
      if( thousands_sep == undefined ){
          thousands_sep = ".";
      }
      i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
   
      if( (j = i.length) > 3 ){
          j = j % 3;
      } else{
          j = 0;
      }
   
      km = (j ? i.substr(0, j) + thousands_sep : "");
      kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
      kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
      return km + kw + kd;
  }

