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

    File:               fac_edit_adres_save
    Status:             95%
    Description:        SUBMIT-form

    Parameters:
    Context:
    Note:

     SUBMIT-form
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/save2db.inc" -->

<% FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    }) %>
<%
  var adr_key = getQParamInt( "adr_key", -1 );

  var autfunction = "WEB_ALGMSU";
  var authparams = user.checkAutorisation(autfunction);

  var fields =  [ { dbs: "mld_adres_contactpers_bureau", typ: "varchar",  frm: "mld_adr_cnt_bur" },
                  { dbs: "mld_adres_telefoon", typ: "varchar",  frm: "mld_adr_tel" },
                  { dbs: "mld_adres_email", typ: "varchar",  frm: "mld_adr_email" },
                  { dbs: "mld_adres_naam", typ: "varchar",  frm: "mld_adr_nm" },
                  { dbs: "mld_adres_bezoek_adres", typ: "varchar",  frm: "mld_adr_bez_adr" },
                  { dbs: "mld_adres_bezoek_postcode", typ: "varchar",  frm: "mld_adr_bez_pcd" },
                  { dbs: "mld_adres_bezoek_plaats", typ: "varchar",  frm: "mld_adr_bez_pla" },
                  { dbs: "mld_adres_bezoek_land", typ: "varchar",  frm: "mld_adr_bez_lnd" },
                  { dbs: "mld_adres_post_adres", typ: "varchar",  frm: "mld_adr_pst_adr" },
                  { dbs: "mld_adres_gebouw_ruimte", typ: "varchar",  frm: "mld_adr_geb_rui" },
                  { dbs: "mld_adres_post_postcode", typ: "varchar",  frm: "mld_adr_pst_pcd" },
                  { dbs: "mld_adres_post_plaats", typ: "varchar",  frm: "mld_adr_pst_pla" },
                  { dbs: "mld_adres_post_land", typ: "varchar",  frm: "mld_adr_pst_lnd" },
                  { dbs: "mld_adres_contactpersoon", typ: "varchar",  frm: "mld_adr_cnt_prs" },
                  { dbs: "mld_adres_contactpers_telefoon", typ: "varchar",  frm: "mld_adr_cnt_tel" },
                  { dbs: "mld_adres_contactpers_email", typ: "varchar",  frm: "mld_adr_cnt_email" },
                  { dbs: "mld_adres_factuuradres", typ: "check",  frm: "mld_adr_fac_adr" },
                  { dbs: "mld_adres_opdrachtadres", typ: "check",  frm: "mld_adr_opd_adr" },
                  { dbs: "mld_adres_afleveradres", typ: "check",  frm: "mld_adr_afl_adr" },
                  { dbs: "alg_locatie_key", typ: "key",  frm: "locatiekey" }];

var warning = "";
if (adr_key > 0)
  {
    sql = buildUpdate("mld_adres", fields)
        + "     mld_adres_key = " + adr_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "mld_adres_key",         typ: "key",      seq: "mld_s_mld_adres_key" });
    var regIns = buildInsert("mld_adres", fields);
    var adr_key = regIns.sequences["mld_adres_key"];
    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(function ()
        {
          FcltMgr.closeDetail(window, { adr_key: <%=adr_key%>,
                                        warning: "<%=safe.jsstring(warning)%>",
                                        keepForm: <%=warning?"true":"false"%>,
                                        refresh: true
                                      });
        });
    </script>
  </head>
  <body>
  </body>
</html>
<% ASPPAGE_END(); %> 
