     photoShowAttemps = 20;
  var infoDivs = Array();
  function showInfoDiv(id, message){
    if(!infoDivs[id])
      infoDivs[id] = document.createElement("DIV");
    infoDivs[id].className = 'infoDiv';
    infoDivs[id].innerHTML = message;
    //infoDivs[message].attachEvent('onmouseout', 'hideInfoDiv("'+message+'"');
    document.body.appendChild(infoDivs[id]);

  }

  function hideInfoDiv(id){
    infoDivs[id].visibility = 'hidden';
  }

  function showbig(picname){

    window.open('/msk/includes/foto.php5?pic='+picname,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=30,height=30');
  }

  function showMap(mapUrl){
    window.open(mapUrl,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=730,height=470');
  }

   function showSpbMap(mapUrl){
    window.open(mapUrl,'_blank','scrollbars=no,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=561,height=780');
  }

  function PreLoad(source){
    var NewImage = new Image();
    NewImage.src = source;
  }

  function prepareSubmit(frm){
    var len = frm.all("editbox").length; if (!len) len = 1;
    for (var i=0; i<len; i++)
      frm.all("codebox", i).innerText = frm.all("codebox", i).style.display ? borderOn(frm.all("codebox", i).innerText) : borderOn(frm.all("editbox", i).innerHTML);
  }

 function menuProcess(menuId){
   menuId = document.getElementById(menuId);
    if(menuId.style.display == 'none'){
     menuId.style.display = 'block';
   }else{
      menuId.style.display = 'none';
   }
 }

 function changeDisplayState(id) {o=document.getElementById(id); if(o.style.display == 'block'){ o.style.display = 'none'; } else{ o.style.display = 'block';}}

 function btShowFunctionArguments(name){
   btChangeFunctionArgumentsBlock(name,'none','block','block');
 }

 function btHideFunctionArguments(name){
   btChangeFunctionArgumentsBlock(name,'block','none','none');
 }

 function btChangeFunctionArgumentsBlock(name,plus,minus,arguments){
    document.getElementById('backtrace_img_plus_'+name).style.display = plus;
    document.getElementById('backtrace_img_minus_'+name).style.display = minus;
    document.getElementById('backtrace_arguments_'+name).style.display = arguments;
 }


 function showObject(pathToObject){
   window.open(pathToObject,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=510,height=300');
 }

 function ge(id){
   return document.getElementById(id);
 }

 function printSelected(){
   if(ge('obj_form')){
     var ids = new Array();
     var _count = 0;

     form = ge('obj_form');
     objCount = form.elements.length - 1;

     for(i=0; i <= objCount; i++){
       formElement = form.elements[i];
       if(formElement.type && formElement.type == 'checkbox' && formElement.value && formElement.checked){
         ids[_count] =formElement.value;
         _count ++;
       }
     }
     if(ids.lenght == 0){
       alert('Не выбрано не одного объекта!');
       return false;
     }
     newWindow = window.open('','_blank','scrollbars=yes,taskbar=yes,resizeable=yes,status=yes,menubar=yes,top=30,left=30,width=1024,height=1000');
     wDoc = newWindow.document;
     wDoc.write ('<html>');
     wDoc.write ('Загрузка данных...');
     wDoc.write ('<form action="/estate/second/print/" method="POST" id="ids_form">');
     for(i=0 ; ids[i] ; i++)
       wDoc.write ('<input type="hidden" value="' +ids[i] +'" name="id[]">');
    wDoc.write ('</form>');
     wDoc.getElementById('ids_form').submit();;
   }
 }

 onviserLoaded = false;








  function isEmpty(_value){
    return typeof(_value) == 'undefined' || _value == '';
  }

  function setDivHTMLandState(divName,text){
    if(!ge(divName))
      return false;
    if(isEmpty(text)){
      ge(divName).style.display = 'none';
      ge(divName).innerHTML = '';
      return false;
    }else{
      ge(divName).style.display = 'block';
      ge(divName).innerHTML = text;
      return true;
    }
  }






    var objectsTypes = new Array();
    objectsTypes[1] = new Array();
    objectsTypes[1][5] = 'коттеджные посёлки';
    objectsTypes[1][2] = 'дом, дача, коттедж';
    objectsTypes[1][3] = 'участок';
    objectsTypes[2] = new Array();
    objectsTypes[2][3] = 'дом, дача, коттедж';
    objectsTypes[2][4] = 'VIP-коттедж';
    objectsTypes[2][1] = 'квартира';
    objectsTypes[2][2] = 'комната';
    objectsTypes[2][5] = 'участок';

    var actionTypes = new Array();
    actionTypes[1] = new Array();
    actionTypes[2] = new Array();
    actionTypes[1][5] = new Array();
    actionTypes[1][5][1] = 'покупаю дом/участок';
    actionTypes[1][2] = new Array();
    actionTypes[1][2][1] = 'покупаю';
    actionTypes[1][3] = new Array();
    actionTypes[1][3][1] = 'покупаю';
    actionTypes[2][1] = new Array();
    actionTypes[2][1][1] = 'покупаю';
    actionTypes[2][1][3] = 'снимаю';
    actionTypes[2][2] = new Array();
    actionTypes[2][2][1] = 'покупаю';
    actionTypes[2][2][3] = 'снимаю';
    actionTypes[2][3] = new Array();
    actionTypes[2][3][1] = 'покупаю';
    actionTypes[2][3][3] = 'снимаю';
    actionTypes[2][4] = new Array();
    actionTypes[2][4][1] = 'покупаю';
    actionTypes[2][4][3] = 'снимаю';
    actionTypes[2][5] = new Array();
    actionTypes[2][5][1] = 'покупаю';

    function changeSimpleSearchObjectType(){

      c = document.forms.simpleSearch.city.value;
      ot = document.forms.simpleSearch.objectType;
      if(c == 0){
        ot.options.length = 0;
        addSelectElement(ot, 'выберите город', 0);
        addSelectElement( document.forms.simpleSearch.actionType, 'выберите город', 0);
      }else if(c == 1 || c == 2){
        ot.options.length = 0;
        for(var i in objectsTypes[c])
          addSelectElement(ot, objectsTypes[c][i], i);
        changeSimpleSearchActionType();
      }
      //ge('spbDistrictsTbl').style.display = c == 2 ? 'block' : 'none';
    }

    function changeSimpleSearchActionType(){
      c = document.forms.simpleSearch.city.value;
      ot = document.forms.simpleSearch.objectType.value;
      at = document.forms.simpleSearch.actionType;
      at.options.length = 0;
      for(var i in actionTypes[c][ot])
        addSelectElement(at, actionTypes[c][ot][i], i);
    }

    function addSelectElement(o, t, v){ var e = document.createElement('OPTION');o.options.add(e);e.innerHTML = t;e.value = v;}

    function redirectToExtendedSearch(){
      c = document.forms.simpleSearch.city.value;
      ot = document.forms.simpleSearch.objectType.value;
      at = document.forms.simpleSearch.actionType.value;

      //sd = document.forms.simpleSearch.spbDistricts.value;
      if(c == 0){ alert('Выберите город!'); return;
      }else if(c == 1){
        url = false;
        if(ot == 5) url = '/msk/estate/settlements/search';
        if(ot == 2) url = '/msk/estate/country/search/?objectType=1';
        if(ot == 3) url = '/msk/estate/country/search/?objectType=2';
        if(url)
          location.href = url ;
        return false;
      }else if(c == 2){
        uri = 'http://pon.ru/params.php?agentobject='+ot+'&agentoperation='+at;//+'&agentregion='+sd;
        location.href = uri;


      }
    }

    function doSimpleSearch(){
      c = document.forms.simpleSearch.city.value;
      if(document.forms.simpleSearch.mskDistricts)
        d = c== 1 ? document.forms.simpleSearch.mskDistricts.value : false;
      else
        d = false;
      ot = document.forms.simpleSearch.objectType.value;
      at = document.forms.simpleSearch.actionType.value;
      // sd = document.forms.simpleSearch.spbDistricts.value;

      if(c == 0){ alert('Выберите город!'); return;
      }else if(c == 1){
        url = false;
        if(ot == 5) url = '/msk/estate/settlements/';
        if(ot == 2) url = '/msk/estate/country/cottages/';
        if(ot == 3) url = '/msk/estate/country/grounds/';
        if(url)
          location.href = url + (d ? '?raion=' + d : '');
      }else if(c == 2){
        uri = 'http://pon.ru/find.php?agentobject='+ot+'&agentoperation='+at;//+'&agentregion='+sd;
        location.href = uri;
      }
    }


    function validateCommmentsForm(form){
      if(form.u_name.value == ''){
        alert('Введите имя!');
        return false;
      }

      if(form.u_email.value == ''){
        alert('Введите e-mail!');
        return false;
      }

      if(form.u_text.value == ''){
        alert('Вы, кажется, забыли комментарий!');
        return false;
      }

      return true;
    }


 function removeComment(id){

   cTd = ge('comment_td_' + id);
   if(!cTd || !window.confirm('Вы уверены?')) return false;
   cTd.style.backgroundColor = '';
   cTd.innerHTML = 'удаляеться...';

    JsHttpRequest.query(
            '/msk/comments/delete/' + id + '/ajax/?noMainIndex=true',
            {
                'id':id
            },
            function(result, errors) {
              if(result['st']){
                id = result['id'];
                cTd = ge('comment_td_'+ id);
                cTd.innerHTML = '';
                cTd.style.display = 'none';
              }
            },
            true
        );
 }

