var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isFF = (!isIE && !(navigator.appVersion.indexOf("MSIE")>-1));
var isOPR = (navigator.userAgent.indexOf("Opera")!=-1);
var isIE6 = navigator.userAgent.indexOf("MSIE 6.0") >= 0;
var isIE7 = navigator.userAgent.indexOf("MSIE 7.0") >= 0;
var isIE8 = navigator.userAgent.indexOf("MSIE 8.0") >= 0;
if (isOPR) { isIE = false; }

    var today = new Date();
    var lastId = today.getTime();
    function getNewId()
         {
         lastId++;
         return "window_id_"+lastId;
         }

    function checkTagForm()
         {
         if (document.getElementById('ac_update').style.display=='block')
                 return false;
         else
                 return true;
         }

    function autoCompleteInit(rubric)
             {
            try {  new Ajax.Autocompleter('tag','ac_update','/api/lenta/_autocomplete_result.html?rubric_id='+rubric, {afterUpdateElement : function(){return false}}); }
             catch (e) { }
             }

    function sliderInit()
             {
             try { new Control.Slider('handle_track','ruller_track',{sliderValue:1,onSlide:function(v){moveLine(v)}}); }
             catch (e) { }
             }

    function vacancyTab(obj)
         {
         id = obj.id.replace(/z(1|2|3|4|5)([0-9]*)$/, '$2');
         z = obj.id.replace(/z(1|2|3|4|5)([0-9]*)$/, '$1');

         try { document.getElementById('z1'+id).className='zakladka_sr'; } catch (e) {}
         try { document.getElementById('z2'+id).className='zakladka_sr'; } catch (e) {}
         try { document.getElementById('z3'+id).className='zakladka_sr'; } catch (e) {}
         try { document.getElementById('z4'+id).className='zakladka_sr'; } catch (e) {}
         try { document.getElementById('z5'+id).className='zakladka_sr'; } catch (e) {}
         
         xz = Math.round(z)+1;
         while ( xz<=5)
         {
         	try { document.getElementById('z'+xz+id).className='zakladka_sl'; } catch (e) {}
         	xz++
         }
         
         
         try { document.getElementById('zt1'+id).style.display='none'; } catch (e) {}
         try { document.getElementById('zt2'+id).style.display='none'; } catch (e) {}
         try { document.getElementById('zt3'+id).style.display='none'; } catch (e) {}
         try { document.getElementById('zt4'+id).style.display='none'; } catch (e) {}
         try { document.getElementById('zt5'+id).style.display='none'; } catch (e) {}

         try { document.getElementById('z'+z+id).className='zakladka_a'; } catch (e) {}
         try { document.getElementById('zt'+z+id).style.display='block'; } catch (e) {}
         }


    function moveLine(v)
             {
      //       alert(document.getElementById('dates').offsetWidth);
             var newMargin = -1*(document.getElementById('num_dates').value*26-document.getElementById('dates').offsetWidth)*(1-v);
             newMargin = newMargin.toString() + 'px';
             document.getElementById('scroll_dates').style.marginRight=newMargin;
             }


    function fotoFull(file,w,h)
         {
         var infoWin = new Dialog.info({url: '/win/foto.html?file='+file, options: {method: 'get'}},
                           {windowParameters: {className: "nashi", width:w, height:h, draggable:false, resizable: false}}
                           );
         }
    function fotoFree(file,title,w,h)
         {
         try {
         var infoWin = new Dialog.info({url: '/win/freefoto.html?filename='+file+'&title='+encodeURIComponent(title), options: {method: 'get'}},
                           {windowParameters: {className: "nashi", width:w, height:h, draggable:false, resizable: false}}
                           );
         } catch (e) {}
         }

    function advertFull(id)
         {
         var infoWin = new Dialog.info({url: '/win/adv.html?id='+id, options: {method: 'get'}},
                           {windowParameters: {className: "nashi", width:400, height:300, draggable:false, resizable: false}}
                           );
         }

    function videoFull(fileId,w,h)
         {
         tmpWin = getNewId();
         win = new Window(tmpWin, {url:'/win/video.html?id='+fileId, classname:'nashi', width:w, height:h, scrolling:'no', minimizable:false, maximizable:false, resizable:false});
         win.setDestroyOnClose();
         win.setZIndex(10);
         win.toFront();
         win.showCenter('modal');
         }


            function getWay(cl)
                  {
                  switch (cl)
                      {
                      case 'f1':
                           return 60;
                      case 'f2':
                           return 40;
                      case 'f3':
                           return 50;
                      case 'f4':
                           return 35;
                      }
                  }
            function getZIndex(cl)
                  {
                  switch (cl)
                      {
                      case 'f1':
                           return 4;
                      case 'f2':
                           return 3;
                      case 'f3':
                           return 2;
                      case 'f4':
                           return 1;
                      }
                  }

            function f_show(obj)
                  {
                  if (isOPR) { obj.style.zIndex=10; return false; }
                  if (!obj.effectMove && obj.style.zIndex!=10) obj.effectMove = Effect.MoveBy( obj, 0, getWay(obj.className), {afterFinish: function() { obj.style.zIndex=10; f_left(obj) }, duration: 0.3});
                  }

            function f_hide(obj)
                  {
                  if (isOPR) {obj.style.zIndex=getZIndex(obj.className); return false}
                  if (!obj.effectMove) obj.effectMove = Effect.MoveBy( obj, 0, getWay(obj.className), {afterFinish: function() { obj.style.zIndex=getZIndex(obj.className); f_left(obj) }, duration: 0.3});
                  }

            function f_left(obj)
                  {
                  new Effect.MoveBy( obj, 0, -getWay(obj.className), {afterFinish: function() { obj.effectMove=''; }, duration: 0.3});
                  }


                var a=0;
                var b=-550;
                var t;
                var tf;
                function line()
                        {  document.getElementById('f').style.bottom='-550px'
                           document.getElementById('bl').style.display='block'
                           a+=5;
                           document.getElementById('bl').style.width=a+'px'
                           if (a<270){t=setTimeout('line()', 1)} else { clearTimeout(t); form(); a=0; }
                        }
                function form()
                {
                   document.getElementById('f').style.bottom=b+'px'
                   b+=5
                   if (b<0) {tf=setTimeout('form()',1)} else {clearTimeout(tf); b=-550}
                }



var xPos = 0;
var yPos = 0;
var showProgress = true;




if (isFF)
     {
     document.onmousedown = function(e)
          {
          xPos = e.pageX;
          yPos = e.pageY;
          }
     }
else
     {
     document.onmousedown = function()
          {
          xPos = event.clientX + document.body.scrollLeft;
          yPos = event.clientY + document.body.scrollTop;
          }
     }


function startProgress()
      {
      document.getElementById('cursorProgress').style.left = xPos + 15;
      document.getElementById('cursorProgress').style.top = yPos + 0;
      document.onmousemove = moveProgressImage;
      document.getElementById('cursorProgress').style.display = "block";
      }




function moveProgressImage()
      {
      if (isFF)
          {
          document.onmousemove = function(e)
              {
              document.getElementById('cursorProgress').style.left = e.pageX + 15;
              document.getElementById('cursorProgress').style.top = e.pageY + 0;
              }
          }
      else
          {
          document.getElementById('cursorProgress').style.posLeft = event.clientX + document.body.scrollLeft + 15;
          document.getElementById('cursorProgress').style.posTop = event.clientY + document.body.scrollTop + 0;
          }
      return false;
      }

function stopProgress()
      {
      document.getElementById('cursorProgress').style.display = "none";
      document.onmousemove = null;
      }


if (isOPR) { isIE = false; }

var firstStarted = false;
var secondStarted = false;
var toSub = false;
var popOpened = false;
var popupCount = 0;

var firstTop = 0;
var secondTop = 0;
var thirdTop = 0;

function clearSelected()
         {
         firstStarted = false;
         secondStarted = false;
         firstTop = 0;
         secondTop = 0;
         thirdTop = 0;
         }


function getAbsolutePos(el)
         {
         var r = { x: el.offsetLeft, y: el.offsetTop };
         if (el.offsetParent)
            {
                var tmp = getAbsolutePos(el.offsetParent);
                r.x += tmp.x;
                r.y += tmp.y;
            }
         return r;
         }


function askQuestion(name,contact,text,page)
         {
         if (!/[А-яA-z]/.exec(name.value))
             {
             alert('Укажите своё имя!')
             name.focus();
             return false;
             }
         if (!/[А-яA-z]/.exec(contact.value))
             {
             alert('Укажите свои координаты!')
             contact.focus();
             return false;
             }
         if (!/[А-яA-z]/.exec(text.value))
             {
             alert('Напишите ваш вопрос!')
             text.focus();
             return false;
             }
         document.getElementById('ask_form').style.display='none';
         lookup({url:'/feedback.api.php', postFunction:'window.setTimeout("smartCloseMessageSender();", 1500);', values:'name='+encodeURIComponent(name.value)+'&contact='+encodeURIComponent(contact.value)+'&text='+encodeURIComponent(text.value)+'&page='+encodeURIComponent(page.value), dest:'ans_form'});

         name.value='';
         contact.value='';
         text.value='';
         }

function sendToEmail(email)
         {
         if (!/^[A-z][A-z0-9._-]{1,30}[A-z0-9]?@[A-z][A-z0-9._-]{0,16}[A-z0-9]\.[A-z]{2,4}$/.exec(email))
              alert('Введённый вами адрес неправильный!');
         else
              lookup({url:'/feedback.api.php', values:'email='+email, dest:'emailCont'});
         }


function sendAnketa2(){
	if(!document.getElementById('a_title').value){
		alert('Введите ваше имя!');
		document.getElementById('a_title').focus();
		return false;
	}
	if(!document.getElementById('a_org').value){
		alert('Введите название организации!');
		document.getElementById('a_org').focus();
		return false;
	}
	if(!document.getElementById('a_email').value){
		alert('Введите ваш email!');
		document.getElementById('a_email').focus();
		return false;
	}
	var working_time=new Object();
	working_time.address=document.getElementsByName('working_time[address][]');
	working_time.phone=document.getElementsByName('working_time[phone][]');
	working_time.time=document.getElementsByName('working_time[time][]');
	working_time.data=new Array();
	for(var i=0;i<working_time.address.length;i++){
		if(working_time.address[i].value && working_time.phone[i].value){
			working_time.data[working_time.data.length]='working_time[address][]='+working_time.address[i].value;
			working_time.data[working_time.data.length]='working_time[phone][]='+working_time.phone[i].value;
			working_time.data[working_time.data.length]='working_time[time][]='+working_time.time[i].value;
		}
	}
	if(working_time.data.length){
		working_time.data='&'+working_time.data.join('&');
	}else{
		alert('Вам необходимо указать координаты хотя бы одного офиса!');
		return false;
	}
	document.getElementById('job_form').action='/work/feedback.anketas.html';
	document.getElementById('job_form').submit();
	//lookup({url:'/feedback.api.php',values:'anketas=1&title='+document.getElementById('a_title').value+'&org='+document.getElementById('a_org').value+'&description='+document.getElementById('a_description').value+'&email='+document.getElementById('a_email').value+'&site='+document.getElementById('a_site').value+'&card='+(document.getElementById('a_card').checked?'Y':'N')+working_time.data});
}

function sendAnketa()
         {
         if (!document.getElementById('a_title').value) {
                 alert('Введите ваше имя!');
                 document.getElementById('a_title').focus();
                 return false;
         }
         if (!document.getElementById('a_org').value) {
                 alert('Введите название организации!');
                 document.getElementById('a_org').focus();
                 return false;
         }
         if (!document.getElementById('a_description').value) {
                 alert('Введите описание деятельности!');
                 document.getElementById('a_description').focus();
                 return false;
         }
         if (!document.getElementById('a_address').value) {
                 alert('Введите фактический адрес!');
                 document.getElementById('a_address').focus();
                 return false;
         }
         if (!document.getElementById('a_phone').value) {
                 alert('Введите ваш телефон!');
                 document.getElementById('a_phone').focus();
                 return false;
         }
         if (!document.getElementById('a_email').value) {
                 alert('Введите ваш email!');
                 document.getElementById('a_email').focus();
                 return false;
         }

         lookup({url:'/feedback.api.php', values:'anketas=1&title='+document.getElementById('a_title').value+'&org='+document.getElementById('a_org').value+'&description='+document.getElementById('a_description').value+'&address='+document.getElementById('a_address').value+'&phone='+document.getElementById('a_phone').value+'&email='+document.getElementById('a_email').value+'&site='+document.getElementById('a_site').value+'&card='+(document.getElementById('a_card').checked?'Y':'N'), dest:'rr'});

         alert('Ваша заявка отправлена, спасибо!');

         document.getElementById('a_title').value = '';
         document.getElementById('a_org').value = '';
         document.getElementById('a_description').value = '';
         document.getElementById('a_address').value = '';
         document.getElementById('a_phone').value = '';
         document.getElementById('a_email').value = '';
         document.getElementById('a_site').value = '';
         document.getElementById('a_card').checked = false;

         document.getElementById('ank_im').alt='+';
         document.getElementById('ank_im').src='/images/plus.gif';
         document.getElementById('bl').style.display='none';
         document.getElementById('h2').style.display='none';

         }

function sendToPhone(code1,code2,code3,code4)
         {
         phone = code1.toString()+code2.toString()+code3.toString()+code4.toString();
         if (
              !/^[0-9]{3,5}$/.exec(code1) ||
              !/^[0-9]{1,3}$/.exec(code2) ||
              !/^[0-9]{1,2}$/.exec(code3) ||
              !/^[0-9]{1,2}$/.exec(code4)
            )
              alert('Введённый вами телефон неправильный!');
         else
              lookup({url:'/feedback.api.php', values:'phone='+phone, dest:'phoneCont'});
         }

function smartCloseMessageSender()
         {
         if (document.getElementById('ans_form').style.display=='block')
             {
             document.getElementById('f_q').style.display='none';
             document.getElementById('deal').style.display='block';
             document.getElementById('ans_form').style.display='none';
             document.getElementById('ask_form').style.display='block';
             }
         }

function closeMessageSender()
         {
         document.getElementById('f_q').style.display='none';
         document.getElementById('deal').style.display='block';

         document.getElementById('ans_form').style.display='none';
         document.getElementById('ask_form').style.display='block';
         }

function openMessageSender()
         {
         document.getElementById('f_q').style.display='block';
         document.getElementById('deal').style.display='none';

         document.getElementById('ans_form').style.display='none';
         document.getElementById('ask_form').style.display='block';
         }

function secDivAdjust(res)
         {
         if (res)
             {
             try { document.getElementById('second').id = 'second2'; }
             catch (e) { }
             try { document.getElementById('sec_br').style.display = 'none'; }
             catch (e) { }
             }
         }

function activateFirst(obj,id,sw)
         {
         document.getElementById('first_name').innerHTML = '<span>1</span>категория';
         
         if (!sw)
             {
             try { document.getElementById('sec_br').style.display = 'block'; }
             catch (e) { }
             }
         try {
               document.getElementById('fraze').innerHTML = '';
               document.getElementById('fraze').style.position='absolute';
               document.getElementById('fraze').style.pixelLeft='0px';
               document.getElementById('fraze').style.pixelTop='0px'; }
         catch (e) { }

         closeMessageSender();

         try { if (!sw) document.getElementById('second2').id = 'second'; }
         catch (e) { }

         if (firstStarted == true) document.getElementById('first_'+selFirstObj.id).innerHTML = selFirstObj.innerHTML;
         selFirstObj = {innerHTML:obj.parentNode.innerHTML, id:id};

         firstSel = obj.parentNode;
         pos = getAbsolutePos(firstSel);
         firstTop = pos.y;


         var firstTabsNodesList = firstSel.parentNode.childNodes;
         for (i=0; i<firstTabsNodesList.length; i++)
             {
             if (firstTabsNodesList[i].nodeName == 'DIV')
                 {
                 firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_unbord', 'right_bord');
		 		 //firstTabsNodesList[i].style.paddingBottom = false;
		 		// firstTabsNodesList[i].style.paddingTop = false;
				firstTabsNodesList[i].style.paddingBottom = '12px';
                 }
             }
	 	 obj.parentNode.style.paddingBottom = '0px';
	 	 obj.parentNode.style.paddingTop = '0px';
         obj.parentNode.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" id="selected_f"><tr><td class="cell_arrow"><img alt=">" src="/images/arrow.gif" /></td><td class="cell_link">'+obj.innerHTML+'</td></tr></table>';
         firstStarted = true;

         if (sw) return false;

         document.getElementById('third').innerHTML = '';
         topfunc = "lookup({url:'/tops.api.php', postFunction:'secDivAdjust(http.responseText); analizeThird()', values:'category_id="+id+"', dest:'third'});";

         document.getElementById('second').innerHTML = '';
         if (toSub)
              {
              lookup({url:'/subcategories.api.php', postFunction:'document.getElementById(\'subcategory_'+toSub+'\').onclick();', values:'id='+id, dest:'second'});
              toSub = false;
              }
         else
              {
              lookup({url:'/subcategories.api.php', values:'id='+id, postFunction:topfunc, dest:'second'});
              }
         secondStarted = false;

         try { document.getElementById('second').innerHTML = '<h3 class="col_name"><span>2</span>ещё</h3><div class="t_cats"><img alt="Часы" src="/images/wait.gif" class="wait"><span class="loading">идёт загрузка</span></div>'; }
         catch (e) { document.getElementById('second2').innerHTML = '<h3 class="col_name"><span>2</span>ещё</h3><div class="t_cats"><img alt="Часы" src="/images/wait.gif" class="wait"><span class="loading">идёт загрузка</span></div>'; }
         }

var bannerCont;
function bContent()
{
	if($('bs_content')){
		bannerCont = $('bs_content').innerHTML;
	}
}

function analizeThird(){
	if($('third').innerHTML==''&&bannerCont){
		$('third').innerHTML='<div class="bs" id="bs_content" style="text-align:center; margin-right:-70px; margin-top:50px; position:relative;">'+bannerCont+'</div>';
	}
}

function activateSecond(obj,id,sw)
         {
         if (!sw)
             {
             try { document.getElementById('sec_br').style.display = 'none'; }
             catch (e) { }
             }
         try {
               document.getElementById('fraze').innerHTML = '';
               document.getElementById('fraze').style.position='absolute';
               document.getElementById('fraze').style.pixelLeft='0px';
               document.getElementById('fraze').style.pixelTop='0px';
                   }
         catch (e) { }

         closeMessageSender();

         try { if (!sw) document.getElementById('second').id = 'second2'; }
         catch (e) { }

         if (secondStarted == true) document.getElementById('second_'+selSecondObj.id).innerHTML = selSecondObj.innerHTML;
         selSecondObj = {innerHTML:obj.parentNode.innerHTML, id:id};

         if (document.documentElement.scrollTop>285) self.scrollTo(0,225);

         var firstTabsNodesList = firstSel.parentNode.childNodes;
         for (i=0; i<firstTabsNodesList.length; i++)
             {
             if (firstTabsNodesList[i].nodeName == 'DIV')
                 {
                 firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                 }
             }
         var secondTabsNodesList = obj.parentNode.parentNode.childNodes;
         for (i=0; i<secondTabsNodesList.length; i++)
             {
             if (secondTabsNodesList[i].nodeName == 'DIV')
                 {
                 secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                 secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_unbord', 'right_bord');
                 }
             }

         obj.parentNode.innerHTML = '<div class="cell_link">'+obj.innerHTML+'</div>';
         secondSel = document.getElementById('second_'+selSecondObj.id);
         pos = getAbsolutePos(secondSel);
         secondTop = pos.y;
         firstOffset = secondTop-firstTop;



         pos = getAbsolutePos(firstSel);
         lastFirstOffset = pos.y;

         for (i=secondTabsNodesList.length-1; i>=0; i--)
                 {
                 if (secondTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(secondTabsNodesList[i]);
                     lastSecondOffset = pos.y;
                     break;
                     }
                 }

      //   alert(lastFirstOffset+' '+lastSecondOffset);

         if (lastFirstOffset < lastSecondOffset)
             document.getElementById('last_sec').style.display = 'none';
         else
             document.getElementById('last_sec').style.display = 'block';

         if (firstOffset >= 0) /* -_ */
             {
             for (i=0; i<secondTabsNodesList.length; i++) /* --> */
                 {
                 if (secondTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(secondTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset <= secondTop && tmpOffset >= firstTop)
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('left_unbord', 'left_bord');
                         }
                     else
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                         }
                     }
                 }
             for (i=0; i<firstTabsNodesList.length; i++) /* <-- */
                 {
                 if (firstTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(firstTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset+firstTabsNodesList[i].offsetHeight <= secondTop+secondSel.offsetHeight && tmpOffset >= firstTop)
                         {
                         firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_unbord', 'right_bord');
                         }
                     else
                         {
                         firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                         }
                     }
                 }
             firstSel.className = firstSel.className.replace('right_unbord', 'right_bord');
             secondSel.className = secondSel.className.replace('left_unbord', 'left_bord');
             }
         else  /* _- */
             {
             for (i=0; i<secondTabsNodesList.length; i++) /* --> */
                 {
                 if (secondTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(secondTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset+secondTabsNodesList[i].offsetHeight <= firstTop && tmpOffset >= secondTop)
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('left_unbord', 'left_bord');
                         }
                     else
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                         }
                     }
                 }
             for (i=0; i<firstTabsNodesList.length; i++) /* <-- */
                 {
                 if (firstTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(firstTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset <= firstTop && tmpOffset >= secondTop)
                         {
                         firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_unbord', 'right_bord');
                         }
                     else
                         {
                         firstTabsNodesList[i].className = firstTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                         }
                     }
                 }
             firstSel.className = firstSel.className.replace('right_unbord', 'right_bord');
             secondSel.className = secondSel.className.replace('left_unbord', 'left_bord');
             }


         secondStarted = true;

         if (sw) return false;

         document.getElementById('third').innerHTML = '<h3 class="col_name"><span>3</span>организация</h3><div class="t_cats"><img alt="Часы" src="/images/wait.gif" class="wait"><span class="loading">идёт загрузка</span></div>';
         lookup({url:'/organizations.api.php', values:'id='+id, dest:'third'});
         }

function activateThird(obj,id)
         {
//         document.getElementById('sec_br').style.display = 'block';

         closeMessageSender();

/*
         thirdSel = obj.parentNode.parentNode;
         pos = getAbsolutePos(thirdSel);
         thirdTop = pos.y;
         secondOffset = thirdTop-secondTop;


         var secondTabsNodesList = secondSel.parentNode.childNodes;
         for (i=0; i<secondTabsNodesList.length; i++)
             {
             if (secondTabsNodesList[i].nodeName == 'DIV')
                 {
                 secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                 }
             }
         var thirdTabsNodesList = obj.parentNode.parentNode.parentNode.childNodes;
         for (i=0; i<thirdTabsNodesList.length; i++)
             {
             if (thirdTabsNodesList[i].nodeName == 'DIV')
                 {
                 thirdTabsNodesList[i].className = thirdTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                 }
             }

         if (secondOffset >= 0)
             {
             for (i=0; i<thirdTabsNodesList.length; i++)
                 {
                 if (thirdTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(thirdTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset <= thirdTop && tmpOffset >= secondTop)
                         {
                         thirdTabsNodesList[i].className = thirdTabsNodesList[i].className.replace('left_unbord', 'left_bord');
                         }
                     else
                         {
                         thirdTabsNodesList[i].className = thirdTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                         }
                     }
                 }
             for (i=0; i<secondTabsNodesList.length; i++)
                 {
                 if (secondTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(secondTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset+secondTabsNodesList[i].offsetHeight <= thirdTop && tmpOffset >= secondTop)
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_unbord', 'right_bord');
                         }
                     else
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                         }
                     }
                 }
             secondSel.className = secondSel.className.replace('right_unbord', 'right_bord');
             thirdSel.className = thirdSel.className.replace('left_unbord', 'left_bord');
             }
         else
             {
             for (i=0; i<thirdTabsNodesList.length; i++)
                 {
                 if (thirdTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(thirdTabsNodesList[i]);
                     tmpOffset = pos.y;
                     if (tmpOffset+thirdTabsNodesList[i].offsetHeight <= secondTop+secondSel.offsetHeight && tmpOffset >= thirdTop)
                         {
                         thirdTabsNodesList[i].className = thirdTabsNodesList[i].className.replace('left_unbord', 'left_bord');
                         }
                     else
                         {
                         thirdTabsNodesList[i].className = thirdTabsNodesList[i].className.replace('left_bord', 'left_unbord');
                         }
                     }
                 }
             for (i=0; i<secondTabsNodesList.length; i++)
                 {
                 if (secondTabsNodesList[i].nodeName == 'DIV')
                     {
                     pos = getAbsolutePos(secondTabsNodesList[i]);
                     tmpOffset = pos.y;
      //               alert(tmpOffset+'<='+secondTop+' && '+tmpOffset+'>='+thirdTop);
                     if (tmpOffset <= secondTop && tmpOffset >= thirdTop)
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_unbord', 'right_bord');
                         }
                     else
                         {
                         secondTabsNodesList[i].className = secondTabsNodesList[i].className.replace('right_bord', 'right_unbord');
                         }
                     }
                 }
             secondSel.className = secondSel.className.replace('right_unbord', 'right_bord');
             thirdSel.className = thirdSel.className.replace('left_unbord', 'left_bord');
             }
*/
         }

function activateOnReturn(category_id,subcategory_id){
	activateFirst(document.getElementById("category_"+category_id),category_id);
	window.setTimeout(function(){
		activateSecond(document.getElementById("subcategory_"+subcategory_id),subcategory_id);
	},1234)
}


var closePop = true;
var popClose;
var popOpened = false;
function popup_close(a)
        {
        try { document.getElementById('popup_'+a).style.display='none'; }
        catch (e) { popOpened = false; return false; }
        popOpened = false;
        return true;
        }

function popup_open(a)
        {
        if (popOpened) popup_close(popOpened);
        document.getElementById('popup_'+a).style.display='block';
        popOpened = a;
        popupCount = 1;
        }


document.onclick = function()
        {
		//if (!popClose) { popClose = true; return false; }
        if (popOpened && popupCount==0) { popup_close(popOpened); }
        else popupCount = 0;

        }


var oncl = new Array();

function menuSwitch2(obj,classname)
      {
      var menuNodesList = obj.parentNode.childNodes;
      for (i=0; i<menuNodesList.length; i++)
           {
           if (menuNodesList[i].nodeName == 'A')
                {
                menuNodesList[i].className = '';
                try
                   {
                   menuNodesList[i].onclick = oncl[menuNodesList[i].id].onclick;
                   menuNodesList[i].href = oncl[menuNodesList[i].id].href;
                   }
                catch (e)
                   {
                   // sdf
                   }
                }
           }
      oncl[obj.id] = {onclick:obj.onclick, href:obj.href};
      obj.onclick = function() { return false; }
      obj.href = null;
      obj.className = classname;
      }

function menuSwitch(params)
      {
      if (!params.silent) params.silent = false;
      if (params.silent == false)
           {
           if (!/(.+)\.(.+)/.exec(document.title))
                document.title = params.obj.innerHTML + '. ' + document.title;
           else
                document.title = document.title.replace(/(.+)\.(.+)/, params.obj.innerHTML+'.$2');
           }
      var menuNodesList = params.obj.parentNode.childNodes;
      for (i=0; i<menuNodesList.length; i++)
           {
           if (menuNodesList[i].nodeName == 'A')
                {
                menuNodesList[i].className = params.classname;
                }
           }
      params.obj.className = params.classname+'Active';
      }


function startProgress()
      {
      document.getElementById('cursorProgress').style.left = xPos + 15;
      document.getElementById('cursorProgress').style.top = yPos + 0;
      document.onmousemove = moveProgressImage;
      moveProgressImage();
      document.getElementById('cursorProgress').style.display = "block";
      }




function moveProgressImage()
      {
      if (isFF)
          {
          document.onmousemove = function(e)
              {
              document.getElementById('cursorProgress').style.left = e.pageX + 15;
              document.getElementById('cursorProgress').style.top = e.pageY + 0;
              }
          }
      else
          {
          document.getElementById('cursorProgress').style.posLeft = event.clientX + document.body.scrollLeft + 15;
          document.getElementById('cursorProgress').style.posTop = event.clientY + document.body.scrollTop + 0;
          }
      return false;
      }

function stopProgress()
      {
      document.getElementById('cursorProgress').style.display = "none";
      document.onmousemove = null;
      }



function getHTTP()
      {
      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 lookupProcess(lookupSettings)
      {
      if (!lookupSettings) lookupSettings = new Object();

      if (!lookupSettings.values)         lookupSettings.values   = '';
      if (!lookupSettings.postFunction)   lookupSettings.postFunction   = '';
      if (!lookupSettings.dest)           lookupSettings.dest = false;
  /*
      try {
          destHeight = document.getElementById(lookupSettings.dest).offsetHeight;
          document.getElementById(lookupSettings.dest).innerHTML = "<div>&nbsp;</div>";
          document.getElementById(lookupSettings.dest).style.height = destHeight;
          }
      catch (e) { destObj = false; }
  */
      if (lookupSettings.url)
           {
           this.working = false;
           if (!this.working && (this.http = getHTTP()))
                {
                if (showProgress) startProgress();
                var http = this.http;
                this.http.open("POST", lookupSettings.url, true);
                this.http.onreadystatechange = function()
                     {
                     if (http.readyState == 4)
                          {
                          if (showProgress) stopProgress();
                          showProgress = true;
                          re = /^Location: ([a-zA-Z0-9._-]+)/;
                          ReLocation = re.exec(http.responseText);
                          try { destObj = document.getElementById(lookupSettings.dest); }
                          catch (e) { destObj = false; }
                          if ( !ReLocation && destObj )
                               {
                               destObj.style.display = "block";
                               destObj.style.height = '';
                               destObj.innerHTML = http.responseText;
                               if (lookupSettings.postFunction) eval(lookupSettings.postFunction);
                               }
                          else
                               {
                               if ( ReLocation )
                                    {
                                    document.location.href = ReLocation[1];
                                    }
                               else
                                    {
                                    return http.responseText;
                                    }
                               }
                          this.working = false;
                          this.http = false;
                          }
                     }
                this.working = true;
                this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.http.send(lookupSettings.values);
                }
           if(!this.http)
                {
                alert('Ошибка при создании XMLHTTP объекта. Ваш браузер не поддерживается системой!')
                }
           }
      }

function lookup(lookupSettings)
      {
      if (!lookupSettings) lookupSettings = new Object();

      if (!lookupSettings.values)         lookupSettings.values   = '';
      if (!lookupSettings.postFunction)   lookupSettings.postFunction   = '';
      if (!lookupSettings.dest)           lookupSettings.dest = false;

      if (lookupSettings.url)
           {
           this.working = false;
           if (!this.working && (this.http = getHTTP()))
                {
//                if (showProgress) startProgress();
                var http = this.http;
                this.http.open("POST", lookupSettings.url, true);
                this.http.onreadystatechange = function()
                     {
                     if (http.readyState == 4)
                          {
//                          if (showProgress) stopProgress();
//                          showProgress = true;
                          re = /^Location: ([a-zA-Z0-9._-]+)/;
                          ReLocation = re.exec(http.responseText);
                          try { destObj = document.getElementById(lookupSettings.dest); }
                          catch (e) { destObj = false; }
                          if ( !ReLocation && destObj )
                               {
                               destObj.style.display = "block";
                               destObj.innerHTML = http.responseText;
                               if (lookupSettings.postFunction) eval(lookupSettings.postFunction);
                               }
                          else
                               {
                               if ( ReLocation )
                                    {
                                    document.location.href = ReLocation[1];
                                    }
                               else
                                    {
                                    return http.responseText;
                                    }
                               }
                          this.working = false;
                          this.http = false;
                          }
                     }
                this.working = true;
                this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.http.send(lookupSettings.values);
                }
           if(!this.http)
                {
                alert('Ошибка при создании XMLHTTP объекта. Ваш браузер не поддерживается системой!')
                }
           }
      }


function lookup2(lookupSettings)
      {
      if (!lookupSettings) lookupSettings = new Object();

      if (!lookupSettings.values)         lookupSettings.values   = '';
      if (!lookupSettings.postFunction)   lookupSettings.postFunction   = '';
      if (!lookupSettings.dest)           lookupSettings.dest = false;

      if (lookupSettings.url)
           {
           this.working = false;
           if (!this.working && (this.http = getHTTP()))
                {
//                if (showProgress) startProgress();
                var http = this.http;
                this.http.open("POST", lookupSettings.url, true);
                this.http.onreadystatechange = function()
                     {
                     if (http.readyState == 4)
                          {
//                          if (showProgress) stopProgress();
//                          showProgress = true;
                          re = /^Location: ([a-zA-Z0-9._-]+)/;
                          ReLocation = re.exec(http.responseText);
                          alert(http.responseText);
                          try { destObj = document.getElementById(lookupSettings.dest); }
                          catch (e) { destObj = false; }
                          if ( !ReLocation && destObj )
                               {
                               destObj.style.display = "block";
                               destObj.innerHTML = http.responseText;
            //                   if (lookupSettings.postFunction) postFunction;
                               }
                          else
                               {
                               if ( ReLocation )
                                    {
                                    document.location.href = ReLocation[1];
                                    }
                               else
                                    {
                                    return http.responseText;
                                    }
                               }
                          this.working = false;
                          this.http = false;
                          }
                     }
                this.working = true;
                this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.http.send(lookupSettings.values);
                }
           if(!this.http)
                {
                alert('Ошибка при создании XMLHTTP объекта. Ваш браузер не поддерживается системой!')
                }
           }
      }



function urlEncodeById(text_id){
	textValue = document.getElementById('value'+text_id).value;
	textValue = encodeURIComponent(textValue);
	return textValue;
}

function advertsSubRubrics(el){
	var value=el;
	document.getElementById('select_rubric_id').value='';
	document.getElementById('div-rubrics-select').innerHTML='';
	document.getElementById('auto_add').style.display='none';
	document.getElementById('ad_price').style.display='none';
	document.getElementById('ad_mark').style.display='none';
	document.getElementById('ad_text').style.height='78px';
	document.getElementById('adverts_text').style.height='82px';
	document.getElementById('adverts_text_p').style.height='82px';
	if(value.indexOf('-subrubrics')>0){
		value=value.replace('-subrubrics','');
		lookup({url:'/api/adverts.rubrics.api.php',values:'id='+value,dest:'div-rubrics-select'});
	}else{
		document.getElementById('select_rubric_id').value=value;
	}
}

function advertsSubRubricsSelected(el){
	document.getElementById('auto_add').style.display='none';
	document.getElementById('ad_price').style.display='none';
	document.getElementById('ad_mark').style.display='none';
	var value=el;
	if(value.indexOf('-price')>0){
		value=value.replace('-price','');
		document.getElementById('auto_add').style.display='block';
		document.getElementById('ad_price').style.display='inline';
		document.getElementById('ad_price').style.width='216px';
	}
	if(value.indexOf('-mark')>0){
		value=value.replace('-mark','');
		document.getElementById('auto_add').style.display='block';
		document.getElementById('ad_mark').style.display='inline';
		document.getElementById('ad_price').style.width='100px';
	}
	document.getElementById('select_rubric_id').value=value;
}

function advertsAddToFavorite(id,del){
	del=typeof del=='undefined'?false:del;
	var destObj=document.getElementById('favorite-span-'+id);
	var http=getHTTP();
	http.open('POST','/api/adverts.favorite.api.php',true);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			var res=http.responseText;
			response=http.responseText.split('[(.)(.)]');
			if(Number(response[0])>0){
				if(document.getElementById('adverts-favorite-menuitem')){
					document.getElementById('adverts-favorite-menuitem').style.display='inline';
				}
				if(del && top.window.location.href.indexOf('bizbi.ru/a/favorite')>1){
					document.getElementById('advert-div-'+id).parentNode.removeChild(document.getElementById('advert-div-'+id));
				}
			}else{
				if(document.getElementById('adverts-favorite-menuitem')){
					document.getElementById('adverts-favorite-menuitem').style.display='none';
				}
				if(top.window.location.href.indexOf('bizbi.ru/a/favorite')>1){
					top.window.location.href='/a/all';
				}
			}
			destObj.style.display="block";
			destObj.innerHTML=response[1];
		}
	}
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send('id='+id+(del?'&type=delete':''));
}

var oldObj = null;
var oldId = null;
function date_del()
{
	f_obj.style.zIndex=f_objZindex;
	document.getElementById('overimg_'+f_id+'_'+f_class).className="overimg";
}
function img_show(obj,id,img_w,img_h)
{
    objZindex = getZIndex(obj.className);
    if(oldObj && oldObj!=obj)
    	{
    		oldObj.style.zIndex=getZIndex(oldObj.className);
    		document.getElementById('overimg_'+oldId+'_'+oldObj.className).className='overimg';
    	}
    if(document.getElementById('overimg_'+id+'_'+obj.className).className=="overimg act_over")
    	{
    		fotoFull(id,img_w,img_h);
    		f_id = id;
    		f_obj = obj;
    		f_objZindex = objZindex;
    		f_class = obj.className;
    		setTimeout("date_del()",1000);
//    		obj.style.zIndex=objZindex;
//    		document.getElementById('overimg_'+id+'_'+obj.className).className="overimg";
    	}
    else
    	{
    		obj.style.zIndex='100';
    		document.getElementById('overimg_'+id+'_'+obj.className).className="overimg act_over";
    		
    	}
    oldObj = obj;
    oldId = id;
}