function addItems() {
  $("#gotopage").find("input[name='curpage']").val(nextPage);
  $.ajax({
    url: '/yidong/pptaskq/index?ketangid='+ ketangid, 
    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 searchRunning(){
  $("#search_form").submit();
}

//重置
function searchRecover(){
  $("#search_form").find("input[name='se_title']").val("");
  $("#search_form").find("select[name='se_typeid']").val("");
  $("#search_form").find("select[name='se_isrushed']").val("");
  $("#search_form").find("input[name='curpage']").val(1);
  $("#search_form").submit();
}

//预览题目
function viewStemDetail(id){
  $.popup(".popup-preview");
  $("#previewdetail").empty();
  $.ajax({
    url: '/yidong/pptaskview/index?id='+ id +'&rnum='+ Math.random(), 
    type: 'GET',
    dataType: "html", 
    beforeSend: function(){
      $.showIndicator();
    },
    success: function(data){
      $("#previewdetail").html(data);
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    },
    complete: function(){
      $.hideIndicator();
    }
  });
}

//提交回答
function submitMyanswer(id){
  $.ajax({
    url: '/yidong/pptaskview/reply?id='+ id, 
    type: 'POST',
    data: $("#reply_form").serialize(),
    dataType: "json", 
    beforeSend: function(){
      $.showIndicator();
    },
    success: function(data){
      if(data.code=="success"){
        $.toast("提交成功");
        $.closeModal(".popup-preview");
      }else{
        $.toast(data.msg);
      }
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    },
    complete: function(){
      $.hideIndicator();
    }
  });
}

var window_width = $(window).width();
var window_height = $(window).height();

//编辑题目
function editJournalDetail(id, ketangid){
  $.closeModal(".popup-preview");
  $("#previewdetail").empty();
  $.popup(".popup-editor");
  $("#editordetail").empty();
  $("#editordetail").html('<iframe src="/yidong/pptaskadd/index?id='+ id +'&ketangid='+ ketangid +'&rnum='+ Math.random() +'" width="'+ window_width +'" height="'+ (window_height-47) +'" style="border:none;"></iframe>');
}