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

    File:               bez/bez_select_bezoeker.asp
    Description:        Geavanceerd bezoeker selecteren
    Parameters:
    Context:
    Note:


*/ %>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"] });

var urole = getQParamSafe("urole");
var loc_key = getQParamInt("loc_key", -1);
var autfunction = "";
switch(urole)
{
  case "fe": autfunction = "WEB_BEZUSE";
           break;
  case "fo": autfunction = "WEB_BEZFOF";
           break;
  case "bo": autfunction = "WEB_BEZBOF";
           break;
  case "mi": autfunction = "WEB_BEZBAC";
           break;
}

if (S("bez_sel_internpersoon") == 1)
  // De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
  var authparams = user.checkAutorisation(autfunction);
%>
  <html>
    <head>
<%
      FCLTHeader.Generate();
%>
      <script>

        $(function()
        {
          $("#sName_key_show").focus();
        });

        function onChangeContactPerson(a1, a2, a3)
        {
          // Vul bedrijf van contact persoon in
          $("#bedrijf").val($("#toonbedrijf").val());
          // Maak interne persoon leeg indien aanwezig
<%        if (S("bez_sel_internpersoon") == 1)
          { %>
            $("#afdeling").val("");
            // setValue(key, txt, doonChange, checkExist, extraParam, lastTry)
            sgPerson.setValue(-1, "", false, false, null, true);
<%        } %>
        }

        function onChangeInternalPerson(a1, a2, a3)
        {
          // Vul afdeling van intern persoon in
          $("#afdeling").val($("#toonafdeling").val());
          // Maak contactpersoon leeg indien aanwezig
<%        if (S("bez_sel_contactpersoon") > 0)
          { %>
            $("#bedrijf").val("");
            // setValue(key, txt, doonChange, checkExist, extraParam, lastTry)
            sgContactPerson.setValue(-1, "", false, false, null, true);
<%        } %>
        }

        function bez_submit()
        {
            var data = {};
            if (($("#bedrijf").length > 0 && $("#bedrijf").val() != "") || ($("#sContact_key_show").length > 0 && $("#sContact_key_show").val()))
            {
                data.bedrijf = $("#bedrijf").val();
                data.naam = $("#sContact_key_show").val();
                data.contkey = $("#sContact_key").val();
            }
            else if ($("#afdeling").val() != "" || $("#sName_key_show").val())
            {
                data.bedrijf = $("#afdeling").val();
                data.naam = $("#sName_key_show").val();
                data.prskey = $("#sName_key").val();
                data.get_email = true;
            }
            else
                data.cancel = true;

            FcltMgr.closeDetail(window, data);
        }

        function bez_cancel()
        {
          FcltMgr.closeDetail(window, { cancel: true } );
        }

      </script>
    </head>

    <body class="fclt-modal" id="mod_queuemail">
<% MODAL_START(); %>
        <form name="u2">
<%        var titel = (S("bez_sel_contactpersoon") > 0? L("lcl_contact_pers") + (S("bez_sel_internpersoon") == 1? "/" : "") : "")
                    + (S("bez_sel_internpersoon") == 1? L("lcl_intern_pers") : "");
          MODAL_BLOCK_START("bezInput", titel, { "icon": "fa-user" });
          if (S("bez_sel_contactpersoon") > 0)
          {
            FCLTcontactpersoonselector("sContact_key",
                                       "sgContactPerson",
                                       { contactpersoonKey: -1,
                                         label: L("lcl_contact_pers"),
                                         onChange: "onChangeContactPerson",
                                         extracode: "B",
                                         locatiekey: (loc_key > 0? loc_key : null),
                                         moreinfo: true,
                                         extraParamField: "toonbedrijf",
                                         whenEmpty: L("lcl_search_generic")  // want filter
                                       });
            RWFIELDTR("bedrijf", "fld", L("lcl_company"), "", {readonly: true});
          }
          if (S("bez_sel_internpersoon") == 1)
          {
            FCLTpersoonselector("sName_key",
                                "sgPerson",
                                { perslidKey: -1,
                                  label: L("lcl_intern_pers"),
                                  onChange: "onChangeInternalPerson",
                                  extracode: "A",
                                  moreinfo:true,
                                  extraParamField: "toonafdeling",
                                  autlevel: authparams.PRSwritelevel,
                                  whenEmpty: L("lcl_search_generic")  // want filter
                                });
            RWFIELDTR("afdeling", "fld", L("lcl_department"), "", {readonly: true});
          }
          MODAL_BLOCK_END();

          var buttons =  [ {title: L("lcl_select"), icon: "fa-fclt-save", action: "bez_submit()", importance: 1 },
                           {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "bez_cancel()", importance: 3 }];
          SIMPLE_BLOCK_START();
          CreateButtons(buttons);
          SIMPLE_BLOCK_END();
%>
        </form>
        <% MODAL_END(); %>
    </body>
  </html>
<% ASPPAGE_END(); %>
