<%@ page import="ro.emid.common.action.browse.adrese.BrowseAdresaAction" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.types.Localitate" %>
<%@ page import="ro.emid.common.db.adrese.AdreseHelper" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.AppProperties" %>

<style type="text/css">
    @import url('<%=AppConstants.WEB_RESOURCE_PATH%>/styles/browse-adrese.css');
</style>

<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/prototype-1.4.1.js?<%=AppProperties.getInstance().getVersion()%>"></script>

<link rel="stylesheet" type="text/css" href="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/tree/plus/plus.css">
<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/tree/plus/plus.js"></script>
<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/emid-utils.js"></script>


<%
    final Localitate[] judete = AdreseHelper.getAdreseDao().getJudete();
%>

<form action="<%=GlobalAppConstants.APP_NAME%>?action=callcenter_browseGeoSave" method="post">
    <div style="background-color: #ffffff; padding: 5px;">
        <span id="plusFiliala"><nobr><b><%=CategoryAccessDB.getFiliala().getName()%></b></nobr></span>
        <div id="judeteFiliala" class="childsContainer">
            <% for ( int i = 0; i < judete.length; i++) {
                final Localitate judet = judete[i]; %>

            <% if( judet.getCountCopii() > 0) { %>
            <div class="judet">
                     <span id="plusJudet<%=judet.getCodJudet()%>">
                         <nobr>
                             <% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>
                             <input type="checkbox" name="<%=BrowseAdresaAction.P_CHECK_JUDET%>" value="<%=judet.getCodJudet()%>" onclick="browseAdresaCancelPropagation( this, event, 'municipiiJudet<%=judet.getCodJudet()%>')"/>
                             <% } %>
                             j. <%=judet.getDenumireJudet()%>
                         </nobr>
                     </span>
                <div id="municipiiJudet<%=judet.getCodJudet()%>" class="childsContainer">
                    municipii ...
                </div>
            </div>
            <script type="text/javascript">
                var plusJudet<%=judet.getCodJudet()%> = new Plus( "plusJudet<%=judet.getCodJudet()%>", "municipiiJudet<%=judet.getCodJudet()%>", function(){
                    selectNode( this.obj);
                    if( !this.loaded && this.getStatus() == PlusConstants.STATUS_MINUS){
                        $("municipiiJudet<%=judet.getCodJudet()%>").innerHTML = "Se incarca ...";

                        new Ajax.Request('<%=GlobalAppConstants.APP_NAME%>?action=browse-adrese-load-localitati-comune', {
                            method: 'post',
                            parameters: "idJudet=<%=judet.getCodJudet()%>" ,
                            onComplete: function (originalRequest){
                                var response = getResponseMesg( originalRequest.responseText);

                                $( "municipiiJudet<%=judet.getCodJudet()%>").innerHTML = response;


                                plusJudet<%=judet.getCodJudet()%>.loaded = 1;

                                ScriptsUtils.evalScripts( response, false);
                            }
                        });
                    }
                });
            </script>
            <% } else { %>
            <div class="judet" style="padding-left:12px">
                <span><nobr>j. <%=judet.getDenumireJudet()%></nobr></span>
            </div>
            <% } %>

            <% } %>
        </div>
    </div>


        <%--<tr>--%>
            <%--<td>--%>
                <%--<% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>--%>
                <%--<input type="submit" value="Salveaza">--%>
                <%--<input type="button" value="Renunta" onclick="window.close()">--%>
                <%--<% } %>--%>
            <%--</td>--%>
        <%--</tr>--%>

        <%--<tr>--%>
            <%--<td colspan="3">--%>
                <%--<span class="legenda-judet"></span> - judet;&nbsp;&nbsp;--%>
                <%--<span class="legenda-municipiu"></span> - municipiu/comuna;&nbsp;&nbsp;--%>
                <%--<span class="legenda-localitate"></span> - localitate/sat;&nbsp;&nbsp;--%>
                <%--<span class="legenda-strada"></span> - strada;&nbsp;&nbsp;--%>
            <%--</td>--%>
        <%--</tr>--%>
    <%--</table>--%>
</form>


<script type="text/javascript">

    var plusFiliala = new Plus("plusFiliala", "judeteFiliala");
    plusFiliala.setMinus();

    var selectedNode = null;
    var tableClienti = null;

    function selectNode( node){
        if ( selectedNode != null){
            Element.removeClassName( selectedNode, "selectedNode");
        }
        selectedNode = node;
        Element.addClassName( selectedNode, "selectedNode" );
    }

    function browseAdresaCancelPropagation( zeCheck, e, childsContainerId){
        if (!e) var e = window.event;

        //daca este expandat, oprim propagarea eventului pentru a nu face collapse la nod
        if( $( childsContainerId).style.display != "none" ){
            e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
        }
    }

</script>