function addItems() {
  $("#gotopage").find("input[name='curpage']").val(nextPage);
  $.ajax({
    url: '/yidong/discuss/index?id='+ topicid, 
    type: 'POST',
    dataType: "html", 
    data: $("#gotopage").serialize(),
    beforeSend: function(){
      $(".infinite-scroll-preloader").show();
      $(".load-more-button").hide();
    },
    success: function(data){
      $('.infinite-scroll-bottom .list-container').append(data);
      nextPage ++;
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    },
    complete: function(){
      $(".infinite-scroll-preloader").hide();
      $(".load-more-button").show();
      if(nextPage > maxPages){
        $(".load-more-button").remove();
        $(".infinite-scroll-preloader").remove();
      }
    }
  });
}

$(".load-more-button").click(function(){
  if(nextPage <= maxPages){
    addItems();
  }
});

//加载第1页
addItems();

//提交回复
function replyRunning(){
  $.ajax({
    url: '/yidong/discuss/reply?id='+ topicid, 
    type: 'POST',
    data: $("#reply_form").serialize(),
    dataType: "json", 
    beforeSend: function(){
      $.showIndicator();
    },
    success: function(data){
      if(data.code=="success"){
        $.toast("发表成功");
        $("#reply_form").find("textarea[name='myanswer']").val("");
        $.closeModal(".popup-about");
      }else{
        $.toast(data.msg);
      }
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    },
    complete: function(){
      $.hideIndicator();
    }
  });
}

//点赞
function giveThumbsup(tgid,elem){
  $.ajax({
    url: '/yidong/discuss/thumbsup?id='+ tgid, 
    type: 'GET',
    dataType: "json", 
    success: function(data){
      if(data.code=="success"){
        $(elem).html("赞("+ data.thumbsup +")");
      }else{
        $.toast(data.msg);
      }
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    }
  });
}