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

<% if( request.getAttribute("close") != null) { %>

    <script type="text/javascript">
        window.opener.<%=BrowseAdresaAction.Util.getJSCBF( request)%>;
        window.close();
    </script>

<% return;} %>


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

<form action="<%=GlobalAppConstants.APP_NAME%>?action=browseGeoSave" method="post">
    <table width="100%" border="0">
        <tr valign="top">
            <td>
                <b>Localizare geografica</b>
            </td>
        </tr>
        <tr valign="top"><td>
            <div class="container">
                <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=browseGeo_loadMunicipii', {
                                                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>
        </td>
        </tr>

        <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="judet_legenda"></span> - judet;&nbsp;&nbsp;
                <span class="municipiu_legenda"></span> - municipiu/comuna;&nbsp;&nbsp;
                <span class="localitate_legenda"></span> - localitate/sat;&nbsp;&nbsp;
                <span class="strada_legenda"></span> - strada;&nbsp;&nbsp;
            </td>
        </tr>
    </table>
</form>


<style type="text/css">

    .container{
        padding:3px;
        background-color: white;
        border:1px solid gray;
        font-size:12px;
        cursor:auto;
        overflow: auto;
        height: 400px
    }

    .judet{
        color: black;
    }

    .judet_legenda{
        background-color: black;
        width: 10px;
        height: 10px;
        font-size:10px;
        margin-right:10px;
    }

    .municipiu{
        color: #000066;
    }

    .municipiu_legenda{
        background-color: #000066;
        width: 10px;
        height: 10px;
        font-size:10px;
        margin-right:10px;
    }

    .localitate{
        color: #660099;
    }

    .localitate_legenda{
        background-color: #660099;
        width: 10px;
        height: 10px;
        font-size:10px;
        margin-right:10px;
    }

    .strada{
        color: #006600;
        cursor:pointer;
    }

    .strada_legenda{
        background-color: #006600;
        width: 10px;
        height: 10px;
        font-size:10px;
        margin-right:10px;
    }

    .childsContainer{
        <% if( BrowseAdresaAction.Util.isBrowseMode( request)){ %>
            padding-left:15px;
        <% } else { %>
            padding-left:18px;
        <% } %>
    }


    .selectedNode{
        background-color:#ccccff;
    }


</style>

<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 loadPuncteConsum( idStrada){
        $("locuriConsum").innerHTML = "Se incarca ...";
        new Ajax.Request('<%=GlobalAppConstants.APP_NAME%>?action=browseGeo_loadLocuriConsum', {
            method: 'post',
            parameters: "idStrada="+idStrada,
            onComplete: function (originalRequest){
                $( "locuriConsum").innerHTML = getResponseMesg( originalRequest.responseText);

                tableClienti = new Table("tableLocuriConsum", "tableClienti");
            }
        });
    }

    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>