<%@ page import="org.apache.log4j.Logger"%>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.components.sugest.base.SugestConstants" %>
<%@ page import="ro.emid.common.types.Localitate" %>
<%@ page import="ro.emid.common.db.adrese.AdreseHelper" %>

<%
    final Logger LOG = Logger.getLogger("cautLocalitateResp_jsp");
    final String codMun = ObjectUtils.getStringValue(request.getParameter("codMun"));
    final String municipiu = ObjectUtils.getStringValue(request.getParameter("mun"));
    final String whatToSearch = ObjectUtils.getStringValue(request.getParameter("q"));

    final int beginIndex = ObjectUtils.getIntValue( request.getParameter( SugestConstants.SUGEST_Q_BEGIN_INDEX), 0);
    final int maxCount = ObjectUtils.getIntValue( request.getParameter( SugestConstants.SUGEST_Q_MAX_COUNT), 10);

    LOG.debug(" whatToSearch=" + whatToSearch);
    try {
        final Localitate[] localitati = AdreseHelper.getAdreseDao().searchLocalitate2(codMun, municipiu, whatToSearch, beginIndex, maxCount);
        LOG.debug("GASIT " + localitati.length + " LOCALITATI");

        final long totalCount = AdreseHelper.getAdreseDao().getCountLocalitate2(codMun, municipiu, whatToSearch);
%>

<respmesg>
    {
        totalResultCount : <%=totalCount%>,
        list: [
            <% for (int i = 0; i < localitati.length; i++) {  %>
                <%=(i==0?"":",") %> 
                {
                    key : "<%=localitati[i].getCodLocal()%>",
                    value : "<%=ro.emid.common.utils.Util.escapeToJs(localitati[i].getDenumireLocalitate())%> - j.<%=ro.emid.common.utils.Util.escapeToJs(localitati[i].getDenumireJudet())%>",
                    denLocalitate : "<%=ro.emid.common.utils.Util.escapeToJs(localitati[i].getDenumireLocalitate())%>",
                    denJudet : "<%=ro.emid.common.utils.Util.escapeToJs(localitati[i].getDenumireJudet())%>",
                    codMunicipiu : "<%=localitati[i].getCodMunic()%>",
                    denMunicipiu : "<%=ro.emid.common.utils.Util.escapeToJs(localitati[i].getDenumireMunicipiu())%>"
                }
            <% } %>
        ]
    }
</respmesg>

<%} catch (Throwable t) {
    LOG.error("Eroare get lista localitati", t);
}%>