function addPostVotes(postId, klass, vote){
  $('#'+postId+'_vote').unbind('click').click(function(){return false;}); 
  $.getJSON("/ajax/add_post_vote",
            { post: postId, klass: klass, vote: vote },
           function(json){
              if(json.success){
                 $('#'+postId+'_rating')
                      .removeClass()
                      .addClass(json.vote_class)
                      .attr("innerHTML",json.rating);
                 $('#'+postId+'_rating_up')
                      .attr('src', MEDIA_URL + 'design/3/img/b-bar/plus_disabled.png');
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  return false;
}

function addToFav(anchor, name){
  $.getJSON("/ajax/add_favorites", { item: name },
           function(json){
              if(json.success){
                 $('#'+name+'_fav').attr('src', MEDIA_URL + 'design/3/img/b-bar/favorites_on.png');
                 this.onclick = null;
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  return false;
}

function addCommentVote(commentId, vote){
  $('#'+commentId+'_rating').unbind('click').click(function(){return false;}); 
  $.getJSON("/ajax/add_comment_vote",
            { comment: commentId, vote: vote },
           function(json){
              if(json.success){
                 $('#comment_'+commentId+'_rating')
                      .removeClass()
                      .addClass(json.vote_class)
                      .attr("innerHTML",json.rating);
                 $('#comment_'+commentId+'_rating_up')
                      .attr('src', MEDIA_URL + 'design/2/img/rating_up_dis.gif');
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  return false;
}

function addComment(postId, commentId){
  comment = $('#content'+commentId).attr('value');
  if( !comment ){ return false; }
  
  $.getJSON("/ajax/add_comment",
            { comment: commentId, post: postId, content: comment},
           function(json){
              if(json.success){ 
                 $('#aftercomment'+json.afterComment)
                     .after(json.html);
                 init();
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  $('#commentform'+commentId).hide();
  $('#content'+commentId).attr('value', '');
  $('#commentlink'+commentId).show();  
  return false;
}

function addPicLink(insertMode, fieldId, picId){
    // Вставляет в поле редактирования ссылку <glader pic="...">
    field = $('#'+fieldId);
    field.text( field.text() + '<glader pic="' + picId + '">' );
}

function setBestAnswer(commentId){
 $.getJSON("/ajax/best_answer",
            { comment: commentId},
           function(json){
              if(json.success){ 
                 window.location = window.location;
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  $('#best_answer_mark_'+commentId).hide();  
  return false;
}

function delBestAnswer(commentId){
 $.getJSON("/ajax/best_answer",
            { comment: commentId, del:1 },
           function(json){
              if(json.success){ 
                 window.location = window.location;
              }
              if(json.error){
                 alert(json.error)
              }
              return false;
           });

  $('.js-del_best_answer').hide();  
  return false;
}