  //------------------- Comments -----------------------
      $(document).ready(function(){
          $("#add_comm_topic").click(function(){
             $("#add_comm_end").hide();
             $(".comment_form").remove();
             $("#comment_to").val('');
             $("#add_comm_end").before('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
          });
	  
          $(".comment:odd").css("background-color","#f4ffde");	
          $(".answer").click(function(){ 
              $("#add_comm_end").show();
              $(".comment_form").remove();
              $("#c"+this.id.slice(1)).append('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
              $('#comment_to').val(this.id.slice(1)); 
              $('#comment_form_tpl').show();            
          });
      });
      
      function delclick()
        {
          $(".delete_comment").click(function(){
            level = (parseInt($('#c'+this.id.slice(1)).css("margin-left"))-10)/30;
            k = 1; 
            list_id = this.id.slice(1); 
            while (level < ((parseInt($('#c'+this.id.slice(1)).next("div").css("margin-left"))-10)/30)){
              list_id = list_id + "|" + $('#c'+this.id.slice(1)).next("div").attr("id").slice(1);
              $('#c'+this.id.slice(1)).next("div").remove();
              k++;
            }

            $('#c'+this.id.slice(1)).remove();
            
            $("#comment_count").html(parseInt($("#comment_count").html()) - k);
                
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $.post("/comments/delete/", {comid:list_id, obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
        }
   
      $(document).ready(function(){
          $(".moderate_comment").click(function(){ 
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $('#c'+this.id.slice(1)).html('<div style="height: 25px;"><img src="/data/users/avatar/comment_moder.png" style="float: left; margin-right: 10px;" /><div style="width: 100%; text-align: cwnter; font-size: 16px; padding-top: 3px;">Пришел добрый доктор Айболит и вылечил плохой коментарий <a href="javascript: void(0);" id="d'+this.id.slice(1)+'" class="delete_comment" style="text-decoration: underline; color: red">удалить</a></div></div>');  
            delclick();
            $.post("/comments/moderate/", {comid:this.id.slice(1), obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
      });   
      
      $(document).ready(function(){
        delclick();
      });        
   



  /* Coder debug */
  document.onkeydown = NavigateThrough;
  function NavigateThrough (event)
    {	
	  if (!document.getElementById) return;
	  if (window.event) event = window.event;
	  if (event.ctrlKey)
	    {
  	      var link = null;
		  var href = null;		
		  switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
		    {
		      case 0x25:
			    document.getElementById('coder_debug').style.display='none'				
			  break;
			  case 0x27:				
                document.getElementById('coder_debug').style.display='';			    
			  break;
		    }        
	    }			
    }
  
    
  /* Empty and restore default fields values */
  function setfocus(id)
    {
  	  document.getElementById(id).focus();  
    }  

  function empty(id)
    {	  
      if (document.getElementById(id).value == document.getElementById(id).title)
        {
	      document.getElementById(id).value="";
	    }    
    }

  function fill(id)
    {	       
  	  if (document.getElementById(id).value=="")
  	    {  	      
  	      document.getElementById(id).value = document.getElementById(id).title;
  	    }
    }

  //------------------- Коментарии -----------------------
      $(document).ready(function(){
          $("#add_comm_topic").click(function(){
             $("#add_comm_end").hide();
             $(".comment_form").remove();
             $("#comment_to").val('');
             $("#add_comm_end").before('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
          });
	  
          $(".comment:odd").css("background-color","#f4e7f1");	
          $(".answer").click(function(){
              $("#add_comm_end").show();
              $(".comment_form").remove();
              //$("#c"+this.id.slice(1)).append('<div class="comment_form">Добавить комментарий:<form action="" method="post"><textarea id="comment_text" name="comment_text"></textarea><br/><input type="hidden" name="comment_to" value="'+this.id.slice(1)+'"><input type="submit" id="comment_submit" value="Отправить"></form></div>');
              $("#c"+this.id.slice(1)).append('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
              $('#comment_to').val(this.id.slice(1)); 
              $('#comment_form_tpl').show();            
          });
      });
      
      function delclick()
        {
          $(".delete_comment").click(function(){
            level = (parseInt($('#c'+this.id.slice(1)).css("margin-left"))-10)/30;
            k = 1; 
            list_id = this.id.slice(1); 
            while (level < ((parseInt($('#c'+this.id.slice(1)).next("div").css("margin-left"))-10)/30)){
              list_id = list_id + "|" + $('#c'+this.id.slice(1)).next("div").attr("id").slice(1);
              $('#c'+this.id.slice(1)).next("div").remove();
              k++;
            }

            $('#c'+this.id.slice(1)).remove();
            
            $("#comment_count").html(parseInt($("#comment_count").html()) - k);
                
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $.post("/comments/delete/", {comid:list_id, obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
        }
   
      $(document).ready(function(){
          $(".moderate_comment").click(function(){ 
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $('#c'+this.id.slice(1)).html('<div style="height: 25px;"><img src="/data/users/avatar/comment_moder.png" style="float: left; margin-right: 10px;" /><div style="width: 100%; text-align: cwnter; font-size: 16px; padding-top: 3px;">Пришел добрый доктор Айболит и вылечил плохой коментарий <a href="javascript: void(0);" id="d'+this.id.slice(1)+'" class="delete_comment" style="text-decoration: underline; color: red">удалить</a></div></div>');  
            delclick();
            $.post("/comments/moderate/", {comid:this.id.slice(1), obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
      });   
      
      $(document).ready(function(){
        delclick();
      });        
   
