    //Показ ограничения вводимых символов
     function Limiter(element,min,max)
     {
      if(element.value.length < max){
       document.getElementById("divin_"+element.id).style.width = Math.round(element.value.length/max*200)+"px";
      }else{
       document.getElementById("divin_"+element.id).style.width = 200+"px";
       element.value = element.value.slice(0,max);
      }
      document.getElementById("len_"+element.id).innerHTML = element.value.length+"/"+max;
     }
    //Убираем пунктирные рамки
    $(document).ready(function(){
  	  jQuery("a").focus( 
  	    function(){ 
  	      this.blur(); 
  	    }); 
  	});
  	//Сворачиваем-разворачиваем цитату
    $(document).ready(function(){ 
      var needHeight = $("#citat").height();
      var miniHeight = 60;
      var windHeight = $(window).height();
      if( windHeight>680 ){  miniHeight = (Math.floor((windHeight-620)/15)*15); }
      $("#citat").height(miniHeight+"px");
      $("#citat").click(function(){
        if($("#citat").height()>miniHeight){
          $("#citat").animate({height:miniHeight+"px"},600);
        } else {
          $("#citat").animate({height:needHeight+"px"},600);
        }
      });
  	 });
    //Переключение вкладок "Характеристик","Отзывы"...
    $(document).ready(function(){ 
  	  $("#tab_comments").hide();
  	  $("#tab_shops").hide();
  	  $("#a_tabs span:first").css({fontWeight:"bold"});
  	  
      $("#a_tabs span").click(function () {
        var id = $(this).attr('id');
        var tab_arr = id.split('_');
        var tab = 'tab_'+tab_arr[1];
        if(!$("#"+tab).is(':visible')){
  	      $("#a_tabs span").css({fontWeight:"normal"});
  	      $(this).css({fontWeight:"bold"});
  	      $(".tab").hide();
  	      $("#"+tab).slideDown();
  	    }
  	    return false;
  	  });
  	});
    //Меню производителей
    $(document).ready(function(){
      var full_height = $("#brand").height();
      var min_height  = '300px';
      var sort = gSORT.split('|');
      var alfav = sort[1].split(',');
      var count = sort[0].split(',');
      if($.cookie("brand_height")){
        if($.cookie("brand_height") == "display"){
          $("#brand").height(full_height);
          $("#brandnavig_down").css({fontWeight:"bold"});
          $("#brandnavig_up").css({fontWeight:"normal"});
          $.each(alfav, function(i,id){
            $("#brand").append($("#bid_"+id));
          });
        }
        if($.cookie("brand_height") == "hidden"){
          $("#brand").height(min_height);
          $("#brandnavig_down").css({fontWeight:"normal"});
          $("#brandnavig_up").css({fontWeight:"bold"});
        }
      }else{
        $("#brand").height(min_height);
        $.cookie("brand_height","hidden",{expires: 1, path: "/"}); 
        $("#brandnavig_down").css({fontWeight:"normal"});
        $("#brandnavig_up").css({fontWeight:"bold"});
      }
      $("#brandnavig_down").click(function () {
        if($.cookie("brand_height")=="hidden"){
          $("#brandnavig_down").css({fontWeight:"bold"});
          $("#brandnavig_up").css({fontWeight:"normal"});
          $.cookie("brand_height","display",{expires: 1, path: "/"});
          $("#brand").animate( {height: full_height},900);
          $.each(alfav, function(i,id){
            $("#brand").append($("#bid_"+id));
          });
        }
        return false;
      });
      $("#brandnavig_up").click(function () {
        if($.cookie("brand_height")=="display"){
          $("#brandnavig_down").css({fontWeight:"normal"});
          $("#brandnavig_up").css({fontWeight:"bold"});
          $.cookie("brand_height","hidden",{expires: 1, path: "/"});   
          $("#brand").animate( {height: min_height},900);
          $.each(count, function(i,id){
            $("#brand").append($("#bid_"+id));
          });
        }
        return false;
      });
      
    });
    
    //Увеличение изображения при наведении
    $(document).ready( function(){
     	$('.white img').hover(
      function(){
			  $(this).stop().animate({left:"0px",top:"0px",width:"148px",height:"148px"},400);
			  $(this).css({border:"0px"});
		  },
		  function(){
			  $(this).css({border:"1px dashed #E6E6E6"});
			  $(this).stop().animate({left:"25px",top:"25px",width:"100px",height:"100px"},400);
		  });
    });
    $(document).ready( function(){
     	$('#content .screen').hover(
      function(){
			  $(this).find('a').css({fontWeight: 'bold'});
		  },
		  function(){
			  $(this).find('a').css({fontWeight: 'normal'});
		  });
    });
    //Голосование
    $(document).ready(function(){
      //источники - http://www.wbotelhos.com/raty/ , http://plugins.jquery.com/project/raty   
      $('.voter').raty({
        start:     0.5,
        path:      '/img/',
        number:    6,
        hintList:  [],
        showHalf:  true,
        onClick:   function(score) {
          var name_url = this.attr('id');
          $.get("/voter.php", { varscore: score, varname_url: name_url }, function(data){
            var votearr = data.split('|');
            $.fn.raty.start(votearr[2],'#'+name_url);
            $.fn.raty.readOnly(true,'#'+name_url);
            $('#'+name_url).find('small span:first').text(votearr[0]);
            $('#'+name_url).find('small span:last').text(votearr[2]);
            $.cookie(name_url,"true",{expires: 1, path: "/"});
          });
        }
      });
      //Предустанавливаем результаты
      $('.voter').each(function(){
        var score = $(this).find('small span:last').text();
        if( score > 0 ) {
          var name_url = $(this).attr('id');
          $.fn.raty.start(score,'#'+name_url);
          if($.cookie(name_url)=="true"){
            $.fn.raty.readOnly(true,'#'+name_url);
          }
        }
      });
    });
    
    //Всплывающее окно
    $(document).ready(function(){
      //Open
      $('.modal').click(function () {
        $('#modalbody').html('');
        $('#modalfon').fadeTo( 100, 0.60 );
        $('#modalfon img').show();
        var modalidname = $(this).attr('id');
        $.get('/modal/'+modalidname+'.php', { hid: gHID, model: gMODEL, brand: gBRAND } , 
        function(data){
          $('#modalbody').html(data);
          $('#modalwin').show();
        });
        return false;
      });
      //Close
      $('#modalhead a').click(function () {
        $('#modalfon img').hide();
        $('#modalbody').html('');
        $('#modalwin').hide();
        $('#modalfon').fadeTo( 200, 0.00 , function(){ $('#modalfon').hide(); } );
        return false;
      });
    });
    //Добавление/Редактирование/удаление отзыва
    $(document).ready(function(){
      //Добавление
	    $('#submit_response').live('click', function() {
        var hash     = $('input[name="hash"]').val();
        var name     = $('input[name="name"]').val();
        var mail     = $('input[name="mail"]').val();
        var response = $('textarea[name="response"]').val();
        var referer  = location.href;
        if( name=="" )    { alert("Укажите Ваше Имя"); return false; }
        if( mail=="" )    { alert("Укажите Ваш email для связи"); return false; }
            var emailTest = "^[_\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\.)+[a-z]{2,4}$"; 
            var regex = new RegExp(emailTest); 
        if( !regex.test(mail) || !(mail.length > 0) ){ alert("E-mail указан некорректно"); return false; }
        if( response=="" ){ alert("Отсутствует текст отзыва"); return false; }
        $('#modalbody').html('<img src="../img/loading_black.gif" style="float: left;">&nbsp;&nbsp;&nbsp;<b>Подождите</b><br>&nbsp;&nbsp;&nbsp;Идет обработка отзыва');
        $.post( "/modal/modal_addresponse.php", {  
          model:     gMODEL,
          hid:       gHID,
          hash:      hash,
          name:      name, 
          mail:      mail, 
          response:  response, 
          referer:   referer }, 
        function(data){
          var data_array = data.split("|");
          if(jQuery.trim(data_array[0])=='TRUE'){
            //Делаем отметку в кукисы
            $.cookie(gMODEL,data_array[1],{expires: 30, path: "/"});
            var date = new Date();
            if( $("#"+data_array[1]).is(":visible") ){
              //Меняем существующий отзыв
              var tmp_response = "<small>"+date.toLocaleDateString()+"</small> <b>"+name+"</b><br><br>"+response;
              $("#"+data_array[1]+" #resp_tmp").html(tmp_response);
            } else {
              //Добавляем новый отзыв в html
              var tmp_response = '<div class="wide" class="op" id="'+data_array[1]+'" ><div class="op_top"><div class="op_top_r"><div class="op_top_c"></div></div></div><div class="op_cen"><div id="resp_tmp"><small>'+date.toLocaleDateString()+'</small> <b>'+name+'</b><br><br>'+response+'</div><div class="resp_edit_del"><a title="Редактировать" href="javascript:void(0);" rel="nofollow" id="response_edit">EDIT</a> <a title="Удалить" href="javascript:void(0);" rel="nofollow" id="response_del">DEL</a></div></div><div class="op_bot"><div class="op_bot_r"><div class="op_bot_c"></div></div></div></div>';
              $(tmp_response).prependTo("#tab_comments");
            }
            //Скрываем окно
            $("#modalfon img").hide();
            $("#modalbody").html('');
            $("#modalwin").hide();
            $("#modalfon").fadeTo( 200, 0.00 , function(){ $("#modalfon").hide(); } );
          }else{
            $("#modalbody").html("<b>"+name+"</b>, отзыв <b>не</b> принят,<br>возможно стоит повторить операцию позже.<br><br>"+data);
          }
        });
        return false;
	    });
      //Редактироване
      $('#response_edit').live('click', function () {
        var model = gMODEL;
        if($.cookie(model)){
          var hash = $.cookie(model);
          if(hash != ""){
            $('#modalbody').html('');
            $('#modalfon').fadeTo( 100, 0.60 );
            $('#modalfon img').show();
            $.get('/modal/modal_addresponse.php', { hid: gHID, model: gMODEL, brand: gBRAND, hash: hash } , 
            function(data){
              $('#modalbody').html(data);
              $('#modalwin').show();
            });
          }
        }
        return false;
      });
      //Удаление
      $('#response_del').live('click', function () {
        var model = gMODEL;
        if($.cookie(model)){
          var hash = $.cookie(model);
          if(hash != ""){
            if( confirm("Хотите удалить отзыв?\nУверены?\n\n") ){
              $.get('/modal/modal_addresponse.php', { hid: gHID, model: gMODEL, brand: gBRAND, hash: hash, action: "del" } , 
              function(data){
                if( data == "DELETED" ) {
                  $("#"+hash).remove();
                  $.cookie(gMODEL, null);
                }
              });
            }
          }
        }
        return false;
      });
    });
    //Форма обратной связи
    $(document).ready(function(){
	    $('#submit_message').live('click', function() {
        var name     = $('input[name="name"]').val();
        var mail     = $('input[name="mail"]').val();
        var message =  $('textarea[name="message"]').val();
        var referer  = location.href;
        if( name=="" )    { alert("Укажите Ваше Имя"); return false; }
        if( mail=="" )    { alert("Укажите Ваш email для связи"); return false; }
            var emailTest = "^[_\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\.)+[a-z]{2,4}$"; 
            var regex = new RegExp(emailTest); 
        if( !regex.test(mail) || !(mail.length > 0) ){ alert("E-mail указан некорректно"); return false; }
        if( message=="" ){ alert("Отсутствует текст отзыва"); return false; }
        $('#modalbody').html('<img src="../img/loading_black.gif" style="float: left;">&nbsp;&nbsp;&nbsp;<b>Подождите</b><br>&nbsp;&nbsp;&nbsp;Идет отправка письма');
        $.post( "/modal/modal_contacts.php", {  
          hid:       gHID,
          name:      name, 
          mail:      mail, 
          message:   message, 
          referer:   referer }, 
        function(data){
          if(jQuery.trim(data)=='TRUE'){
            $("#modalbody").html("<b>"+name+"</b>, Ваше письмо отправлено администратору сайта.<br><br>");
          }else{
            $("#modalbody").html("<b>"+name+"</b>, письмо <b>не</b> отправлено,<br>возможно стоит повторить операцию позже.<br><br>");
          }
        });
        return false;
	    });
	  });
    //Переход по ссылке интернет-магазина
    $(document).ready(function(){
      $('#tab_shops .wide i').hide();
      $('#tab_shops .wide').live('click', function () {
        var link = $(this).find('i').text();
        window.open(link);
        return false;
      });
    });
    //Поисковой модуль
    $(document).ready(function(){
       //Скрытие-раскрытие списков
       $('.modalstitle').live('click', function() {
         if($(this).next().is(':visible')){
           $(this).next().hide(200);
           $(this).css({fontWeight:"normal"});
         } else {
           $(this).next().show(200);
           $(this).css({fontWeight:"bold"});
           if($.cookie("mchecked")){
             var coo = $.cookie("mchecked").split('/');
             $.each(coo, function(i,cooka){
               $('input[name="'+cooka+'"]').attr("checked",true); 
             });
             coo.length
           }
         }
       });
       //Отметка чекбокса
       $('.modalchecks').live('click', function() {

          var descval_id = this.name;
          //Обход чекбоксов и занос их в кукисы
          var tocookie = '';
          var del = '';
          $('.modalchecks').each(function(){
             if( $(this).is(":checked") ){
               tocookie += del+this.name;
               del = '/';
             }
          });
          $.cookie("mchecked",tocookie,{expires: 1, path: "/"});
          $.post( "/modal/count_search.php", {  
            hid:       gHID,
            counter:   tocookie }, 
          function(data){
            $('#modalcounter').html(data);
          });

       });
       
    });                 
