<%@language = "javascript" %>
<%
/*  $Revision$
    $Id$

    File:           mld_stdmelding.asp
    Description:    Details van een mld kenmerk
    Parameters:     stdm_key
                    mode        show, edit, save

    Context:
    Note:           vervult zowel de _show, _edit als _save mode
                    Voorheen facmgtVB\mld_stdmeldingrecord.asp

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/stdmeldingselector.inc" -->
<!-- #include file="../Shared/srtgroepselector.inc" -->
<!-- #include file="../Shared/srtdeelselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="mld.inc" -->

<%
FCLTHeader.Requires({js: ["jquery-ui.js"]});

var mode = getQParam("mode", "show");
var stdm_key = getQParamInt("stdm_key", -1);
var disc_key = getQParamInt("disc_key", -1);
var srtdisc_key = getQParamInt("srtdisc_key", -1);
var simplemode = getQParamInt("simple", 0) == 1;

var authparams = user.checkAutorisation("WEB_MLDMGT");

if (stdm_key > 0)
{
  stdm_info = mld.mld_stdmeldinginfo(stdm_key);
  // Hier hebben we echt de waarde van mld_stdmelding_directklaar nodig,
  // en niet de defaultwaarde uit mld_disc_params_directklaar.
  var sql = "SELECT mld_stdmelding_directklaar"
          + "  FROM mld_stdmelding"
          + " WHERE mld_stdmelding_key = " + stdm_key;
  var oRs = Oracle.Execute(sql);
  stdm_info.directklaar = oRs("mld_stdmelding_directklaar").Value;
  oRs.Close();
}
else
{
  var prios = {}; // let op: geen array dus maar object!
  for (var i = 1; i <= 4; i++)
  {
    prios[i] = { text: { 1: L("lcl_mld_urg_kritiek"),
                         2: L("lcl_mld_urg_hoog"),
                         3: L("lcl_mld_urg_normaal"),
                         4: L("lcl_mld_urg_laag")
                       }[i],
                 key: i,
                 uitvoertijd: null,
                 eenheid: null
               };
  }
  stdm_info = { ins_srtdiscipline_key: srtdisc_key,
                ins_discipline_key: disc_key,
                stdmeldinggroep_key: -1,
                stdmelding_omschrijving: "",
                stdmelding_volgnr: "",
                srtgroep_key: -1,
                srtdeel_key: -1,
                prioriteiten: prios,
                planbaar: false,
                slabewaken: true,
                alg_onrgoed_niveau: 'R',
                freetext: 1
              };
}
stdm_info.disc_key = -1;
stdm_info.srtgroep_key = -1;
stdm_info.srtdeel_key = -1;
if (stdm_info.ins_srtinst_niveau == "D")
{
  stdm_info.disc_key = stdm_info.ins_srtinst_key;
}
else if (stdm_info.ins_srtinst_niveau == "G")
{
  stdm_info.srtgroep_key = stdm_info.ins_srtinst_key;
  var sql = "SELECT sg.ins_discipline_key"
          + "  FROM ins_srtgroep sg"
          + " WHERE sg.ins_srtgroep_key = " + stdm_info.srtgroep_key;
  var oRs = Oracle.Execute(sql);
  if (!oRs.eof)
    stdm_info.disc_key = oRs("ins_discipline_key").Value;
  oRs.Close();
}
else if (stdm_info.ins_srtinst_niveau == "S")
{
  stdm_info.srtdeel_key = stdm_info.ins_srtinst_key;
  var sql = "SELECT sg.ins_srtgroep_key"
          + "     , sg.ins_discipline_key"
          + "  FROM ins_srtdeel sd"
          + "     , ins_srtgroep sg"
          + " WHERE sd.ins_srtgroep_key = sg.ins_srtgroep_key"
          + "   AND sd.ins_srtdeel_key = " + stdm_info.srtdeel_key;
  var oRs = Oracle.Execute(sql);
  if (!oRs.eof)
  {
    stdm_info.srtgroep_key = oRs("ins_srtgroep_key").Value;
    stdm_info.disc_key = oRs("ins_discipline_key").Value;
  }
  oRs.Close();
}

%>

<html>
  <head>
<%  FCLTHeader.Generate();

    if (mode == "save")
    {
      var fields =  [ { dbs: "mld_ins_discipline_key",                     typ: "key",     frm: "disc_key" },
                      { dbs: "mld_stdmelding_omschrijving",                typ: "varchar", frm: "stdm_omschr" },
                      { dbs: "mld_stdmelding_notfrontend",                 typ: "check0",  frm: "notfrontend" },
                      { dbs: "prs_kostensoort_key",                        typ: "key",     frm: "kostensoort" },
                      { dbs: "alg_onrgoed_niveau",                         typ: "varchar", frm: "onrgoed_niveau" },
                      { dbs: "mld_stdmelding_notify",                      typ: "check0",  frm: "notify" },
                      { dbs: "mld_stdmelding_planbaar",                    typ: "check0",  frm: "planbaar" },
                      { dbs: "mld_stdmelding_freetext",                    typ: "key",     frm: "freetext" },
                      { dbs: "ins_srtinst_verplicht",                      typ: "check0",  frm: "obj_verplicht" },
                      { dbs: "mld_stdmelding_hint",                        typ: "varchar", frm: "aanwijzing" },
                      { dbs: "mld_stdmelding_autoorder",                   typ: "check0",  frm: "autoorder" },
                      { dbs: "mld_stdmelding_vereisdienst",                typ: "check0",  frm: "vereisdienst" },
                      { dbs: "prs_dienst_key",                             typ: "key",     frm: "dienst_key" },
                      { dbs: "mld_typeopdr_key",                           typ: "key",     frm: "typeopdr_key" },
                      { dbs: "mld_stdmelding_regime",                      typ: "key",     frm: "regime" },
                      { dbs: "mld_stdmelding_malusbasis",                  typ: "float",   frm: "malusbasis" },
                      { dbs: "mld_stdmelding_malus",                       typ: "float",   frm: "malus" },
                      { dbs: "mld_stdmelding_afhankelijk",                 typ: "check0",  frm: "afhankelijk" },
                      { dbs: "mld_stdmelding_image",                       typ: "varchar", frm: "image" },
                      { dbs: "mld_stdmelding_afmeldtext",                  typ: "key",     frm: "afmeldtext" },
                      { dbs: "mld_stdmelding_volgnr",                      typ: "number",  frm: "volgnummer" },
                      { dbs: "mld_stdmelding_prseigen",                    typ: "check0",  frm: "prseigen" },
                      { dbs: "mld_stdmelding_doublecheck",                 typ: "key",     frm: "doublecheck" },
                      { dbs: "mld_stdmelding_kopieerbaar",                 typ: "check0",  frm: "kopieerbaar" },
                      { dbs: "mld_stdmelding_kto",                         typ: "key",     frm: "kto" },
                      { dbs: "bes_ins_discipline_key",                     typ: "key",     frm: "bes_disc_key" },
                      { dbs: "mld_stdmelding_vervaldatum",                 typ: "date",    frm: "vervaldatum" },
                      { dbs: "mld_stdmelding_opdrtypevast",                typ: "check0",  frm: "opdrtypevast" },
                      { dbs: "mld_stdmeldinggroep_key",                    typ: "key",     frm: "mldgrp_key" },
                      { dbs: "mld_stdmelding_directklaar",                 typ: "key",     frm: "directklaar" },
                      { dbs: "mld_stdmelding_slabewaken",                  typ: "check0",  frm: "slabewaken" },
                      { dbs: "alg_onrgoed_obj_niveau",                     typ: "varchar", frm: "obj_show_niveau" },
                      { dbs: "alg_org_obj_niveau",                         typ: "number",  frm: "org_obj_niveau" },
                      { dbs: "mld_stdmelding_t_uitvoertijd.tijdsduur",
                        obj: "MLD_T_UITVOERTIJD",                          typ: "float",  frm: "uitvoertijd3" },
                      { dbs: "mld_stdmelding_t_uitvoertijd.eenheid",
                        obj: "MLD_T_UITVOERTIJD",                          typ: "varchar", frm: "dayshours3" }
                    ];

      // Checken of het eenheden selectveld met dagen/uren bij "Acceptatietijd" niet readonly was en wel is meegegeven.
      // Als dit eenheden selectieveld readonly was dan wordt deze niet opgeslagen en dan moet de tijdsduur ook niet opgeslagen worden.
      // Geldt ook voor de uitvoertijden (kritisch, hoog en laag). Uitvoertijd normaal is verplicht en altijd aanwezig.
      fields = shared.add_time_field(fields, "mld_stdmelding_t_accepttijd",   "accepttijd",   "dayshours_urg");
      fields = shared.add_time_field(fields, "mld_stdmelding_t_uitvtijd_pr1", "uitvoertijd1", "dayshours1");
      fields = shared.add_time_field(fields, "mld_stdmelding_t_uitvtijd_pr2", "uitvoertijd2", "dayshours2");
      fields = shared.add_time_field(fields, "mld_stdmelding_t_uitvtijd_pr4", "uitvoertijd4", "dayshours4");

      // Objecten beperken tot:
      var disc = getFParamInt("disc", -1);
      var srtgroep = getFParamInt("srtgroep", -1);
      var srtdeel = getFParamInt("srtdeel", -1);
      var ins_srtinst_frm = (srtdeel > 0? "srtdeel" : (srtgroep > 0? "srtgroep" : "disc"));
      var ins_srtinst_val = (srtdeel > 0? "S" : (srtgroep > 0? "G" : (disc > 0? "D" : "")));
      fields.push({ dbs: "ins_srtinst_key",                typ: "key",     frm: ins_srtinst_frm });
      fields.push({ dbs: "ins_srtinst_niveau",             typ: "varchar", val: ins_srtinst_val });

      // Kan verwijzen naar meerdere referenties (modules).
      var kanverwijzen_arr = getFParamIntArray("kanverwijzenmulti", [-1]); // Kanverwijzen
      var kanverwijzen = 0;
      for (var i = 0; i < kanverwijzen_arr.length; i++)
      {
        if (kanverwijzen_arr[i] > 0)
          kanverwijzen += kanverwijzen_arr[i];
      }
      if (kanverwijzen > 128)
          kanverwijzen = 128; // selecteer: "Alle meldingen", of "Geen" of een conbinatie van een van de andere verwijzingen.
      fields.push({ dbs: "mld_stdmelding_kanverwijzen",    typ: "number",  val: kanverwijzen });

      // Update, delete of insert uitvoeren.
      if (stdm_key > 0 && mode == "save")
      {
        var sql = buildUpdate("mld_stdmelding", fields) + " mld_stdmelding_key = " + stdm_key;
        var err = Oracle.Execute(sql, true);
      }
      else
      {
        fields.push({ dbs: "mld_stdmelding_key", typ: "key", seq: "mld_s_mld_stdmelding_key" });
        var mldIns = buildInsert("mld_stdmelding", fields);
        var stdmelding_key = mldIns.sequences["mld_stdmelding_key"];
        var err = Oracle.Execute(mldIns.sql, true);
        stdm_key = stdmelding_key;
      }

      if (err.friendlyMsg)
      {
        %><script>alert("<%=safe.jsstring(err.friendlyMsg)%>");</script><%
      }
      else
      {
        %><script>$(document).ready(function () {parent.window.location.href="mld_stdmelding.asp?mode=show&<%=(simplemode?"simple=1&":"")%>stdm_key=<%=stdm_key%>";} );</script><%
      }
      Response.End;
    }
    else if (stdm_key > 0 && mode == "delete")
    {
      sql = "UPDATE mld_stdmelding"
          + "   SET mld_stdmelding_VERWIJDER = SYSDATE"
          + " WHERE mld_stdmelding_key = " + stdm_key;
      var err = Oracle.Execute(sql, true);
%>    <script>
        $(document).ready(function () {
               FcltMgr.closeDetail(window, { stdm_key: <%=stdm_key%>,
                                             warning: "<%=safe.jsstring(err.friendlyMsg)%>",
                                             keepForm: <%=err.friendlyMsg? "true" : "false"%>
                                            });
        } );
      </script>
<%    Response.End;
    }
%>

    <script type="text/javascript" >
      function mld_submit()
      {
        if (!validateForm("u2"))
            return false;

        document.forms.u2.submit();
      }

      function mld_edit()
      {
        window.location.href = "mld_stdmelding.asp?mode=edit&<%=(simplemode?"simple=1&":"")%>stdm_key=<%=stdm_key%>";
      }
      function mld_delete()
      {
        if (confirm("<%=safe.jsstring(L("lcl_R_U_sure"))%>"))
          window.location.href = "mld_stdmelding.asp?mode=delete&<%=(simplemode?"simple=1&":"")%>stdm_key=<%=stdm_key%>";
      }
      function mld_cancel()
      {
        if (<%=stdm_key%> > 0)
          window.location.href = "mld_stdmelding.asp?mode=show&<%=(simplemode?"simple=1&":"")%>stdm_key=<%=stdm_key%>";
        else
          FcltMgr.closeDetail(window, { cancel: true });
      }

      function mldClose(params)
      {
<%      if (stdm_key == -1)
        { %>
          if (params.cancel)
          {
            FcltMgr.closeDetail(window, params);
            return true;
          }
<%      }
        else
        { // Bestaand kenmerk bewerkt, switch naar show-mode
%>
          if (params.close)
          {
            FcltMgr.closeDetail(window, { close: true})
          }
<%      } %>
        if (!params.keepForm)
          window.location.href = "mld_kenmerk.asp?mode=show&kenmerk_key=" + params.kenmerk_key;
      }

      function onChangeDiscipline()
      {
        //sgSrtgroep.setValue($("#stdm").val(), $("#stdm_show").val(), true, true, null, true);
        // Regel hierboven werkt niet goed omdat CheckExist een get call veroorzaakt om te kijken of waarde bestaat.
        // In de tussentijd verstoort CheckJustOne dit process met een $.getJSON()
        // Dus gewoon Groep leegmaken
        sgSrtgroep.setValue(-1, "", true, false, null, true);
        sgSrtgroep.CheckJustOne();
      }

      function callback_ins_info(data, textStatus, jqXHR)
      { // Zet de discipline indien niet ingevuld
        // setValue(key, txt, doonChange, checkExist, extraParam, lastTry)
        if ($("#disc").val() == -1)
          sgDiscObj.setValue(data.disc_key, data.disc_omschr, false /*doonChange*/, true /*checkExist*/);
        if ($("#srtgroep").val() == -1)
          sgSrtgroep.setValue(data.srtgroep_key, data.srtgroep_omschr, false /*doonChange*/, true /*checkExist*/);
        if ($("#srtdeel").val() == -1)
          sgSrtdeel.setValue(data.srtdeel_key, data.srtdeel_omschr, false /*doonChange*/, true /*checkExist*/);
      }

      function onChangeSrtgroep(srtgroep_key)
      { // Zet de discipline indien niet ingevuld.
        if (srtgroep_key > 0 && $("#disc").val() <= 0 && typeof sgDiscObj != "undefined")
        {
          $.getJSON("../Shared/get_ins_info.asp",
                    { srtgroep_key: srtgroep_key },
                      callback_ins_info);
        }
        sgSrtdeel.setValue(-1, "", true, false, null, true);
        sgSrtdeel.CheckJustOne();
      }

      function onChangeSrtdeel(srtdeel_key)
      { // Zet de soortgroep indien niet ingevuld.
        if (srtdeel_key > 0 && $("#srtgroep").val() <= 0 && typeof sgSrtgroep != "undefined")
        {
          jQuery.ajaxSetup({async: false});
          $.getJSON("../Shared/get_ins_info.asp",
                    { srtdeel_key: srtdeel_key },
                      callback_ins_info);
          jQuery.ajaxSetup({async: true});
        }
      }

      function onChangeAccepttijd(prio)
      {
        if (isNaN(parseFloat($("#accepttijd").val())))
          $("#dayshours_urg").prop("disabled", true);
        else
          $("#dayshours_urg").prop("disabled", false);
      }

      function onChangeUitvoertijd(prio)
      {
        if (isNaN(parseFloat($("#uitvoertijd" + prio).val())))
          $("#dayshours" + prio).prop("disabled", true);
        else
          $("#dayshours" + prio).prop("disabled", false);
      }

      function Upload()
      {
        url = "<%=protectQS.create("../shared/BijlagenForm.asp?module=MLDS" + (mode == "show"? "&reado=1" : ""))%>";
        FcltMgr.openModalDetail(url, L("lcl_change"),
                    { callback: function (data)
                            { if (data.filenaam)
                                $("#image").val(data.filenaam.replace(/.dwf$/i,'')); } // strip extensie
                            } );
      }

      jQuery(document).ready(function()
                             {
                               $('textarea').resize(function () { FcltMgr.resized(window) } );
                               $('textarea').autogrow();
                             });
    </script>
  </head>
  <body id="<%=mode == "edit"? "editbody" : "showbody"%>">
<%  var buttons = [];

    if (mode == "show")
      var buttons =  [ {title: L("lcl_change"), action:"mld_edit()",   icon: "wijzigen.png" },
                       {title: L("lcl_delete"), action:"mld_delete()", icon: "delete.png" } ];
    else
      var buttons =  [ {title: L("lcl_submit"), action:"mld_submit()", icon: "opslaan.png" },
                       {title: L("lcl_cancel"), action:"mld_cancel()", icon: "undo.png" } ];
    IFRAMER_HEADER(L("lcl_mld_stdmelding_frame"), buttons);

    if (mode == "edit")
    {
      myFIELD = RWFIELDTR;
      myTEXTAREA = RWTEXTAREATR;
      myCHECKBOX = RWCHECKBOXTR;
    }
    else
    {
      myFIELD = function (a, b, c, d, e) { ROFIELDTR(b, c, d, e) };
      myTEXTAREA = function (a, b, c, d, e) { ROTEXTAREATR(b, c, d, e) };
      myCHECKBOX = function (a, b, c, d, e) { ROCHECKBOXTR(b, c, d, e) };
    }

%>
    <div id="show">
      <form name="u2"
            action="mld_stdmelding.asp?mode=save&<%=(simplemode?"simple=1&":"")%>stdm_key=<%=stdm_key%>"
            method="post"
            target="hidFrameSubmit"
            onSubmit="mld_submit()">
<%      BLOCK_START("mldStdMld", L("lcl_mld_standaardmelding") + " " + (stdm_key > 0?stdm_info.mld_stdmelding_key : L("lcl_mld_new")));
        //ROFIELDTR("fldshort", L("lcl_key"), stdm_info.mld_stdmelding_key);
        // Vakgroep
        FCLTdisciplineselector("disc_key",
                               "sgDisc",
                               { label: L("lcl_mld_vakgroep"),
                                 disc_key: stdm_info.ins_discipline_key,
                                 module: "MLDA", // Module MLD en daarnaast ook de vakgroepen tonen zonder stdmeldingen zodat nieuwe stdmeldingen eraan toegevoegd kunnen worden (MLDA).
                                 perslidKey: user_key,
                                 autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                 srtdisc_key: stdm_info.ins_srtdiscipline_key,
                                 //urlAdd: [{urlParam: "srtdisc_key", field: "srtdisc_key"}],
                                 required: (mode == 'edit'),
                                 readonly: (mode == 'show')
                               });
        var params = { maxlength: 60,
                       required: true,
                       translate: { fld: "mld_stdmelding_omschrijving", key : stdm_info.mld_stdmelding_key }
                     }
        myFIELD("stdm_omschr", "fldtxt", L("lcl_mld_inf_Omschrijving"), stdm_info.stdmelding_omschrijving_dblang, params);
        myFIELD("volgnummer", "fldshort", L("lcl_mld_stdmelding_volgnummer"), stdm_info.stdmelding_volgnr, {maxlength: 3, suppressEmpty: true});
        // Laat alle meldinggroepen zien.
        sql = "SELECT g.mld_stdmeldinggroep_key akey"
            + ", " + lcl.xsqla('g.mld_stdmeldinggroep_naam', 'g.mld_stdmeldinggroep_key')
            + " FROM mld_stdmeldinggroep g"
            + " ORDER BY 2";
        FCLTselector("mldgrp_key",
                      sql,
                      { initKey: stdm_info.stdmeldinggroep_key,
                        label: L("lcl_mld_meldinggroep"),
                        emptyOption: "",
                        readonly: (mode == 'show'),
                        suppressEmpty: true
                      });
        if (!simplemode) {
            myCHECKBOX("notfrontend", "fldcheck", L("lcl_mld_notfrontend"), stdm_info.notfrontend);
            myCHECKBOX("notify", "fldcheck", L("lcl_mld_notify"), stdm_info.notify);
            sql = "SELECT prs_kostensoort_key"
                + "     , prs_kostensoort_oms"
                + "  FROM prs_kostensoort"
                + " ORDER BY UPPER(prs_kostensoort_oms)"
            FCLTselector("kostensoort",
                          sql,
                          { initKey: stdm_info.kostensoort,
                            label: L("lcl_charge_type"),
                            emptyOption: "",
                            readonly: (mode == 'show'),
                            suppressEmpty: true
                          });
            if (mode == 'edit' || stdm_info.vervaldatum) {  // suppressEmpty
                FCLTcalendar("vervaldatum",
                               { label: L("lcl_mld_expiration_date"),
                                 datum: stdm_info.vervaldatum,
                                 initEmpty: !stdm_info.vervaldatum, // Leeg laten als er geen vervaldatum is.
                                 volgnr: 1,
                                 readonly: (mode == 'show')
                               });
            }
            var kanverwijzen = "";
            // 0:  Geen verwijzingen
            // 1:  Melding (M)
            // 2:  Opdracht [O]
            // 4:  Reservering (R)
            // 8:  Bestelling (B)
            // 16: Bestelopdr [X] /* reserved for future use */
            // 32: Contract [C]   /* reserved for future use */
            // 64: Factuur [F]    /* reserved for future use */
            // 128: Alle meldingen
            if (mode == 'edit')
            {
              for (var i = 1; i < 256; i = i * 2)
              { // Een string met keys maken.
                kanverwijzen += ((stdm_info.kanverwijzen & i) == i? ((kanverwijzen == ""? "" : ",") + i) : "");
              }
              sql = "SELECT        128, " + safe.quoted_sql(mld.getrefmoduletext(128)) + " FROM DUAL"
                  + " UNION SELECT   1, " + safe.quoted_sql(mld.getrefmoduletext(1))   + " FROM DUAL"
                  + " UNION SELECT   2, " + safe.quoted_sql(mld.getrefmoduletext(2))   + " FROM DUAL"
                  + " UNION SELECT   4, " + safe.quoted_sql(mld.getrefmoduletext(4))   + " FROM DUAL"
                  + " UNION SELECT   8, " + safe.quoted_sql(mld.getrefmoduletext(8))   + " FROM DUAL"
                  //+ " UNION SELECT  16, " + safe.quoted_sql(mld.getrefmoduletext(16)) + " FROM DUAL" /* reserved for future use */
                  //+ " UNION SELECT  32, " + safe.quoted_sql(mld.getrefmoduletext(32)) + " FROM DUAL" /* reserved for future use */
                  //+ " UNION SELECT  64, " + safe.quoted_sql(mld.getrefmoduletext(64)) + " FROM DUAL" /* reserved for future use */
                  + " ORDER BY 1";
              FCLTselector("kanverwijzenmulti",
                            sql,
                            { initKey: kanverwijzen, // Variabele kanverwijzen is een string met keys.
                              label: L("lcl_mld_kanverwijzen"),
                              multi: true,
                              emptyOption: L("lcl_none"),
                              readonly: (mode == 'show')
                            });
            }
            else
            {
              for (var i = 1; i < 256; i = i * 2)
              { // Een string met maken.
                kanverwijzen += ((stdm_info.kanverwijzen & i) == i? ((kanverwijzen == ""? "" : ", ") + mld.getrefmoduletext(i)) : "");
              }
              ROTEXTAREATR("fldtxt", L("lcl_mld_kanverwijzen"), kanverwijzen, {suppressEmpty: true});
            }
        }
        BLOCK_END();

        BLOCK_START("mldRunTime", L("lcl_mld_run_time"));
        sql = "SELECT  'U', " + safe.quoted_sql(L("lcl_mld_hours")) + " FROM DUAL"
            + " UNION SELECT  'D', " + safe.quoted_sql(L("lcl_mld_days")) + " FROM DUAL"
            + " ORDER BY 2";
        var selectparams = { fieldName: "dayshours_urg",
                             sql: sql,
                             params: { id: "dayshours_urg",
                                       initKey: stdm_info.eenheid_accepttijd,
                                       readonly: (mode == 'show'),
                                       disable: !stdm_info.accepttijd
                                     }
                           }
        if (mode == "edit" || stdm_info.accepttijd) {  //suppressEmpty
            myFIELD("accepttijd", "fldshort", L("lcl_mld_timetoaccept"), stdm_info.accepttijd, {maxlength: 3, datatype: "float", html: "onChange='onChangeAccepttijd();'", selector: selectparams});
        }
        sql = "SELECT  1, " + safe.quoted_sql(L("lcl_mld_office_hours")) + " FROM DUAL"
            + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_opening_hours")) + " FROM DUAL"
            + " UNION SELECT  3, " + safe.quoted_sql(L("lcl_mld_24_7")) + " FROM DUAL"
            + " ORDER BY 1";
        FCLTselector("regime",
                      sql,
                      { initKey: stdm_info.regime,
                        label: L("lcl_mld_regime"),
                        readonly: (mode == 'show')
                      });
        selectparams.fieldName = "dayshours3";
        selectparams.params.id = "dayshours3";
        selectparams.params.initKey = (stdm_info.prioriteiten[3]? stdm_info.prioriteiten[3].eenheid : 'D')
        selectparams.params.disable = !(stdm_info.prioriteiten[3] && stdm_info.prioriteiten[3].uitvoertijd);
        myFIELD("uitvoertijd3", "flduitvoertijd3", L("lcl_mld_uitvoertijd_normaal"), (stdm_info.prioriteiten[3] && stdm_info.prioriteiten[3].uitvoertijd? Math.round(stdm_info.prioriteiten[3].uitvoertijd * 100) / 100 : ""), {maxlength: 4, required: true, datatype: "float", html: "onChange='onChangeUitvoertijd(3);'", selector: selectparams});
        if (mode == "edit" || stdm_info.prioriteiten[1]) {  //suppressEmpty
            selectparams.fieldName = "dayshours1";
            selectparams.params.id = "dayshours1";
            selectparams.params.initKey = (stdm_info.prioriteiten[1]? stdm_info.prioriteiten[1].eenheid : 'D')
            selectparams.params.disable = !(stdm_info.prioriteiten[1] && stdm_info.prioriteiten[1].uitvoertijd);
            myFIELD("uitvoertijd1", "flduitvoertijd1", L("lcl_mld_uitvoertijd_kritisch"), (stdm_info.prioriteiten[1] && stdm_info.prioriteiten[1].uitvoertijd? Math.round(stdm_info.prioriteiten[1].uitvoertijd * 100) / 100 : ""), {maxlength: 4, datatype: "float", html: "onChange='onChangeUitvoertijd(1);'", selector: selectparams});
        }
        if (mode == "edit" || stdm_info.prioriteiten[2]) {  //suppressEmpty
            selectparams.fieldName = "dayshours2";
            selectparams.params.id = "dayshours2";
            selectparams.params.initKey = (stdm_info.prioriteiten[2]? stdm_info.prioriteiten[2].eenheid : 'D')
            selectparams.params.disable = !(stdm_info.prioriteiten[2] && stdm_info.prioriteiten[2].uitvoertijd);
            myFIELD("uitvoertijd2", "flduitvoertijd2", L("lcl_mld_uitvoertijd_hoog"), (stdm_info.prioriteiten[2] && stdm_info.prioriteiten[2].uitvoertijd? Math.round(stdm_info.prioriteiten[2].uitvoertijd * 100) / 100 : ""), {maxlength: 4, datatype: "float", html: "onChange='onChangeUitvoertijd(2);'", selector: selectparams});
        }
        if (mode == "edit" || stdm_info.prioriteiten[4]) {  //suppressEmpty
            selectparams.fieldName = "dayshours4";
            selectparams.params.id = "dayshours4";
            selectparams.params.initKey = (stdm_info.prioriteiten[4]? stdm_info.prioriteiten[4].eenheid : 'D')
            selectparams.params.disable = !(stdm_info.prioriteiten[4] && stdm_info.prioriteiten[4].uitvoertijd);
            myFIELD("uitvoertijd4", "flduitvoertijd4", L("lcl_mld_uitvoertijd_laag"), (stdm_info.prioriteiten[4] && stdm_info.prioriteiten[4].uitvoertijd? Math.round(stdm_info.prioriteiten[4].uitvoertijd * 100) / 100 : ""), {maxlength: 4, datatype: "float", html: "onChange='onChangeUitvoertijd(4);'", selector: selectparams});
        }
        myCHECKBOX("slabewaken", "fldcheck", L("lcl_mld_slabewaken"), stdm_info.slabewaken);
        myCHECKBOX("planbaar", "fldcheck", L("lcl_mld_planbaar"), stdm_info.planbaar);
        if (!simplemode) {
            myFIELD("malusbasis", "fldshort", L("lcl_mld_malusbasis"), stdm_info.malusbasis, {maxlength: 9, datatype: "float", suppressEmpty: true});
            myFIELD("malus", "fldshort", L("lcl_mld_malus"), stdm_info.malus, {maxlength: 9, datatype: "float", suppressEmpty: true});
            myCHECKBOX("afhankelijk", "fldcheck", L("lcl_mld_afh_srtruimte_object"), stdm_info.afhankelijk);
        }
        BLOCK_END();

        BLOCK_START("mldHand", L("lcl_mld_behandeling"));
        sql = "SELECT  0, " + safe.quoted_sql(L("lcl_mld_onzichtbaar")) + " FROM DUAL"
            + " UNION SELECT  1, " + safe.quoted_sql(L("lcl_mld_optioneel")) + " FROM DUAL"
            + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_verplicht")) + " FROM DUAL"
            + " ORDER BY 1";
        FCLTselector("freetext",
                      sql,
                      { initKey: stdm_info.freetext,
                        label: L("lcl_mld_freetext"),
                        readonly: (mode == 'show')
                      });
        sql = "SELECT  1, " + safe.quoted_sql(L("lcl_mld_optioneel")) + " FROM DUAL"
            + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_verplicht")) + " FROM DUAL"
            + " ORDER BY 1";
        FCLTselector("afmeldtext",
                      sql,
                      { initKey: stdm_info.afmeldtext,
                        label: L("lcl_mld_afmeldtext"),
                        readonly: (mode == 'show')
                      });
        sql = "SELECT  0, " + safe.quoted_sql(L("lcl_mld_not")) + " FROM DUAL"
            + " UNION SELECT  1, " + safe.quoted_sql(L("lcl_mld_when_enter")) + " FROM DUAL"
            + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_when_accept")) + " FROM DUAL"
            + " UNION SELECT  3, " + safe.quoted_sql(L("lcl_mld_when_enter_accept")) + " FROM DUAL"
            + " ORDER BY 1";
        FCLTselector("doublecheck",
                      sql,
                      { initKey: stdm_info.doublecheck,
                        label: L("lcl_mld_doublecheck"),
                        readonly: (mode == 'show')
                      });
            myCHECKBOX("kopieerbaar", "fldcheck", L("lcl_mld_copyable"), stdm_info.kopieerbaar);
        if (!simplemode) {

            sql = "SELECT  'L', " + safe.quoted_sql(L("lcl_location")) + ", 1 FROM DUAL"
                + " UNION SELECT  'G', " + safe.quoted_sql(L("lcl_building")) + ", 2 FROM DUAL"
                + " UNION SELECT  'V', " + safe.quoted_sql(L("lcl_floor")) + ", 3 FROM DUAL"
                + " UNION SELECT  'R', " + safe.quoted_sql(L("lcl_room")) + ", 4 FROM DUAL"
                + " ORDER BY 3";
            FCLTselector("onrgoed_niveau",
                          sql,
                          { initKey: stdm_info.alg_onrgoed_niveau,
                            label: L("lcl_mld_onrgoed_niveau"),
                            readonly: (mode == 'show')
                          });
            myCHECKBOX("prseigen", "fldcheck", L("lcl_mld_prseigen"), stdm_info.prseigen);
            sql = "SELECT NULL, "      + safe.quoted_sql(L("lcl_mld_afhankelijk_vakgroep")) + " FROM DUAL"
                + " UNION SELECT  0, " + safe.quoted_sql(L("lcl_No")) + " FROM DUAL"
                + " UNION SELECT  1, " + safe.quoted_sql(L("lcl_Yes")) + " FROM DUAL"
                + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_initieel_fo")) + " FROM DUAL"
                + " ORDER BY 1 NULLS FIRST";
            FCLTselector("directklaar",
                          sql,
                          { initKey: stdm_info.directklaar,
                            label: L("lcl_mld_directklaar"),
                            readonly: (mode == 'show')
                          });
        }
        BLOCK_END();

        if (!simplemode) {
            BLOCK_START("mldObjD", L("lcl_mld_obj_details"));
            sql = "SELECT  '', " + safe.quoted_sql(L("lcl_mld_no_objects")) + ", 0 FROM DUAL"
                + " UNION SELECT  'L', " + safe.quoted_sql(L("lcl_location")) + ", 1 FROM DUAL"
                + " UNION SELECT  'G', " + safe.quoted_sql(L("lcl_building")) + ", 2 FROM DUAL"
                + " UNION SELECT  'V', " + safe.quoted_sql(L("lcl_floor")) + ", 3 FROM DUAL"
                + " UNION SELECT  'R', " + safe.quoted_sql(L("lcl_room")) + ", 4 FROM DUAL"
                + " ORDER BY 3";
            FCLTselector("obj_show_niveau",
                          sql,
                          { initKey: stdm_info.alg_onrgoed_obj_niveau || null,
                            label: L("lcl_mld_obj_show_niveau"),
                            readonly: (mode == 'show')
                          });
            sql = "SELECT  9, " + safe.quoted_sql(L("lcl_mld_no_objects")) + ", -2 FROM DUAL"
                + " UNION SELECT -1, " + safe.quoted_sql(L("lcl_mld_all_objects")) + ", -1 FROM DUAL"
                + " UNION SELECT 0, " + safe.quoted_sql(L("lcl_company")) + ", 0 FROM DUAL";
            for (var i = 1; i <= S("prs_max_dep_level"); i++)
              sql += " UNION SELECT " + i + ", " + safe.quoted_sql(L("lcl_dep_name_level" + i)) + ", " + i + " FROM DUAL"
              sql += " ORDER BY 3";
            FCLTselector("org_obj_niveau",
                          sql,
                          { initKey: stdm_info.alg_org_obj_niveau,
                            label: L("lcl_mld_dep_obj"),
                            readonly: (mode == 'show')
                          });
            myCHECKBOX("obj_verplicht", "fldcheck", L("lcl_mld_obj_verplicht"), stdm_info.srtinst_verplicht);
            if (mode == 'edit' || stdm_info.disc_key > 0 || stdm_info.srtgroep_key > 0 || stdm_info.srtdeel_key > 0)
            { // suppressEmpty
                myFIELD("object_restrict", "fldobjrestrict", null, L("lcl_mld_object_restrict"), {readonly: true});
                FCLTdisciplineselector("disc",
                                       "sgDiscObj",
                                       { label: L("lcl_discipline"),
                                         disc_key: stdm_info.disc_key,
                                         module: "INS",
                                         perslidKey: -1, // alles is toegestaan! Dan is perslidKey niet meer relevant. user_key,
                                         autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                         autRW: null, // alles is toegestaan! Dan is autRW niet meer relevant. "R",
                                         onChange: "onChangeDiscipline",
                                         readonly: (mode == 'show')
                                       });
                FCLTsrtgroepselector("srtgroep",
                                     "sgSrtgroep",
                                     { label: L("lcl_obj_group"),
                                       srtgroep_key: stdm_info.srtgroep_key,
                                       autfunction: "", // alles is toegestaan! autfunction,
                                       onChange: "onChangeSrtgroep",
                                       urlAdd: [{urlParam: "disc_key", field: "disc"}],
                                       readonly: (mode == 'show')
                                     });
                FCLTsrtdeelselector("srtdeel",
                              "sgSrtdeel",
                              { label: L("lcl_obj_sort"),
                                srtdeel_key: stdm_info.srtdeel_key,
                                autfunction: "", // alles is toegestaan! autfunction,
                                onChange: "onChangeSrtdeel",
                                urlAdd: [{urlParam: "srtgroep_key", field: "srtgroep"},
                                         {urlParam: "disc_key", field: "disc"}],
                                readonly: (mode == 'show')
                              });
            }
            BLOCK_END();
        }

        if (!simplemode) {
            BLOCK_START("mldOpdrD", L("lcl_mld_opdr_details"));
            sql = "SELECT prs_dienst_key"
                + "     , prs_dienst_omschrijving"
                + "  FROM prs_dienst"
                + " ORDER BY UPPER(prs_dienst_omschrijving)"
            FCLTselector("dienst_key",
                          sql,
                          { initKey: stdm_info.prs_dienst_key,
                            label: L("lcl_mld_behandel_dienst"),
                            emptyOption: "",
                            readonly: (mode == 'show'), suppressEmpty: true
                          });
            myCHECKBOX("vereisdienst", "fldcheck", L("lcl_mld_vereisdienst"), stdm_info.vereisdienst);
            myCHECKBOX("opdrtypevast", "fldcheck", L("lcl_mld_opdrtypevast"), stdm_info.opdrtypevast);
            sql = "SELECT mld_typeopdr_key"
                + "     , mld_typeopdr_omschrijving"
                + "  FROM mld_typeopdr"
                + " ORDER BY UPPER(mld_typeopdr_omschrijving)"
            FCLTselector("typeopdr_key",
                          sql,
                          { initKey: stdm_info.typeopdr_key,
                            label: L("lcl_mld_std_typeopdr"),
                            emptyOption: "",
                            readonly: (mode == 'show'), suppressEmpty: true
                          });
            myCHECKBOX("autoorder", "fldcheck", L("lcl_mld_autoorder"), stdm_info.autoorder);
            sql = "SELECT d.ins_discipline_key"
                + "     , ins_discipline_omschrijving"
                + "  FROM ins_tab_discipline d"
                + " WHERE d.ins_discipline_module = 'BES'"
                + "   AND d.ins_discipline_verwijder IS NULL"
                + "   AND EXISTS (SELECT 1"
                + "                 FROM mld_discipline md"
                + "                    , ins_srtdiscipline isd"
                + "                WHERE md.ins_srtdiscipline_key = isd.ins_srtdiscipline_key"
                + "                  AND isd.ins_srtdiscipline_bes = 1"
                + "                  AND md.ins_discipline_key = " + stdm_info.ins_discipline_key + ")"
                + " ORDER BY UPPER(d.ins_discipline_omschrijving)"
            FCLTselector("bes_disc_key",
                          sql,
                          { initKey: stdm_info.bes_ins_discipline_key,
                            label: L("lcl_mld_limited_bes_cat"),
                            emptyOption: "",
                            readonly: (mode == 'show'), suppressEmpty: true
                          });
            BLOCK_END();
        }

        BLOCK_START("mldOverig", L("lcl_mld_overig"));
        myTEXTAREA("aanwijzing",
                   "fldtxt",
                   L("lcl_mld_hint"),
                   stdm_info.hint_dblang,
                   {translate: { fld: "mld_stdmelding_hint", key : stdm_info.mld_stdmelding_key }, suppressEmpty: true}
                   );
        if (mode == 'edit')
        {
          var params = { type: "button",
                         html: "title='" + L("lcl_mld_symbol_upload") + "' onclick='Upload()'"
                       }
          ROFIELDTR("stdmsymbol_button", L("lcl_mld_symbol_upload"), L("lcl_mld_browse_upload"), params);
        }
        myFIELD("image", "fldtxt", L("lcl_mld_symbol_name"), stdm_info.image, {maxlength: 255, suppressEmpty: true});
        sql = "SELECT  0, " + safe.quoted_sql(L("lcl_mld_never")) + " FROM DUAL"
            + " UNION SELECT  1, " + safe.quoted_sql(L("lcl_mld_always")) + " FROM DUAL"
            + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_mld_opt_in")) + " FROM DUAL"
            + " UNION SELECT  3, " + safe.quoted_sql(L("lcl_mld_opt_out")) + " FROM DUAL"
            + " ORDER BY 1";
        if (!simplemode) {
            FCLTselector("kto",
                          sql,
                          { initKey: stdm_info.stdmelding_kto,
                            label: L("lcl_mld_in_KTO"),
                            readonly: (mode == 'show')
                          });
        }
        BLOCK_END();
        IFACE.FORM_END();

    if (!simplemode && stdm_key > -1 && (user.checkAutorisation("WEB_MLDMGT", true)))
    { // 2. De overruling van de SLA (acceptatietijd en uitvoertijd)
      page = "../mld/mld_stdmsrtruimte_search_list.asp?embedded=1&stdmelding_key=" + stdm_key;
      IFRAMER("mldstdmsrtruimte", page, { refreshOnClose: true, initHide: false } );
    }
%>
      </form>
    </div>
    <iframe src="../Shared/empty.html"
            name="hidFrameSubmit"
            FcltClose="mldClose"
            style="display:none"></iframe>
  </body>
</html>
