<%@ 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.Strada" %>
<%@ page import="ro.emid.common.db.adrese.AdreseHelper" %>

<%
    final Logger LOG = Logger.getLogger("cautStradaResp_jsp");

    final String codMun = ObjectUtils.getStringValue(request.getParameter("codMun"));
    final String municipiu = ObjectUtils.getStringValue( request.getParameter("mun"));
    final String codLocalitate = ObjectUtils.getStringValue(request.getParameter("codloc"));
    final String localitate = ObjectUtils.getStringValue( request.getParameter("loc"));
    final String tipArtera  = ObjectUtils.getStringValue( request.getParameter("tipArtera")).trim();
    final String q = ObjectUtils.getStringValue(request.getParameter("q")).trim();

    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);

    try {
        Strada[] strazi = AdreseHelper.getAdreseDao().searchStrazi(codMun, municipiu, codLocalitate, localitate, tipArtera, q, beginIndex, maxCount);
        long totalCount = AdreseHelper.getAdreseDao().searchStraziCount(codMun, municipiu, codLocalitate, localitate, tipArtera, q);
        LOG.debug("GASIT " + strazi.length + " STRAZI");
%>
<respmesg>
        {
            totalResultCount : <%=totalCount%>,
            list : [
                <% for (int i = 0; i < strazi.length; i++) {  %>
                    <%=(i==0?"":",") %>
                    {
                        key : "-1",
                        value : "<%=ro.emid.common.utils.Util.escapeToJs(strazi[i].getDenumire() + '-' + strazi[i].getTipArtera())%>",
                        cod : "<%=strazi[i].getCod()%>",
                        tipArtera : "<%=ro.emid.common.utils.Util.escapeToJs(strazi[i].getTipArtera())%>",
                        denumire : "<%=ro.emid.common.utils.Util.escapeToJs(strazi[i].getDenumire())%>"
                    }
                <% } %>
            ]
        }
</respmesg>

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

