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

    File:           prs_bedrijf_search.asp
    Description:   Toont zoekvelden voor lijst van bedrijven
    Parameters:
    Context:       Vanuit menu
    Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/xd.inc" -->

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

/***** Get webform parameters *****/

var loc_key = getQParamInt("locatie_key", -1);
var intern = getQParamInt("intern", 0) == 1;

// optional prefilling params
var pcompanyName = getQParam("pcompanyName", -1);
var pbezoekPostcode = getQParam("pbezoekPostcode", -1);
var pbezoekPlaats = getQParam("pbezoekPlaats", -1);
var pdienst_key = getQParamInt("pdienst_key", -1);
var preltype_key = getQParamInt("prelatietype_key", -1);
var pcontactPrs = getQParam("pcontactPrs", -1);

/***** End get webform parameters *****/

// So what authorization must we check?
var autfunction = "";
if (intern)
  autfunction = "WEB_PRSMAN";   // TODO of PRSUSE?
else
  autfunction = "WEB_RELMAN";
var authparams = user.checkAutorisation(autfunction);

// VALIDATE AND PREPARE
var there_is_dienst = false;
var tsql = "SELECT prs_dienst_key FROM prs_dienst";
var toRs = Oracle.Execute( tsql );
if (!toRs.eof)
  there_is_dienst = true;
toRs.close();
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
<% if (xd.enabled()) { %>
      function xdclicked()
      {
        var doxd = document.getElementById("xd").checked;
        $(".noxd").toggle(!doxd); // Kan want geen secsearch
        $(".onlyxd").toggle(doxd);
      }
<% } %>
      function doSubmit()
      {
<% if (xd.enabled()) { %>
        if ($("#xd").is(":checked"))
        {
              $("form[name=u2]").attr("action", "prs_bedrijf_search_list_xd.asp");
        } else {
              $("form[name=u2]").attr("action", "prs_bedrijf_search_list.asp");
        }
<% } %>
        // Submitten met kenmerken
        doSubmitWithKenmerken();
      }

      function myModal()
      {
        var lvl = "";
        var key = 0;
        var bld_key = "";
        var url = "load_kenmerk.asp?disc=" + "&urole=bo" + "&advanced=1" + "&niveau=B";
        var titel = "";
        showKenmerkModal(url, titel)
      }
    </script>
  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" method="get" action="prs_bedrijf_search_list.asp" target="workFrame">
        <input type="hidden" name="intern" value="<%=intern? 1 : 0%>">
<%    BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%
            if (xd.enabled())
                RWCHECKBOXTR("xd", "fldxd", L("lcl_xd_crossdomain"), false, {html: "onclick='xdclicked()'"});
%>
            <tr class="primsearch">
              <td class="label"><label for="companyName"><%=L("lcl_prs_companies_name")%>:</label></td>
              <td><input type="text" class="fld wildcard" name="companyName" <%=(pcompanyName != -1) ? "value='" + safe.htmlattr(pcompanyName) + "'" : ""%>></td>
            </tr>
            <tr class="primsearch">
              <td class="label"><label for="bezoekPostcode"><%=L("lcl_prs_companies_bezoek_postcode")%>:</label></td>
              <td><input type="text" class="fld wildcard" name="bezoekPostcode" <%=(pbezoekPostcode != -1) ? "value='" + safe.htmlattr(pbezoekPostcode) + "'" : ""%>></td>
            </tr>
            <tr class="primsearch">
              <td class="label"><label for="bezoekPlaats"><%=L("lcl_prs_companies_bezoek_plaats")%>:</label></td>
              <td><input type="text" class="fld wildcard" name="bezoekPlaats" <%=(pbezoekPlaats != -1) ? "value='" + safe.htmlattr(pbezoekPlaats) + "'" : ""%>></td>
            </tr>
<%
              var sqlrelatietype = "SELECT prs_relatietype_key"
                                 + "     , " + lcl.xsqla("prs_relatietype_omschrijving", "prs_relatietype_key")
                                 + "  FROM prs_relatietype"
                                 + " WHERE prs_relatietype_verwijder IS NULL"
                                 + " ORDER BY UPPER(" + lcl.xsql("prs_relatietype_omschrijving", "prs_relatietype_key") + ")";
              FCLTselector("relatietypekey",
                           sqlrelatietype,
                           { label: L("prs_relatietype"),
                             initKey: preltype_key,
                             trclass: "primsearch noxd",
                             emptyOption: L("lcl_search_generic")
                           });
%>
            </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td class="searchkolom2">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%            if (there_is_dienst && !intern)
              { %>
                <!-- Locatie en gebouw -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="loctekst"><%=L("lcl_location")%>:</label></td>
                  <td>
                    <input type="text" class="fldsrch wildcard" name="loctekst" value="">
                  </td>
                </tr>
<%                FCLTplaatsselector(authparams.PRSreadlevel, { locatiekey: loc_key,
                                                              startlevel: 2, // locatie
                                                              eindlevel: 3, // gebouw
                                                              trclass: "noxd",
                                                              whenEmpty: L("lcl_search_generic")  // want filter
                                                            });
%>

                <!-- Uitvoerende -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="diensttekst"><%=L("lcl_prs_companies_dienst")%>:</label></td>
                  <td>
                    <input type="text" class="fldsrch wildcard" name="diensttekst" value="">
                  </td>
                </tr>
<%              var sql_dienst = "SELECT prs_dienst_key"
                               + "     , " + lcl.xsqla('prs_dienst_omschrijving', 'prs_dienst_key')
                               + "  FROM prs_dienst"
                               + " ORDER BY UPPER(" + lcl.xsql('prs_dienst_omschrijving', 'prs_dienst_key') + ")";
                FCLTselector("dienstkey",
                             sql_dienst,
                             { label: L("lcl_prs_companies_dienst"),
                               initKey : pdienst_key,
                               trclass:"primsearch noxd",
                               emptyOption: L("lcl_search_generic")
                             });
              } %>
              <tr class="primsearch">
                <td class="label"><label for="contactPrs"><%=L("lcl_prs_companies_contact_person")%>:</label></td>
                <td><input type="text" class="fld wildcard" name="contactPrs" <%=(pcontactPrs != -1) ? "value='" + safe.htmlattr(pcontactPrs) + "'" : ""%>></td>
              </tr>
<%            RWCHECKBOXTR("tooningids", "fldnotingids", L("lcl_prs_companies_ingids"), 0, {trclass: "noxd"}) %>
            </table>
          </td><!-- end column 2-->
        </tr>
<%      if (!intern)
        { %>
          <!--  checkboxen -->
          <tr>
            <td colspan="2">
              <div id="statusboxes">
                  <input type="checkbox" class="fldcheck" name="leverancier" id="leverancier" value="1"><label for="leverancier"><%=L("lcl_prs_companies_leverancier")%></label>
                  <input type="checkbox" class="fldcheck" name="uitvoerende" id="uitvoerende" value="1"><label for="uitvoerende"><%=L("lcl_prs_companies_uitvoerende")%></label>
                  <input type="checkbox" class="fldcheck" name="contract" id="contract" value="1"><label for="contract"><%=L("lcl_prs_companies_contract")%></label>
                  <input type="checkbox" class="fldcheck" name="huurder" id="huurder" value="1"><label for="huurder"><%=L("lcl_prs_companies_huurder")%></label>
              </div>
            </td>
          </tr>
<%      } %>
<%    BLOCK_END();

      var buttons =  [ {title: L("lcl_search"), action:"doSubmit()", id: "bSearch" },
                       {title: L("lcl_obj_advanced"), action:"myModal()", id: "bAdvanced", xclass: "noxd" } ];
      CreateButtons(buttons, { entersubmit: true });
%>
      </form>
    </div> <!-- search -->

    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload="FcltMgr.iframeLoaded(this)"
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html>