function contentFade(action){
  if(action === "in"){
    $("#fadeDiv").show()
  }else{
    $("#fadeDiv").hide()
  }
}

function sessionReload(){
  $.ajax({
    url: '/refreshSession',
    type: 'GET',
    success: function(){location.reload();},
    error:function(){}
  });
}

$(document).on('click', '.allChk', function (){
  $(this).parents('table').find('[type="checkbox"]').prop("checked", this.checked);
})
$(document).on('click', '.page-item', function (){
  searchFormSubmit($(this).attr("data-pageindex"))
})
$(document).on('change', '#rowCnt', function (){
  searchFormSubmit(1)
})
function searchFormSubmit(pageIndex){
  $("#pageIndex").val(pageIndex);
  $("#searchBtn").click();
}


$(document).on('mouseenter', '.firstMenuLink', function (event){
  $(".secondMenu").hide();
  const targetMenu = $(this).parent().find(".secondMenu");
  targetMenu.show()
  targetMenu.find("ul").css("padding-top",(event.clientY-20)+"px")
})
$(document).on('mouseenter', '.secondMenuLink', function (event){
  $(".thirdMenu").hide();
  const targetMenu = $(this).parent().find(".thirdMenu");
  targetMenu.show()
  targetMenu.find("ul").css("padding-top",(event.clientY-20)+"px")
})
$(document).on('mouseleave', '.menuDiv', function (){
  $(".secondMenu").hide();
  $(".thirdMenu").hide();
})

$(document).on('change', '#fileInputer', function (){
  for(const file of this.files){
    setFileDiv(file, files.push(file));
  }
  this.value = null;
})

function byteCalculation(size) {
  const bytes = parseInt(size);
  const s = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
  const e = Math.floor(Math.log(bytes)/Math.log(1024));

  if(e === "-Infinity") return "0 "+s[0];
  else return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];

}

$(document).on('click', '.fileDelete', function (){
  const target = $(this);
  files[Number(target.attr("data-fileidx"))].isDelete = true;
  target.parent().remove();
  const uploadDiv = $("#uploadDiv");
  if(uploadDiv.children().length === 0){
    uploadDiv.append("<br>파일을 업로드 해주세요.");
  }
})
$(document).on('click', '.uploadedFileDelete', function (){
  const target = $(this).parent().find("span")[0];
  if(target.className===""){
    target.className = "text-decoration-line-through";
  }else{
    target.className = "";
  }
})

$(document).on('click', '.fileDownLink', function (){
  let url = "/file/fileDownload?"
  url += "board="+$(this).attr("data-board");
  url += "&parentKey="+Number($("#viewModalPlanKey").val());
  url += "&fileSeq="+$(this).attr("data-fileseq");
  window.open(encodeURI(url));
})