<script>




{*-- ここからjsでのデータ表示用 ---------------------------------------------------*}
function doHeaderEnable(pmode) { {*pmode:H Header有効・D 明細有効*}
  let h = $("#headerTop");
  let d = $("#detailTop");
  let m = $("#funcMenu");
  if (pmode == "H") { {*Header有効*}
    h.removeClass("noevent");
    d.addClass("noevent");

    $(".Func2").removeClass("noevent");
    $(".Func5").addClass("noevent");
    $(".Func9").addClass("noevent");

    {*ヘッダー項目クリア*}
    common.setValue(h.find(".ktktcd"), "");
    h.find(".keycd").focus();
  } else {
    h.addClass("noevent");
    d.removeClass("noevent");
    $(".Func2").addClass("noevent");
    $(".Func5").removeClass("noevent");
    $(".Func9").removeClass("noevent");
    {*データ部フォーカス*}
    d.find(".a")[0].focus();
  }
}

function clearDetail() {  {*明細クリア*}
  $("#detail .detail").remove();
}

function clearHeader() {  {*headerクリア*}
  let frm = $("#headerTop");
  let container = frm.closest(".container");
  doHeaderEnable("H");
  common.clearInputData(container);
}

function dspDetail() { {*データ表示*}
  let frm = $("#headerTop");
  let detail = $("#detail").find(".detail");

  clearDetail();  {*一旦クリア*}
  var el = "";

  var container = $(".container");
  sendData = {};
  sendData = common.getContainerInputData(container);

  common.postData(
    "./search.php"
    , sendData
    , function name(data) {
      var d = JSON.parse(data);
      if (d.ret == "0") {
        {*行作成*}
        d.ret_array.forEach((item, i) => {
          el += af993ax_detail.appendRow(item);
        });
        $("#detail").append(el);
        doHeaderEnable("D")

        let detail = $("#detail .detail");
        for(i = 0 ; i  < detail.length ; i++) {
          let $me = $(detail[i]);
          //common.setValue($me.find(".apat0"),'-1');
          for(j = 0 ; j <= 20 ; j++) {
            //console.log(".apat"+j);
            //console.log(common.getValue($me.find(".orgapat"+j)));
            common.setValue($me.find(".apat"+j),common.getValue($me.find(".orgapat"+j)));
          }
        }
      } else {
        el += af993ax_detail.appendRow(d.ret_array);
        $("#detail").append(el);
        doHeaderEnable("D")
      }
    }, function name(params) {
      alert(params.msg);
    }
  )
}
{*明細行用関数*}
var af993ax_detail = {
  appendRow: function (d) {
    var n = stringUtil.nvl;
    var row =
    ' <div class="col wp-100 detail"> ' +
    '<div class="col wp-100 rowinfo detailMain">' +
    '  <div class="col wp-100"> ' +
    '    <div class="col wd-490"> ' +
    '      <input name="mhnm" type="text" class="form-control input-sm item wd-090 mhnm keycd" readonly value="' + n(d.mhnm) + '"> '+
    '      <input name="apnm" type="text" class="form-control input-sm item wd-L apnm " readonly value="' + n(d.apnm) + '"> '+
    '      <input name="apid" type="text" class="form-control input-sm item wd-100 apid " readonly value="' + n(d.apid) + '"> '+
    '    </div>' +
    '    <div class="item wd-040" ><input name="dspapat0"  type="checkbox" class="form-control item input-sm wd-kbn dspapat0 apat0" disabled value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat1"  type="checkbox" class="form-control item input-sm wd-kbn apat1 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat2"  type="checkbox" class="form-control item input-sm wd-kbn apat2 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat3"  type="checkbox" class="form-control item input-sm wd-kbn apat3 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat4"  type="checkbox" class="form-control item input-sm wd-kbn apat4 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat5"  type="checkbox" class="form-control item input-sm wd-kbn apat5 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat6"  type="checkbox" class="form-control item input-sm wd-kbn apat6 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat7"  type="checkbox" class="form-control item input-sm wd-kbn apat7 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat8"  type="checkbox" class="form-control item input-sm wd-kbn apat8 " value="-1" tabindex="-1"/></div>' +
    '    <div class="item wd-040" ><input name="apat9"  type="checkbox" class="form-control item input-sm wd-kbn apat9 " value="-1" tabindex="-1"/></div>' +
    '    <input name="orgapat0" type="hidden" class="orgapat0 " value="' + n(d.apat0) + '"/>' +
    '    <input name="orgapat1" type="hidden" class="orgapat1 " value="' + n(d.apat1) + '"/>' +
    '    <input name="orgapat2" type="hidden" class="orgapat2 " value="' + n(d.apat2) + '"/>' +
    '    <input name="orgapat3" type="hidden" class="orgapat3 " value="' + n(d.apat3) + '"/>' +
    '    <input name="orgapat4" type="hidden" class="orgapat4 " value="' + n(d.apat4) + '"/>' +
    '    <input name="orgapat5" type="hidden" class="orgapat5 " value="' + n(d.apat5) + '"/>' +
    '    <input name="orgapat6" type="hidden" class="orgapat6 " value="' + n(d.apat6) + '"/>' +
    '    <input name="orgapat7" type="hidden" class="orgapat7 " value="' + n(d.apat7) + '"/>' +
    '    <input name="orgapat8" type="hidden" class="orgapat8 " value="' + n(d.apat8) + '"/>' +
    '    <input name="orgapat9" type="hidden" class="orgapat9 " value="' + n(d.apat9) + '"/>' +
    '    <input class="dummy a" style="widht:1px;" tabindex="-1"/>' +
    '  </div>' +
    '</div>' +
    '<hr>' +
    ' </div> ';
    return row;
  },
}


{*-- ここまでjsでのデータ表示用 ---------------------------------------------------*}

  $(document).ready(function(){
    /* 明細 高さ 自動設定
    //===================================================================*/
    common.setDetailHeight( $("#detail") );

    /* イベント
    //===================================================================*/
    //　F1
    $(document).on("click", ".Func1:not('.noevent')", function(e) {
    });
    //　F2
    $(document).on("click", ".Func2:not('.noevent')", function(e) {
      dspDetail();
    });
    //　F3
    $(document).on("click", ".Func3:not('.noevent')", function(e) {
    });
    //　F4
    $(document).on("click", ".Func4:not('.noevent')", function(e) {
    });
    //　F5 クリア
    $(document).on("click", ".Func5:not('.noevent')", function(e) {
      clearDetail();
      clearHeader();
    });
    //　F6
    $(document).on("click", ".Func6:not('.noevent')", function(e) {
    });
    //　F7
    $(document).on("click", ".Func7:not('.noevent')", function(e) {
    });
    //　F8
    $(document).on("click", ".Func8:not('.noevent')", function(e) {
    });
    //　F9 登録/実行
    $(document).on("click", ".Func9:not('.noevent')", function(e) {
      $(".btn-reg").trigger("click");
    });
    //　F10 Excel
    $(document).on("click", ".Func10:not('.noevent')", function(e) {
      $(".popup-af993m").trigger("click");
    });
    //　F11
    $(document).on("click", ".Func11:not('.noevent')", function(e) {
    });
    //　F12 メニュー/戻る
    $(document).on("click", ".Func12:not('.noevent')", function(e) {
      $('.btn-close').trigger('click');
    });

    //操作可/不可ボタン
    doHeaderEnable("H");

/*
    //操作可/不可ボタン
    if($("#detailTop").hasClass("noevent")){  //初期
      $(".Func5").addClass("noevent");
      $(".Func11").addClass("noevent");
    } else {  //表示後
      $(".Func2").addClass("noevent");
    }
*/


    //=== header ===

    //MENUボタン===============================
    $(document).on("regSuccess", ".btn-reg", function(e){
      alert("登録しました");
      $(".btn-clear").trigger("click");
    });


    $(document).on("click", ".btn-reg-before", function(e) {
      var detail = $("#detail .detail");
      var errflg = false;
    });

    //=== header ===
    $(document).on("focus", ".dummy", function(e) {
      $("#topmenu").find(".Func2").focus();
    });

    //=== body ===

    //====明細行動作======

    //=== footer ===

    // 初回フォーカス
    {if $errorMsg != ""}
      alert("{$errorMsg}");
      $('.btn-close').trigger('click');
    {/if}

    var form = $("#detailTop");
    if((form.hasClass("noevent"))){
      $(".header").find(".mhno").focus();
    }

  });

</script>
