//屏幕大小
var winwidth = 0;
var winheight = 0;
$(document).ready(function(){
  winwidth = $(window).width();
  winheight = $(window).height();
  //console.log(winwidth +"*"+ winheight);
});

//弹出层索引
var index11, index12, index13r, index14;

//编辑章
function showChapterEditBox(chapterid, parentid){
  layer.load(0, {shade: [0.2, '#393D49']});
  index11 = layer.open({
    type: 2,
    id: 'onedialog',
    title: '编辑章',
    area: [(winwidth-10)+'px', '250px'],
    content: '/yidong/myqtree/chapter?courseid='+ courseid +'&chapterid='+ chapterid +'&parentid='+ parentid +'&rnum='+ Math.random()
  });
  layer.closeAll('loading');
}
function closeChapterEditBox(chapterid){
  layer.close(index11);
  if(chapterid=="" || chapterid=="0"){
    window.location.reload();
  }
}
//删除章
function showChapterDeleBox(chapterid){
  var layerbox = layer.confirm('这将同时删除该章下的<br>所有节、知识点、题库，<br>确认要删除吗？', {
    title: '注意',
    area: [(winwidth-10)+'px', '250px'],
    icon: 0,
    btn: ['确定','取消'] //按钮
  }, function(){
    $.ajax({
      url: '/glcourse/chapter/delete', 
      type: 'POST',
      data: {chapterid:chapterid},
      dataType: "json", 
      beforeSend: function(){
        layer.load(0, {shade: [0.2, '#393D49']});
      },
      success: function(data){
        if(data.code=="success"){
          layer.msg("成功", {icon:1});
          setTimeout(function(){window.location.reload();},2000);
        }else{
          layer.msg(data.msg, {icon:2});
        }
      },
      error: function(){
        layer.msg("系统错误，请联系管理员", {icon:2});
      },
      complete: function(){
        layer.closeAll('loading');
      }
    });
    return false;
  }, function(){
    //do nothing
  });
  return false;
}

//编辑节
function showSectionEditBox(sectionid, parentid){
  layer.load(0, {shade: [0.2, '#393D49']});
  index12 = layer.open({
    type: 2,
    id: 'twodialog',
    title: '编辑节',
    area: [(winwidth-10)+'px', '250px'],
    content: '/yidong/myqtree/section?courseid='+ courseid +'&sectionid='+ sectionid +'&parentid='+ parentid +'&rnum='+ Math.random()
  });
  layer.closeAll('loading');
}
function closeSectionEditBox(sectionid){
  layer.close(index12);
  if(sectionid=="" || sectionid=="0"){
    window.location.reload();
  }
}
//删除节
function showSectionDeleBox(sectionid){
  var layerbox = layer.confirm('这将同时删除该节下的<br>所有知识点、题库，<br>确认要删除吗？', {
    title: '注意',
    area: [(winwidth-10)+'px', '250px'],
    icon: 0,
    btn: ['确定','取消'] //按钮
  }, function(){
    $.ajax({
      url: '/glcourse/section/delete', 
      type: 'POST',
      data: {sectionid:sectionid},
      dataType: "json", 
      beforeSend: function(){
        layer.load(0, {shade: [0.2, '#393D49']});
      },
      success: function(data){
        if(data.code=="success"){
          layer.msg("成功", {icon:1});
          setTimeout(function(){window.location.reload();},2000);
        }else{
          layer.msg(data.msg, {icon:2});
        }
      },
      error: function(){
        layer.msg("系统错误，请联系管理员", {icon:2});
      },
      complete: function(){
        layer.closeAll('loading');
      }
    });
    return false;
  }, function(){
    //do nothing
  });
  return false;
}

//编辑知识点
function showKnowledEditBox(knowledid, parentid){
  layer.load(0, {shade: [0.2, '#393D49']});
  index13 = layer.open({
    type: 2,
    id: 'threedialog',
    title: '编辑知识点',
    area: [(winwidth-10)+'px', '250px'],
    content: '/yidong/myqtree/knowled?courseid='+ courseid +'&knowledid='+ knowledid +'&parentid='+ parentid +'&rnum='+ Math.random()
  });
  layer.closeAll('loading');
}
function closeKnowledEditBox(knowledid){
  layer.close(index13);
  if(knowledid=="" || knowledid=="0"){
    window.location.reload();
  }
}
//删除知识点
function showKnowledDeleBox(knowledid){
  var layerbox = layer.confirm('这将同时删除该知识点下的<br>所有题库，<br>确认要删除吗？', {
    title: '注意',
    area: [(winwidth-10)+'px', '250px'],
    icon: 0,
    btn: ['确定','取消'] //按钮
  }, function(){
    $.ajax({
      url: '/glcourse/knowled/delete', 
      type: 'POST',
      data: {knowledid:knowledid},
      dataType: "json", 
      beforeSend: function(){
        layer.load(0, {shade: [0.2, '#393D49']});
      },
      success: function(data){
        if(data.code=="success"){
          layer.msg("成功", {icon:1});
          setTimeout(function(){window.location.reload();},2000);
        }else{
          layer.msg(data.msg, {icon:2});
        }
      },
      error: function(){
        layer.msg("系统错误，请联系管理员", {icon:2});
      },
      complete: function(){
        layer.closeAll('loading');
      }
    });
    return false;
  }, function(){
    //do nothing
  });
  return false;
}