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

<%
    final String codLocalitate = ObjectUtils.getStringValue(request.getParameter("codLocalitate"));
    final boolean isComuna = request.getParameter("isComuna") != null;

    Localitate loc = AdreseHelper.getAdreseDao().getLocalitate(codLocalitate);
    Localitate[] sate = null;
    Strada[] strazi = null;

    if( loc != null){
        if( loc.getCountCopii() > 0){
            sate = AdreseHelper.getAdreseDao().searchLocalitate2(codLocalitate);
        }

        strazi = AdreseHelper.getAdreseDao().getStrazi(codLocalitate);
    }
%>

<respmesg>
    <% if( strazi != null) for( int i = 0; i < strazi.length; i++){
        final Strada strada = strazi[i]; %>

    <div class="strada">
        <% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>
        <input type="checkbox" name="<%=BrowseAdresaAction.P_CHECK_STRADA%>" value="<%=strada.getCod()%>"/>
        <% } %>
                <span id="plusStrada<%=strada.hashCode()%>" onclick="selectNode( this); window.parent.BrowseWindow.showLocuriConsum( '<%=strada.getCod()%>')">
                    <nobr>
                        <span style="margin-right: 10px"><%=strada.getTipArtera()%></span><span><%=strada.getDenumire()%></span>
                    </nobr>
                </span>
    </div>
    <% } %>

    <% if( sate != null) for (int i = 0; i < sate.length; i++) {
        final Localitate localitate = sate[i]; %>

        <div class="localitate">
            <span id="plusLocalitate<%=localitate.getCodLocal()%>">
                <nobr>
                    <% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>
                        <input type="checkbox" name="<%=BrowseAdresaAction.P_CHECK_LOCAL%>" value="<%=localitate.getCodLocal()%>" onclick="browseAdresaCancelPropagation( this, event, 'straziLocalitate<%=localitate.getCodLocal()%>')"/>
                        <%--see browseAdresa.jsp for browseAdresaCancelPropagation--%>
                    <% } %>
                    <%=localitate.getDenumireLocalitate()%>
                </nobr>
            </span>
            <div id="straziLocalitate<%=localitate.getCodLocal()%>" class="childsContainer">
                 strazi ..
            </div>
        </div>

        <script type="text/javascript">
           var plusLocalitate<%=localitate.getCodLocal()%> = new Plus( "plusLocalitate<%=localitate.getCodLocal()%>", "straziLocalitate<%=localitate.getCodLocal()%>", function(){
               selectNode( this.obj);
               if( !this.loaded && this.getStatus() == PlusConstants.STATUS_MINUS){
                   $("straziLocalitate<%=localitate.getCodLocal()%>").innerHTML = "Se incarca ...";

                   new Ajax.Request('<%=GlobalAppConstants.APP_NAME%>?action=browse-adrese-load-strazi', {
                            method: 'post',
                            parameters: "codLocalitate=<%=localitate.getCodLocal()%>" ,
                            onComplete: function (originalRequest){
                                var response = getResponseMesg( originalRequest.responseText);

                                $( "straziLocalitate<%=localitate.getCodLocal()%>").innerHTML = response;

                                plusLocalitate<%=localitate.getCodLocal()%>.loaded = 1;

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

</respmesg>
