<%@ page import="ro.emid.common.action.browse.adrese.BrowseAdresaAction" %>
<%@ page import="ro.emid.common.db.OpenSCGAccessDB" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.types.Localitate" %>
<%@ page import="ro.emid.common.db.adrese.AdreseHelper" %>

<%
    final long idJudet = ObjectUtils.getLongValue(request.getParameter("idJudet"), -1);

//    final Localitate[] municipii =  OpenSCGAccessDB.searchMunicipiu("", "AND m.COD_DEPTO=" + idJudet, 0, 100000);
    final Localitate[] municipii =  AdreseHelper.getAdreseDao().searchLocalitate("", "AND m.COD_DEPTO=" + idJudet, 0, 100000);

%>

<respmesg>
    <% for (int i = 0; i < municipii.length; i++) {
        final Localitate municipiu = municipii[i]; %>

        <div class="municipiu">
            <span id="plusMunicipiu<%=municipiu.getCodMunic()%>">
                <nobr>
                    <% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>
                        <input type="checkbox" name="<%=BrowseAdresaAction.P_CHECK_MUNIC%>" value="<%=municipiu.getCodMunic()%>" onclick="browseAdresaCancelPropagation( this, event, 'localitatiMunicipiu<%=municipiu.getCodMunic()%>')"/>
                        <%--see browseAdresa.jsp for browseAdresaCancelPropagation--%>
                    <% } %>
                    <%=municipiu.getDenumireMunicipiu()%>
                </nobr>
            </span>
            <div id="localitatiMunicipiu<%=municipiu.getCodMunic()%>" class="childsContainer">
                 localitati
            </div>
        </div>

        <script type="text/javascript">
            var plusMunicipiu<%=municipiu.getCodMunic()%> = new Plus( "plusMunicipiu<%=municipiu.getCodMunic()%>", "localitatiMunicipiu<%=municipiu.getCodMunic()%>", function(){
               selectNode( this.obj);

               if( !this.loaded && this.getStatus() == PlusConstants.STATUS_MINUS){
                   $("localitatiMunicipiu<%=municipiu.getCodMunic()%>").innerHTML = "Se incarca ...";

                   new Ajax.Request('<%=GlobalAppConstants.APP_NAME%>?action=callcenter_browseGeo_loadLocalitati', {
                            method: 'post',
                            parameters: "idMunicipiu=<%=municipiu.getCodMunic()%>" ,
                            onComplete: function (originalRequest){
                                var response = getResponseMesg( originalRequest.responseText);

                                $( "localitatiMunicipiu<%=municipiu.getCodMunic()%>").innerHTML = response;

                                plusMunicipiu<%=municipiu.getCodMunic()%>.loaded = 1;

                                ScriptsUtils.evalScripts( response, false);
                            }
                   });
               }
           });
        </script>
    <% } %>
</respmesg>
