<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.action.browse.adrese.BrowseAdresaAction" %>
<%@ page import="ro.emid.common.AppProperties" %>

<style type="text/css">
    @import url('<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/ext/resources/css/ext-all.css');
    @import url('<%=AppConstants.WEB_RESOURCE_PATH%>/themes/nw7/style.css');
    @import url('<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/table/table.css');
</style>

<style type="text/css">
    fieldset{
        width:100%;
        padding: 15px 10px 10px;
    }
</style>

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

<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/emid-utils.js"></script>
<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/table/table.js"></script>


<script type="text/javascript">


    //overwrite decode method
    Ext.decode = function (respPage) {
        var json = "";
        var index1 = -1;
        var index2 = -1;

        if( respPage && ( index1 = respPage.indexOf("<respmesg>")) > 0 && (index2 = respPage.indexOf("</respmesg>")) > 0 ) {
            json = respPage.substring( index1 + 10, index2);
        }

        return Ext.util.JSON.decode( json);
    };


    // Path to the blank image must point to a valid location on your server
    Ext.BLANK_IMAGE_URL = '<%=AppConstants.WEB_RESOURCE_PATH + "/scripts"%>/ext/resources/images/default/s.gif';

    var panelLocuriConsum = null;

    var selectedFrame = null;

    // Main application entry point
    Ext.onReady(function() {

        new Ext.Viewport({
            layout: 'border',
            items: [
                new Ext.BoxComponent({
                    region: 'north',
                    height: 5, // give north and south regions a height
                    autoEl: {
                        tag: 'div',
                        html:''
                    },
                    margins: '0'
                }),

                new Ext.Panel({
                    region: 'west',
                    collapsible: false,
                    title: 'Localități',
                    autoScroll: true,
                    split: true,
                    width: "30%",
                    margins: '0 0 0 5',
                    minSize: 200,
                    maxSize: 1000,
                    layout: 'fit', // specify layout manager for items
                    html: "<iframe id='browseAdreseFrame' src='<%=AppConstants.APP_NAME%>?action=browse-adrese-frame-view' frameborder='0' width='100%' style='height:100%'></iframe>",
                    autoScroll: false
                }),

                panelLocuriConsum = new Ext.Panel({
                    region : 'center',
                    cls: "detaliiLF",
                    title: 'Locuri de consum',
                    margins : '0 5 0 0',
                    autoScroll: true,
                    bodyStyle : "padding: 10px",
                    minSize: 300,
                    html: "<div id='locuriConsum' style='padding: 0'></div>"
                }),

                <% if( BrowseAdresaAction.Util.isCheckMode(request)){ %>
                    new Ext.BoxComponent({
                        region : 'south',
                        height : 30, // give north and south regions a height
                        margins : '7 5 5 5',
                        html :"<div><button onclick='BrowseWindow.onSave()'>Salvează</button>&nbsp;&nbsp;<button onclick='BrowseWindow.onRenunta()'>Renunță</button></div>"
                    })
                <% } else{ %>
                    new Ext.BoxComponent({
                        region : 'south',
                        height : 5, // give north and south regions a height
                        margins : '0',
                        html :""
                    })
                <% } %>
            ]
        });
    });

    var BrowseWindow = {

        onSave : function(){
            selectedFrame.contentWindow.save();
        },

        onRenunta : function (){
            window.close();
        },

        showLocuriConsum : function ( codStrada){
            $("locuriConsum").innerHTML = "Se incarca ...";
            jQuery.ajax('<%=AppConstants.APP_NAME%>?action=browse-load-locuri-consum', {
                data: "codStrada="+codStrada,
                success: function (data, textStatus, originalRequest){

                    $( "locuriConsum").innerHTML = originalRequest.responseText;

                    try {
                        tableClienti = new Table("tableLocuriConsum", "tableClienti");
                    }catch(e){
                        if( console) console.error("Eroare initializare table", e);
                    }
                },
                error: function(){
                    $( "locuriConsum").innerHTML = "<span class='error'>Eroare incarcare date ...</span>";
                }
            });

            //panelLocuriConsum.load("<%=AppConstants.APP_NAME%>?action=browse-adrese-load-locuri-consum&codStrada="+codInstalatie + "&an=" + an);
        }
    }

</script>
