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

    File:           kpn_edit_kpncat.asp
    Status:         90%
    Description:    edit or add kostenplaats catalogus
    Parameters:     kpndisc_key (required)


    Context:
    Note:

*/ %>

<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/iface.inc" -->
<!--#include file="../Shared/disciplineselector.inc" -->

<%
FCLTHeader.Requires({plugins:["suggest", "jQuery"],
                     js: ["num2curr.js"]})

var kpn_key = getQParamInt("kpn_key");
var kpndisc_key = getQParamInt("kpndisc_key");

var autfunction = 'WEB_FINMSU';
var authparams = user.checkAutorisation(autfunction)

sql = "SELECT K.prs_kostenplaats_nr"
    + "     , K.prs_kostenplaats_omschrijving"
    + "  FROM prs_kostenplaats K"
    + " WHERE prs_kostenplaats_key = " + kpn_key;
oRs = Oracle.Execute(sql);
var kpn_nr  = oRs("prs_kostenplaats_nr").value;
var kpn_oms = oRs("prs_kostenplaats_omschrijving").value;
var kpn_disc;
var kpn_limiet;
oRs.Close();

if (kpndisc_key > -1)
{
  sql = "SELECT D.prs_kostenplaatsdisc_key"
      + "     , D.prs_kostenplaats_key"
      + "     , D.ins_discipline_key"
      + "     , D.prs_kostenplaatsdisc_limiet"
      + "  FROM prs_kostenplaatsdisc D"
      + " WHERE D.prs_kostenplaatsdisc_key = " + kpndisc_key;

  oRs = Oracle.Execute(sql);
  kpn_disc    = oRs("ins_discipline_key").value;
  kpn_limiet  = oRs("prs_kostenplaatsdisc_limiet").value;
  oRs.Close();
}

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script  type="text/javascript" >
      function checkLimit(evt)
      {
        evt = evt || window.event;
        var obj = evt.srcElement || evt.target;
        var limit = obj.value;
        if (limit != ""
             && (!isGoodNumber(limit,true,false,8,-1)
             || parseInt(limit, 10) < 0
             || parseInt(limit, 10) > 99999999))
        {
          alert(L("lcl_prs_bad_budget"));
          window.setTimeout(function(){$("#kpn_limiet").select()}, 0); // Zonder setTimeout functie gaat zetten van focus niet goed.
          return false;
        }
        return true;
      }
      function kpncat_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!validateForm("u2"))
              return false;
          document.forms.u2.submit();
      }
      function kpncat_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }
    </script>
  </head>

  <body id="editbody">
<%  var buttons =  [ {title: L("lcl_submit"), action:"kpncat_submit()", icon: "opslaan.png" },
                     {title: L("lcl_cancel"), action:"kpncat_cancel()", icon: "undo.png" }];

    IFRAMER_HEADER(L("lcl_kpn_kpncat_frame"), buttons);
%>
    <div id="edit">
      <form name="u2"
            action="kpn_edit_kpncat_save.asp?kpndisc_key=<%=kpndisc_key%>&"
            method="post"
            target="hidFrameSubmit"
            onSubmit="kpncat_submit();">
<%
      BLOCK_START("prsPerslid");
%>
        <input type="hidden" name="kpn_key" value="<%=kpn_key%>">
        <input type="hidden" name="kpndisc_key" value="<%=kpndisc_key%>">
<%
        ROFIELDTR( "fld"
                 , L("lcl_prs_dept_name")
                 , kpn_nr
                 );
        ROFIELDTR( "fld"
                 , L("lcl_prs_descr")
                 , kpn_oms
                 );
        FCLTdisciplineselector( "kpn_disc"
                              , "sgDisc"
                              , { label: L("lcl_bes_discipline")
                                , disc_key: kpn_disc
                                , module: "BES" // Alleen de disciplines van BES en MLD tonen
                                , perslidKey: user_key
                                , autfunctionKey: -1 // alles is toegestaan! authparams.autfunctionkey,
                                , srtdisc_key: null // alles mag
                                , required: true
                                });
        RWFIELDTR( "kpn_limiet"
                 , "fldkpnlimiet"
                 , L("lcl_prs_budget") + "&nbsp;" + S("currency_pref")
                 , kpn_limiet
                 , {datatype: "number", maxlength: 8, html: "onChange='checkLimit(event)'", required: true}
                 );
      BLOCK_END();
    IFACE.FORM_END();
%>
      </form>
      <iframe src="../Shared/empty.html" name="hidFrameSubmit" style="display:none"></iframe>
    </div>
  </body>
</html>
