//JavaScript Document
var init_left=0;
var init_top=0;
var radioCheck = function(name){
    jQuery(':radio[name="' + name + '"]').each(function(){
        jQuery(this).not(jQuery(this)).attr('checked', false);
        jQuery(this).parent().eq(0).addClass('radio-unchecked').removeClass('radio-checked');
    })
}
function apply_validate ( selector, func_if_ok )
{
  jQuery(selector).each( function() {
    jQuery(this).submit(function () {
    ext=false; /// glogal scope, appears in validate.js
    var validationError = false;
    jQuery("input, select, textarea", this).each( function() {
      if (jQuery(this).attr("class")) {
        if (!validateField(this))
          validationError = true;
      }
    });
    if(ext) idex=jQuery('#errormtexa'); else idex=jQuery('#errormt');
    if(validationError) {
      jQuery(idex).show();
    } else {
      jQuery(idex).hide();
    }
    if(!validationError&&func_if_ok) return func_if_ok();
    return !validationError;
    });
    jQuery("input, select, textarea", this).each( function() {
      if (jQuery(this).attr("class")) {
        jQuery(this).blur( function() { validateField(this) } );
      }
    });
  });
}
function apply_helps ( selector )
{
  jQuery(selector).each(function(){
    jQuery(this).click(function(event){
      a=$(this);
      w=jQuery(this);
      if($(this).attr('rel')=='no') return;
      jQuery('#dhelp').hide();
      $('#helpcontents').load("/act.php?a=load_help&id="+$(a).attr('id'),function(res){
        p=w.position();
        l=event.pageX-5+'px';
        t=event.pageY-20+'px';
        jQuery('#dhelp').css({'top':t,'left':l});
        a.attr('rel',1);
        //event.stopPropagation();
        jQuery('#dhelp').show();
        //event.preventDefault();
      });
    });
  });
}
jQuery().ready(function(){
    $('.defjs').each(function(){
      if($(this).val()=='') return;
      $(this).focus(function(){
        $(this).attr('tmp',$(this).val());
        $(this).val('');
      }).blur(function(){
        if($(this).attr('tmp')!='' && $(this).val()!='' && $(this).val()!=$(this).attr('tmp'))
          return;
        else $(this).val($(this).attr('tmp'));
      });
    });
    
    $('#appte, #comp_only').change(function(){
      $('#f_arh').submit();
    });
    jQuery('#town_lists').change(function()
    {
      jQuery('#cities .slider').hide();
      var thisId = '#' + jQuery(this).val() + '_list_slider';
      jQuery(thisId).show();
    })
    jQuery('#refresh_cap').click(function(){
      var r=Math.floor(Math.random()*101);
      jQuery('#captcha').attr('src','/img.php?r='+r);
    });
    apply_validate(".formValidate");
    /** * radio buttons ** */
    jQuery(':radio').each(function(){
        if (jQuery(this).attr('disabled') == true) {
            jQuery(this).parent('.radio-check').eq(0).addClass('radio-disabled').removeClass('radio-unchecked');
        }
        else 
            if (jQuery(this).attr('checked') == true) {
                jQuery(this).parent('.radio-check').eq(0).addClass('radio-checked').removeClass('radio-unchecked');
            }
                jQuery(this).click(function(){
                radioCheck(jQuery(this).attr('name'));
                jQuery(this).parent().eq(0).addClass('radio-checked').removeClass('radio-unchecked');
            })
    })
    /** * /radio buttons/ ** */
    jQuery(':checkbox').each(function(){
        if (jQuery(this).attr('disabled') == true) {
            jQuery(this).parent('.radio-check').eq(0).addClass('check-disabled').removeClass('check-unchecked');
        }
        else 
            if (jQuery(this).attr('checked') == true) {
                jQuery(this).parent('.radio-check').eq(0).addClass('check-checked').removeClass('check-unchecked');
            }
                jQuery(this,jQuery(this).parents('form')).click(function(){
            (jQuery(this).attr('checked')) ? jQuery(this).parent('.radio-check').eq(0).addClass('check-checked').removeClass('check-unchecked') : jQuery(this).parent('.radio-check').eq(0).removeClass('check-checked').addClass('check-unchecked')
            //alert(1)
        //if(jQuery(this).attr('id')=='appte') {$('#f_arh').submit();}
        })
        
    })
    jQuery('a', '#accord').each(function(){
        if ($(this).attr('href')=='#' && $(this).attr('rel')=='') 
            $(this).css({
                color: '#000'
            });
        $(this).click(function(event){
            if($(this).hasClass('selrel') && $(this).attr('rel')!='') document.location=$(this).attr('rel');
            if ($(this).next('ul').length > 0) {
                event.preventDefault();
            }
            $(this).addClass('selrel');
            $(this).next().show('slow');
            $('ul', $(this).parent().siblings()).hide('slow');
            $('a', $(this).parent().siblings()).removeClass('selrel');
        })
    })
    /** * just trying jQuery.fn ** */
    jQuery.fn.extend({
        foldTree: function(){
            jQuery(this).each(function(){
                jQuery(this).hide();
            })
        }
    })
    jQuery('ul', '#accord').foldTree();
    /* #1 my change */
    jQuery('a', '#accord').each(function(){
        if ($(this).next('ul').length > 0 && $(this).next('ul').attr('rel')=='open') {
            //$(this).addClass('selected');
            $(this).next().show('slow');
            //$('ul', $(this).parent().siblings()).hide('slow');
            //$('a', $(this).parent().siblings()).removeClass('selected');
        }
    })
    /* #1 my change */
    /* and it works ;) */
    function jqOpen(ref){
        if (jQuery(ref) + ':hidden') {
            jQuery(ref).show();
        } else jQuery(ref).hide();
    }
    jQuery('#opener').click(function(event){
        jqOpen('#cabinet');
        event.preventDefault();
    })
    
    jQuery('#city').text(jQuery('#citiesSelect option:selected').text());
    
    jQuery('#city').click(function(event){
        jQuery('#cities').toggle();
        w=jQuery('#cities');
        if(!w.attr('rel')) {
          p=w.position();
          l=p['left']+(w.width()/2)+'px';
          t=p['top']-(w.height()/2)-70+'px';
          $('#cities').css({"top":t,"left":l});
          w.attr('rel',1);
        }
        event.preventDefault();
    })
    jQuery('a', '#cities .cities').each(function(){
        if (jQuery(this).attr('id') ==
        jQuery('#citiesSelect').attr('value')) {
            jQuery(this).parents('.slider').show();
            jQuery(this).css('color', '#f63');
        }
        jQuery(this).click(function(event){
            jQuery('#city').text(jQuery(this).text());
            jQuery('#cities').hide();
            jQuery('#citiesSelect').attr('value', jQuery(this).attr('id'));
            jQuery(this).parents('form').submit();
            event.preventDefault();
        })
    })
    /** * image changer ** */
    $('a', '.changer').each(function(){
        $(this).bind('click', function(event){
            event.preventDefault();
            $('#preview').attr('src', $(this).attr('href'));
            $(this).siblings().removeClass('selected');
            $(this).addClass('selected');
        })
    })
    /** * select ** */
    
    $('option:selected').each(function(){
        var id = $(this).attr('value');
        $('.typetext', $(this).parents('.select-uni')).text($(this).text());
    })
    $('.select-uni:not(.select-uied)').each(function(){
        $(this).addClass("select-uied");
        $(this).hover(function(){
            $(this).addClass('active');
            $(this).removeClass('passive');
        }, function(){
            $(this).removeClass('active');
            $(this).addClass('passive');
        })
        $(this).bind('click', function(event){
            event.stopPropagation();
        })
        $('a', $(this)).each(function(i){
            $(this).bind('click', function(event){
                if($(this).hasClass('loadcity')) {
                  $('#toloadcity').removeClass("select-uied");
                  $('#toloadcity').load("/act.php?a=load_city_to&id="+jQuery(this).attr('rel'),function(){initA();});
                }
                $('select', $(this).parents('.select-uni')).val($(this).text());
                $('.typetext', $(this).parents('.select-uni')).text($(this).text());
                $('.typetext', $(this).parents('.select-uni')).attr('title', $(this).text());
                $('select', $(this).parents('.select-uni')).attr('value', $(this).attr('rel'));
                $('select', $(this).parents('.select-uni')).change();
                $('.opt-list', $(this).parents('.select-uni')).css('visibility', 'hidden');
                $(this).parents('.select-uni').css('z-index', '1');
                $(this).parents('#f_arh').submit();
                event.preventDefault();
            })
        })
        jQuery('.bg-l', $(this)).each(function(){
            $(this).click(function(event){
                show=false;
                el=$(this).next(':hidden');
                if (el.css('visibility')=="hidden") show=true;
                hideSelect(this);
                if (show) {
                  el.css('visibility', 'visible');
                  $(this).parents('.select-uni').css('z-index', '3');
                }
            })
        })
    })
        
    
    $(document).bind('click', function(){
        $('.opt-list').each(function(){
            $(this).css('visibility', 'hidden');
        })
        $('#slider').hide('slow');
        jQuery('.aim', '#catalog-choice').foldTree();
        jQuery('.jawohl > .selected').removeClass('selected');
    })
    jQuery('.aim', '#catalog-choice').each(function(){
        jQuery(this).bind('click', function(event){
            event.stopPropagation();
        })
    })
    //jQuery('#results').tablesorter({
    //    cssDesc: 'sorted',
    //    cssAsc: 'sorted'
    //});
    //jQuery('#catalog-choice').tablesorter({
    //    cssDesc: 'sorted',
    //    cssAsc: 'sorted'
    //});
    jQuery('th', '.results').each(function(){
        $(this).hover(function(){
            $(this).addClass('thover');
        }, function(){
            $(this).removeClass('thover');
        })
    })
    jQuery('.ico-close,.less-param').each(function(){
        jQuery(this).click(function(event){
            if(jQuery(this).hasClass('action-default')) return true;
            $('.error_Box').hide();
            jQuery(this).parents('.aim').hide();
            event.preventDefault();
        })
    })
    $('#log').focus(function(event){
        $('#slider').show('slow');
    })
    $('.login-box').eq(0).bind('click', function(event){
        event.stopPropagation();
    })
    $('.input-uni').each(function(){
        if ($(this).hasClass('input-login')) {
            $('input.typetext', $(this)).eq(0).focus(function(){
                $(this).parents('.input-uni').removeClass('input-login');
            });
            $('input.typetext', $(this)).eq(0).blur(function(){
                $(this).parents('.input-uni').addClass('input-login');
            })
        }
    })
    jQuery('.aim', '#catalog-choice').foldTree();
    jQuery('.jawohl .ico-close').each(function(){
        jQuery(this).click(function(){
            jQuery('.error_Box').hide();
            jQuery('.jawohl > .selected').removeClass('selected');
        })
    })
    
    jQuery('.jawohl > a.adop').each(function(){
        jQuery(this).click(function(event){
            a=$(this);
            if($(this).attr('rel')=='no') return;
            jQuery('.jawohl > a.selected').removeClass("selected");
            jQuery(this).toggleClass('selected');
            jQuery('.aim', '#catalog-choice').hide();
            if (jQuery(this).hasClass('selected')) {
                jQuery('.aim', jQuery(this).parent()).show();
                w=jQuery('.aim', jQuery(this).parent());
                if(!a.attr('rel')) {
                  p=w.position();
                  l=p['left']-w.width()+30+'px';
                  t=p['top']-(w.height()/2)+'px';
                  jQuery('.aim', jQuery(this).parent()).css({'top':t,'left':l});
                  a.attr('rel',1);
                }
                event.stopPropagation();
            }
            else {
                jQuery('.aim', jQuery(this).parent()).hide();
            }
            event.preventDefault();
            //event.stopPropagation();
        })
    })
    apply_helps('span.help,img.help');
    /*
    jQuery('span.help,img.help').each(function(){
        jQuery(this).click(function(event){
            a=$(this);
            w=jQuery(this);
            if($(this).attr('rel')=='no') return;
            jQuery('#dhelp').hide();
            $('#helpcontents').load("/act.php?a=load_help&id="+$(a).attr('id'),function(res){
              p=w.position();
              l=event.pageX-5+'px';
              t=event.pageY-20+'px';
              jQuery('#dhelp').css({'top':t,'left':l});
              a.attr('rel',1);
              //event.stopPropagation();
              jQuery('#dhelp').show();
              //event.preventDefault();
            });
        });
    });
    */
    if(jQuery('#ecol').val()=='1') {
    jQuery('.coledit').each(function(){
        $(this).css('cursor','pointer');
        jQuery(this).click(function(event){
            a=$(this);
            w=jQuery(this);
            if($(this).attr('rel')=='no') return;
            jQuery('#dnamecol').hide();
            $('#namecolcontents').load("/act.php?a=load_editcol&id="+$(a).attr('relid'),function(res){
              p=w.position();
              l=event.pageX-5+'px';
              t=event.pageY-20+'px';
              jQuery('#dnamecol').css({'top':t,'left':l});
              //event.stopPropagation();
              jQuery('#dnamecol').show();
              //event.preventDefault();
            });
        });
    });
    }
    
    function searchCheck(){
        jQuery(':checkbox', '.divisions').each(function(){
            $(this).attr('disabled', '');
            jQuery(this).parent('.radio-check').eq(0).removeClass('check-disabled');
        })
    }
    function searchUncheck(){
        jQuery(':checkbox', '.divisions').each(function(){
            $(this).attr('disabled', 'disabled');
            jQuery(this).parent('.radio-check').eq(0).addClass('check-disabled');
        })
    }
    jQuery(':radio', '.search-page').each(function(){
        jQuery('#divisions').attr('checked') == true ? searchCheck() : searchUncheck();
        $(this).click(function(){
            jQuery('#divisions').attr('checked') == true ? searchCheck() : searchUncheck();
        })
    });
        jQuery('#open-add-filter').click(function(event){
                jQuery('.error_Box').hide(); 
                jQuery('#add-filter').show();
                var coords = jQuery('#brief-filter').offset();
                jQuery('#add-filter').css({
                        left:coords.left - 27 + 'px',
                        top:coords.top - 22 + 'px'
                })
                event.preventDefault();
                
        })
})
jQuery(document).ready(function(){
        jQuery('#obertka').removeClass('jsoff');        
})
jQuery(document).ready(function(){
        jQuery('thead th','table.results').each(function(i){
                jQuery(this).click(function(){
                        //jQuery('tfoot > tr > td','table.results').removeClass('sorted');
                        //jQuery('tfoot > tr > td').eq(i).addClass('sorted');
        
                        if($(this).attr("rel")) {
                        if($("#urls").val().indexOf('?')>=0)
                          window.location=$("#urls").val()+"&order="+$(this).attr("rel");
                        else
                          window.location=$("#urls").val()+"?order="+$(this).attr("rel");
                        }
                })
        })
})
jQuery(document).ready(function(){
    jQuery('.slider-box').each(function(i){
        jQuery(':checkbox', this).each(function(){
                        if(jQuery(this).attr('checked') == true) {
                                jQuery('.slider-box .slider').eq(i).show();
                        }
                        jQuery(this).click(function(){
                                p=$(this); p0=false;
                                while($(p).length&&!$(p).is('body'))
                                {
                                  if($(p).is('.slider-box')) { p0=p; break; }
                                  p=$(p).parent();
                                }
                                if(jQuery(this).attr('checked') == true) {
                                        if(p0) $(p0).addClass("pad2x");
                                        jQuery('.slider-box .slider').eq(i).slideDown('normal',function(){
                                          $('.error_Box').each(function(){
                                            var id=$(this).attr('rel');
                                            if($('#'+id).css('display')=='inline' || $('#'+id).css('display')=='inline-block') {
                                              validateField('#'+id);
                                              //eOffset = $('#'+id).offset();
                                              //$(this).css({ top: eOffset.top + 13, left: eOffset.left + 25});
                                            }
                                          });
                                        });
                                        
                                } else if (jQuery(this).attr('checked') == false) {
                                      if(p0) $(p0).removeClass("pad2x");
                                      jQuery('.slider-box .slider').eq(i).slideUp('normal',function(){        
                                        $('.error_Box').each(function(){
                                          var id=$(this).attr('rel');
                                          if($('#'+id).css('display')=='block' || $('#'+id).css('display')=='inline' || $('#'+id).css('display')=='inline-block') {
                                            validateField('#'+id);
                                            eOffset = $('#'+id).offset();
                                            if(!eOffset.left) $(this).remove();
                                            //else
                                            //$(this).css({ top: eOffset.top + 13, left: eOffset.left + 25 });
                                          } else $(this).hide();
                                        });
                                      });
                                        
                                }
                                
                        })
        })
    })
})
jQuery(document).ready(function(){
        jQuery('#dopabon').change(function(){
        })
        function changeRel(id, relId){
                jQuery(id).change(function(){
                        if(jQuery(this).val() == 'y'){
                                jQuery(relId).attr('disabled',false);
                                jQuery(relId).parents('.input-uni').removeClass('input-disabled');
                        } else {
                                jQuery(relId).attr('disabled',true);
                                //jQuery(relId).val('');
                                jQuery(relId).parents('.input-uni').addClass('input-disabled');
                        }
                })
        }
        changeRel('#dopabon','#maxa');
        changeRel('#tarId','#vol1');
        $('#dopabon').change();
})
jQuery(document).ready(function(){
        //checkAll('#operators-list');
        function checkAll(id){
                jQuery(':checkbox',id).each(function(){
                        jQuery(this).attr('checked',true);
                        jQuery(this).parent('.radio-check').eq(0).removeClass('check-unchecked').addClass('check-checked');
                })
        }
        function uncheckAll(id){
                jQuery(':checkbox',id).each(function(){
                        jQuery(this).attr('checked',false);
                        jQuery(this).parent('.radio-check').eq(0).removeClass('check-checked').addClass('check-unchecked');
                })
        }
        function checkOneByOne(id){
                var l =jQuery(':checkbox',id).length;
                jQuery(':checkbox',id).each(function(){
                        jQuery(this).click(function(){
                                var n = jQuery("input:checked", id).length;
                                if( n < l ){
                                        jQuery('#operators').attr('checked',false);
                                        jQuery('#operators').parent('.radio-check').eq(0).removeClass('check-checked').addClass('check-unchecked');
                                } else if (n == l) {
                                        jQuery('#operators').attr('checked',true);
                                        jQuery('#operators').parent('.radio-check').eq(0).removeClass('check-unchecked').addClass('check-checked');
                                }
                        })
                })
        };
        checkOneByOne('#operators-list');
        jQuery('#operators').click(function(){
                if(jQuery(this).attr('checked') == true) {
                        checkAll('#operators-list');
                        checkAll('.scellbrand');
                } else if (jQuery(this).attr('checked') == false){
                        uncheckAll('#operators-list');
                        uncheckAll('.scellbrand');
                }
        })
                function inetAndOthers(id,parId)
    {
        if (jQuery(id).attr('checked') == true) 
            {
                jQuery(':checkbox:not(' + id + ')', parId).each(function()
                    {
                        jQuery(this).attr('disabled', true);
                        jQuery(this).parent('.radio-check').eq(0).addClass('check-disabled').removeClass('check-unchecked');
                    })
                
            }
        else 
            {
                jQuery(':checkbox:not(' + id + ')', parId).each(function()
                    {
                        jQuery(this).attr('disabled', false);
                        jQuery(this).parent('.radio-check').eq(0).removeClass('check-disabled').addClass('check-unchecked');
                    })
            }
    }
        
        if(jQuery('#inet0').parent().hasClass('check-checked'))inetAndOthers('#inet0','#inet');
        jQuery('#inet0').click(function()
        {
                inetAndOthers('#inet0','#inet');
        })
        if(jQuery('#tele0').parent().hasClass('check-checked'))inetAndOthers('#tele0','#tele');
        jQuery('#tele0').click(function()
        {
                inetAndOthers('#tele0','#tele');
        })
        jQuery('#tarId').change(function()
        {
        if (jQuery(this).val() == '1') 
        {
                        jQuery('#vol1,#vol2').attr('disabled',true);
                        jQuery('#vol1,#vol2').val('');
                        jQuery('#vol1,#vol2').parents('.input-uni').addClass('input-disabled');
                        
        }
                else
                {
                        jQuery('#vol1,#vol2').attr('disabled',false);
                        jQuery('#vol1,#vol2').parents('.input-uni').removeClass('input-disabled');
                }
                $('.error_Box').hide();
        })
        jQuery('#tarId').change();
        jQuery('#td-sel').change(function()
        {
                switch (jQuery(this).val())
                {
                        case '1':
                        jQuery('#choose-tv').show();
                        jQuery('#choose-inet').show();
                        break;
                        case '2':
                        jQuery('#choose-tv').hide();
                        jQuery('#choose-inet').show();
                        break;
                        case '3':
                        jQuery('#choose-tv').show();
                        jQuery('#choose-inet').hide();
                }
                $('.error_Box').hide();
        })
        jQuery('#td-sel').change();
        jQuery(':radio[name="direct"]').each(function()
        {
                jQuery(this).click(function()
                {
                  jQuery('.what').slideUp('slow').html('');
                  jQuery('.what').load("/act.php?a=load_direct&id="+jQuery(this).attr('rel'),function(){initA();jQuery('.what').slideDown('slow');});
                
                })
        })
        jQuery(':radio[name="vtime"]').each(function()
        {
                jQuery(this).click(function()
                {
                        switch(jQuery(this).attr('id'))
                        {
                                case 'timeYes':
                                        jQuery('#timeYes_').show('slow');jQuery('#timeNo_').hide('slow');
                                        jQuery('.timeno').attr('disabled','disabled');
                                        jQuery('.timeyes').attr('disabled','');
                                        break;
                                case 'timeNo':
                                        jQuery('#timeYes_').hide('slow');jQuery('#timeNo_').show('slow');
                                        jQuery('.timeyes').attr('disabled','disabled');
                                        jQuery('.timeno').attr('disabled','');
                        }
                        $('.error_Box').hide();
                })
        })
        jQuery(':radio[name="vtime"][checked!=""]').click();
        jQuery(':radio[name="service"]').each(function()
        {
                jQuery(this).click(function()
                {
                        switch(jQuery(this).attr('id'))
                        {
                                case 't1':
                                        jQuery('.t_1').show('slow');
                                        jQuery('.t_2').hide('slow')
                                        break;
                                case 't2':
                                        jQuery('.t_1').hide('slow');
                                        jQuery('.t_2').show('slow')
//                                        alert(jQuery(':select[name="cnis"]').val());
                        }
                })
        })
        if(jQuery(':radio[name="service"][checked!=""]').val()==2) {
          jQuery('.t_1').hide('slow');
          jQuery('.t_2').show('slow')
        } else {
          jQuery('.t_2').hide('slow');
          jQuery('.t_1').show('slow')
        }
        var direct=jQuery(':radio[name="direct"][checked!=""]').attr('rel');
        if(direct) jQuery('.what').load("/act.php?a=load_direct&id="+direct,function(){initA();jQuery('.what').slideDown('slow');});
        $('#toloadcity').removeClass("select-uied");
        $('#toloadcity').load("/act.php?a=load_city_to&id="+jQuery('select[name="cnis"]').val()+'&req='+$('#vhid_cityis').val(),function(){initA();});
})


function initA()
{
    jQuery(':radio').each(function(){
        if (jQuery(this).attr('disabled') == true) {
            jQuery(this).parent('.radio-check').eq(0).addClass('radio-disabled').removeClass('radio-unchecked');
        }
        else 
            if (jQuery(this).attr('checked') == true) {
                jQuery(this).parent('.radio-check').eq(0).addClass('radio-checked').removeClass('radio-unchecked');
            }
                jQuery(this).click(function(){
                radioCheck(jQuery(this).attr('name'));
                jQuery(this).parent().eq(0).addClass('radio-checked').removeClass('radio-unchecked');
            })
    })
  $('option:selected').each(function(){
        var id = $(this).attr('value');
        $('.typetext', $(this).parents('.select-uni')).text($(this).text());
    })
    $('.select-uni:not(.select-uied)').each(function(){
        $(this).addClass("select-uied");
        $(this).hover(function(){
            $(this).addClass('active');
            $(this).removeClass('passive');
        }, function(){
            $(this).removeClass('active');
            $(this).addClass('passive');
        })
        $(this).bind('click', function(event){
            event.stopPropagation();
        })
        $('a', $(this)).each(function(i){
            $(this).bind('click', function(event){
                if($('select', $(this).parents('.select-uni')).attr('id')=='sreg') {
                  //alert($(this).attr('rel'));
                  jQuery('#ttowns').load("/act.php?a=load_city&id="+jQuery(this).attr('rel'),function(){initA();});
                }
                if($(this).hasClass('loadcity')) {
                  $('#toloadcity').removeClass("select-uied");
                  $('#toloadcity').load("/act.php?a=load_city_to&id="+jQuery(this).attr('rel'),function(){initA();});
                }
                $('select', $(this).parents('.select-uni')).val($(this).text());
                $('.typetext', $(this).parents('.select-uni')).text($(this).text());
                $('.typetext', $(this).parents('.select-uni')).attr('title', $(this).text());
                $('select', $(this).parents('.select-uni')).attr('value', $(this).attr('rel'));
                $('select', $(this).parents('.select-uni')).change();
                $('.opt-list', $(this).parents('.select-uni')).css('visibility', 'hidden');
                $(this).parents('.select-uni').css('z-index', '1');
                $(this).parents('#f_arh').submit();
                event.preventDefault();
            })
        })
        jQuery('.bg-l', $(this)).each(function(){
            $(this).click(function(event){
                show=false;
                el=$(this).next(':hidden');
                if (el.css('visibility')=="hidden") show=true;
                hideSelect(this);
                if (show) {
                  el.css({'visibility':'visible'});
                  $(this).parents('.select-uni').css('z-index', '10');
                }
            })
        })
    })
//  $('a').each
}

jQuery().ready(function(){
    jQuery.fn.extend({
        addDocumentFragment: function(rel){
            jQuery(this).each(function(){
                var clone = jQuery(rel).clone(true);
                jQuery(this).parents('.xl-to-hide').before(clone);
            })
        },
        relInput: function(){
            jQuery(this).each(function(){
                var relCont = jQuery('.by-rel',jQuery(this).parents('.xl-hidden-clone'));
                var relInp = jQuery(':text',relCont);
                if(jQuery(this).hasClass('others-op')) {
                    relInp.attr('disabled',false);
                    relInp.parents('.input-uni').removeClass('input-disabled');
                    relCont.show(300);
                } else {
                    relCont.hide(300);
                    relInp.attr('disabled',true);
                    relInp.val('');
                    relInp.parents('.input-uni').addClass('input-disabled');
                }
            })
        },
        openHidden: function(){
            jQuery(this).each(function(){
                var id = jQuery(this).attr('href');
                var pos = jQuery(this).offset();
                var x = '50%';
                var y = pos.top + jQuery(this).outerHeight() + 'px';
                var m = '-' + jQuery(id).outerWidth()/2 + 'px';
                jQuery(id).css({
                    left: x,
                    top: y,
                    marginLeft: m
                })
                if(jQuery(id).is(':hidden')){
                    jQuery(id).show();
                } else {
                    jQuery(id).hide();
                }
            })
        }
    });
    jQuery('.form_register .xl-hidden-clone .select-other .opt-list a').each(function(){
        jQuery(this).click(function(){
            jQuery(this).relInput();
        })
    })
    jQuery('.will-chk').each(function(){
        hideRowsIfChecked('#'+$(this).attr('id'),'xl-to-hide-'+$(this).attr('id'),'xl-hidden');
    })
    jQuery('.will-chk').click(function(){
        hideRowsIfChecked('#'+$(this).attr('id'),'xl-to-hide-'+$(this).attr('id'),'xl-hidden');
    })
    function hideRowsIfChecked(checkId,classRows,removeClass){
        if(jQuery(checkId).is(':checked')) {
            jQuery('.' + classRows).each(function(){
                jQuery(this).slideDown(500);
//                jQuery(this).removeClass(removeClass);
            })
        } else {
            jQuery('.' + classRows).each(function(){
                jQuery(this).slideUp(500);
//                jQuery(this).addClass(removeClass);
            })
        }
    }
    jQuery('.add-more-nodes-register').each(function(){
        jQuery(this).click(function(e){
            e.preventDefault();
            var rel=jQuery(this).attr("rel");
            jQuery(this).each(function(){
                var src=jQuery('.xl-hidden-will'+rel+':last');
                var clone=src.clone(true);
                jQuery(src).after(clone);
                jQuery('select.sel_s2',clone).parents('.select-uni').each(function(){
                  jQuery('select',this).val(jQuery('option:first',this).attr('value'));
                  jQuery('.typetext',this).text(jQuery('option:selected',this).text());
                  jQuery('.typetext',this).attr('title',jQuery('option:selected',this).text());
                });
                jQuery('input.text_s2',clone).val('').attr('disabled',true);
                jQuery('input.text_s2',clone).parents('.input-uni').addClass('input-disabled');
                jQuery('input.text_s2',clone).parents('.by-rel').hide();
            })
            register_row_preprocess(rel);
        })
    })

    jQuery('.add-more-nodes-mybox').each(function(){
        jQuery(this).click(function(e){
            e.preventDefault();
            var rel=jQuery(this).attr("rel");
            jQuery(this).each(function(){
                var src=jQuery('.xl-hidden-will'+rel+':last');
                var clone=src.clone(true);
                jQuery('.record_id',clone).val(0);
                jQuery('select.eop',clone).parents('.select-uni').each(function(){
                  jQuery('select',this).val(jQuery('option:first',this).attr('value'));
                  jQuery('.typetext',this).text(jQuery('option:selected',this).text());
                  jQuery('.typetext',this).attr('title',jQuery('option:selected',this).text());
                });
                jQuery('.ename',clone).val('');
                jQuery('.ename',clone).replaceWith(jQuery('.ename',clone).clone(false)); /// drop some strange events from autocomplete
                jQuery(src).after(clone);
            })
            mybox_row_preprocess(rel);
        })
    })

    jQuery('.xz-link').each(function(){
        jQuery(this).bind('click',function(e){
            e.preventDefault();
        })
    })
    jQuery('.xz-link-d').click(function(){
        jQuery('.adm-explain').slideDown();
    })
    jQuery('.xz-link-u').click(function(){
        jQuery('.adm-explain').slideUp();
    })

    jQuery('a.for-login').click(function(event){
      jQuery('#log').focus();
      event.stopPropagation();
    })

  jQuery('.add_to_compare').each(function(){jQuery(this).click(
  function(){
    var r=jQuery(this).attr('rel');
    var ob=this;
    jQuery.post("/act.php?a=set_compare",{'e':r},function(d,s,obj){
      d2=d.split('##');
      var dst=jQuery("a[rel='"+r+"'] > span");
      if(dst.length) dst.html(d2[0]); else jQuery(ob).html(d2[0]);
      var r2=r.split(';');
      if(d2[1]==0) jQuery('tbody#cmpl_'+r2[1]+'_'+r2[0]).removeClass('tr-selected');
      else jQuery('tbody#cmpl_'+r2[1]+'_'+r2[0]).addClass('tr-selected');
    });
  })});
  jQuery('.del_from_compare').each(function(){jQuery(this).click(
  function(event){
    var r=jQuery(this).attr('rel');
    var obj=this;
    jQuery.post("/act.php?a=set_compare",{'force_del':1,'e':r},function(d,s,obj){
      document.location=document.location;
    });
    event.stopPropagation();
  })});
  jQuery('.pop-up-comments').click(function(e){
    jQuery(this).openHidden();
    e.preventDefault();
  })
  jQuery('form#comment_add').each(function(){jQuery(this).submit(
  function(){
    var obj=jQuery(this);
    var c=jQuery('#comment_add_cls',obj).val();
    var i=jQuery('#comment_add_eid',obj).val();
    var t=jQuery('#comment_add_txt',obj).val();
    jQuery.post("/act.php?a=add_comment",{'cls':c,'eid':i,'txt':t},function(d,s,obj){
      jQuery('#comment_add_txt',obj).val("");
      jQuery('#comments_container',obj).html(d);
      comment_slider_hack(obj);
    });
    return false;
  })});
  comment_slider_hack();

  jQuery('#xxxl-anketa').each(function(){
    var obj=jQuery(this);
    jQuery('.ico-close',obj).click(function(event){ jQuery('#dhelp').hide(); jQuery(obj).hide(); });
  });
  jQuery('.jawohl > a.open_anketa').each(function(){
    jQuery(this).click(function(event){
      var a=jQuery(this);
      var w=jQuery('#xxxl-anketa');
      var c=jQuery('#xxxl-anketa-content');
      w.hide();
      c.load("/act.php?a=anketa&e="+jQuery(this).attr('rel'),function(){
        var p=a.position();
        var t=p['top']-0+'px';
        w.css('top',t);
        jQuery('#ank_district').val(jQuery('.typetext',$('#district').parents('.select-uni')).text());
        jQuery('#ank_street').val(jQuery('#local').val());
        initA();
        w.show();
        var f=jQuery(".formValidate",w);
        apply_helps(jQuery('span.help,img.help',f));
        apply_validate(f,function(){
          var options = {
            target:null,
            beforeSubmit:null,
            success:function(a){ c.html(a); },
            url:'/act.php?a=anketa&'+jQuery(f).serialize(),
            type:'post'
          };
          $(f).ajaxSubmit(options);
          return false;
        });
      });
      event.stopPropagation();
      event.preventDefault();
    })
  })

  for(var rel=1;rel<=6;rel++) mybox_row_preprocess(rel);
});
function comment_slider_hack(ob)
{
  jQuery('.full-comment', '.comments').foldTree();
  jQuery('.short-comment', '.comments').each(function(){
    jQuery(this).click(function(event){
      jQuery(this).next().show('slow');
      jQuery('.full-comment', jQuery(this).parent().siblings()).hide('slow');
      event.preventDefault();
    });
  });
  jQuery('.comment-slider a',ob).each(function(){
    jQuery(this).click(function(){
      var c=jQuery('#comment_add_cls').val();
      var i=jQuery('#comment_add_eid').val();
      var f=jQuery(this).attr('rel');
      jQuery.post("/act.php?a=comments",{'cls':c,'eid':i,'from':f},function(d,s,obj){
        jQuery('#comments_container',ob).html(d);
        comment_slider_hack(ob);
      });
      return false;
    })
  })
}

function hideSelect(){
        jQuery('.opt-list').each(function(){
            jQuery(this).css('visibility', 'hidden');
            jQuery(this).parents('.select-uni').css('z-index', '1');
        })
}
function register_row_preprocess(rel)
{
    var w='.xl-hidden-will'+rel+'.xl-hidden-clone';
    var cnt=jQuery(w).length;
    jQuery(w).each(function(){
        var index=jQuery(w).index(this);
        var suff='_'+rel+'_'+index;
        jQuery('.sel_region',jQuery(this)).attr('name','region['+rel+']['+index+']');
        jQuery('.sel_s2',jQuery(this)).attr('name','cl1['+rel+']['+index+']');
        jQuery('.text_s2',jQuery(this)).attr('name','cl1s['+rel+']['+index+']');
        jQuery('label.e-name',this).attr('for','addlist'+suff);
        jQuery('input.text_s2',this).attr('id','addlist'+suff);
        jQuery('select.sel_region',this).attr('id','sel_region'+suff);
        jQuery('select.sel_s2',this).attr('id','sel_s2'+suff);
        jQuery('.ico-close',jQuery(this)).click(function(){ jQuery(this).parents('.xl-hidden-clone').remove(); register_row_preprocess(rel); });
        if(cnt<2) jQuery('.ico-close',jQuery(this)).hide(); else jQuery('.ico-close',jQuery(this)).show();
    });
}
function mybox_row_preprocess(rel)
{
    var w='.xl-hidden-will'+rel+'.xl-hidden-clone';
    var cnt=jQuery(w).length;
    jQuery(w).each(function(){
        var suff='_'+rel+'_'+jQuery(w).index(this);
        jQuery('label.e-name',this).attr('for','addlist'+suff);
        jQuery('input.ename',this).attr('id','addlist'+suff);
        jQuery('select.s_region',this).attr('id','s_region'+suff);
        jQuery('select.eop',this).attr('id','eop'+suff);
        jQuery('.ico-close',jQuery(this)).click(function(){ jQuery(this).parents('.xl-hidden-clone').remove(); mybox_row_preprocess(rel); });
        if(cnt<2) jQuery('.ico-close',jQuery(this)).hide(); else jQuery('.ico-close',jQuery(this)).show();
        mybox_op_onchange(rel,jQuery('.eop',jQuery(this)));
    });

}
function mybox_region_onchange(typid,obj)
{
  var cont=jQuery(obj).parents('.xl-hidden-clone');
  jQuery.get("/act.php?a=load_mybox_cl1&t="+typid+"&r="+jQuery(obj).val(),function(s){
    select_load_options(jQuery('.eop',cont),s);
    mybox_op_onchange(typid,jQuery(sel));
  });
}
function register_region_onchange(typid,obj)
{
  var cont=jQuery(obj).parents('.xl-hidden-clone');
  jQuery.get("/act.php?a=load_register_cl1&t="+typid+"&r="+jQuery(obj).val(),function(s){
    select_load_options(jQuery('.sel_s2',cont),s,true);
  });
}
function select_load_options(sel,html)
{
  if(!jQuery(sel).hasClass('select-uni')) sel=jQuery(sel).parents('.select-uni');
  var selid=jQuery('option:selected',sel).attr('value');
  jQuery('select',sel).html(html);
  var acont=jQuery('.opt-list div ul',sel);
  jQuery('li',acont).remove();
  jQuery('option',sel).each(function(){
    var id=jQuery(this).attr('value');
    jQuery(acont).append('<li><a href="#" rel="'+id+'">'+jQuery(this).text()+'</a></li>');
    var arel=jQuery('.opt-list a[rel='+id+']',sel);
    jQuery(arel).text(jQuery(this).text());
    jQuery(arel).attr('class',jQuery(this).attr('class'));
    jQuery(arel).click(function(event){
      if(jQuery(sel).hasClass("select-other")) jQuery(arel).relInput();
      jQuery('.typetext',sel).text(jQuery(arel).text());
      jQuery('.typetext',sel).attr('title', jQuery(arel).text());
      jQuery('select',sel).attr('value', jQuery(arel).attr('rel'));
      jQuery('select',sel).change();
      jQuery('.opt-list',sel).css('visibility','hidden');
      jQuery(sel).css('z-index', '1');
      event.preventDefault();
    });
  });
  jQuery('select',sel).val(selid);
  jQuery('.typetext',sel).text(jQuery('option:selected',sel).text());
  jQuery('.typetext',sel).attr('title',jQuery('option:selected',sel).text());
  jQuery('select',sel).change();
}
function mybox_op_onchange(typid,obj)
{
  var cont=jQuery(obj).parents('.xl-hidden-clone');
  var rid=jQuery('.s_region',cont).val();
  if(!rid) rid=0;
  var url = '/act.php?a=load_mybox_cls';
  var enameid=jQuery('.ename',cont).attr('id');
  jQuery('.ename'.cont).unautocomplete();
  jQuery('.ename',cont).autocomplete(url,
  {
   minChars: 0,
   delay: 100,
   selectFirst: false,
   scrollHeight:150,
   extraParams:{r:rid,t:typid,op:jQuery('.eop',cont).val()}
  });
  jQuery('.ename',cont).focus(function(event){ 
    jQuery(this).click();
  });
}

jQuery().ready(function(){
  
});