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

//选择班级
function chooseXzclass(){
  $.popup(".popup-editor");
  $("#editordetail").empty();
  $("#editordetail").html('<iframe src="/yidong/xzclass/index?rnum='+ Math.random() +'" width="'+ window_width +'" height="'+ (window_height-47) +'" style="border:none;"></iframe>');
}

//关闭班级
function guanbiXzclass(){
  $.closeModal(".popup-editor");
}

//清空所选班级
function clearForclassnames(){
  $("#forclassnamebox").empty();
  $("#detail_form").find("input[name='forclass']").val("");
}

//提交表单
$("#finished_button").on("click", function(){
  var title = $("#detail_form").find("input[name='title']");
  var courseid = $("#detail_form").find("select[name='courseid']");
  var forclass = $("#detail_form").find("input[name='forclass']");
  var ketangid = $("#detail_form").find("input[name='ketangid']");
  if($(title).val()==""){
    $.toast('请填写课堂标题');
    return false;
  }
  if($(courseid).val()=="" || $(courseid).val()=="0"){
    $.toast("请选择所属课程");
    return false;
  }
  if($(forclass).val()=="" || $(forclass).val()=="0"){
    $.toast("请选择适用班级");
    return false;
  }
  $.ajax({
    url: '/glketang/detail/basicok', 
    type: 'POST',
    dataType: "json", 
    data: $("#detail_form").serialize(),
    success: function(data){
      if(data.code=="success"){
        $.toast("保存成功");
        setTimeout(function(){window.location.href = "/yidong/glketang/index";},2000);
      }else{
        $.toast(data.msg);
      }
    },
    error: function(){
      $.toast("系统错误，请联系管理员");
    }
  });
  return false;
});

//取消按钮
$("#canceled_button").on("click", function(){
  window.location.href = "/yidong/glketang/index";
});