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

    File:               SuggestRegio.asp
    Description:        Suggereer regios
    Parameters:         k             De eerste paar letters
                        autlevel    : optioneel: rechten op dit niveau nodig
    Globals:
    Context:
    Note:
*/ %>

<%
JSON_Result = true;
%>

<!-- #include file="../../Shared/common.inc" -->
<!-- #include file="./suggest.inc" -->
<!-- #include file="./plaatsFilter.inc" -->

<%
var chars = getQParam("k", "");
var autlevel = getQParamInt("autlevel", -1);
var bAll = getQParamInt("SuggestAll", 0) == 1;
var filtcode = getQParam("filtcode", "");

chars = chars.replace(/\*/g,"%");

var filtClause = getFiltClauseRegio(filtcode);

if (autlevel > -1)
{
  filtClause +=" AND alg_regio_key IN "
             + "(SELECT alg_regio_key FROM fac_v_my_regions "
             + " WHERE prs_perslid_key = " + user_key
             + " AND niveau = " + autlevel + ") ";
}

sql = "SELECT r.alg_regio_key"
    + ", alg_regio_omschrijving naam"
    + ", NULL extra"
    + " FROM alg_v_aanwezigregio r"
    + " WHERE alg_regio_upper like " + safe.quoted_sql_wild(chars + "%")
    + filtClause
    + " ORDER BY 2"
WriteResult(sql, bAll, "naam", "alg_regio_key", "extra");
%>
