<%@ page import="java.util.Date" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.types.Category" %>
<%@ page import="ro.emid.common.types.CategoryInfo" %>
<%@ page import="java.util.Map" %>

<%@include file="declaratii.jsp"%>

<style type="text/css">
    #search_menu{
        padding: 5px;
        position: absolute;
        top: 20px;
        right: 0px;
        display: none;
        background-color:#efefff;
        border: 1px solid gray;
    }
</style>

<%
        /**
         * @see ro.emid.incidente.action.category.ShowSucursaleAction
         */
    final Category[] sucursale = (Category[]) request.getAttribute("sucursale");
    final Map<Long, CategoryInfo> categoryInfoMap = (Map<Long, CategoryInfo>) request.getAttribute("categoryInfoMap");
    final Long nrIncidenteTotal = (Long) request.getAttribute("nrIncidenteTotal");
%>

<TABLE border=0 cellPading=0 cellSpacing=0 width="100%">
    <TR>
        <td>
            <%@ include file="../header-localizare.jsp"%>
        </td>
        <TD align="RIGHT" style="position: relative;">
            <div id="search">
                <IMG alt=FAQ border=0 width=12 height=13 hspace=3 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/icon_mini_search.gif" %>">
                <a class="link" style="font-size: 12px;color: #3d3d7d;" href="javascript:makeVisible()">Căutare</a>
            </div>

            <div id='search_menu' onblur="checkClickOut();" >
                <form action="<%=AppConstants.APP_NAME%>?action=cautareGlobala" method="post">
                    <nobr>
                    <input type='hidden' name='forums' id='search-for' value='all'/>
                    <input type="text" class="gsapinputtext" name="query" id='search_box' style="width: 180px;"/>
                    <input type="submit" style="font-size: 12px" value="Caută"/>
                    <input type="button" style="font-size: 12px" value="Închide" onclick="makeInvisible()"/>
                    </nobr>
                </form>
            </div>
        </TD>
    </TR>
</TABLE>
<TABLE border=0 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" style="background-color: white;">
    <TR>
        <TH class="gsapthead" colSpan=2 height=25 noWrap>Sucursale Electrica:</TH>
        <TH class="gsapthead" noWrap width=60>Nr.incidente</TH>
        <TH class="gsapthead" noWrap width=150>Data ultimei editari</TH>
    </TR>
    <% if (null == sucursale) {%>
    <TR>
        <TD>
            Nu sunt sucursale definite ...
        </TD>
    </TR>
    <%} else {
        for(int i=0; i < sucursale.length; i++) { %>
        <% CategoryInfo categoryInfo = categoryInfoMap.get(sucursale[i].getId()); %>
        <TR class="row<%=i%2%>">
            <TD height=50 valign="middle" align="center">
                <IMG
                    height=25
                    src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/folder_big.gif" %>"
                    width=46>
            </TD>
            <TD height=50 width="100%">
                <span style="font-size: 12px"><%=AppConstants.format(sucursale[i].getCodSap())%> </span> - <A title="Lista C.E. <%=sucursale[i].getName()%>" class="link" href="<%=AppConstants.APP_NAME%>?action=showCentre&sucursalaId=<%=sucursale[i].getId()%>">
                     <%=sucursale[i].getName()%></A>&nbsp;<%=(sucursale[i].getDescription() == null) ? "": '-' + sucursale[i].getDescription()%><BR>
                <SPAN style="font-size: 10px;">
                    <% final Category[] centre = categoryInfo.getChildren();
                    if (centre != null) for (Category centru : centre) {%>
                        <%=centru.getName() + ", "%>
                    <%}%>
                </span>
            </TD>
            <TD height=50 valign="middle" align="center">
                <SPAN class=gensmall><%=AppConstants.format(categoryInfo.getCountFise(),"")%></SPAN>
            </TD>
            <TD height=50 noWrap valign="middle" align="center">
                <SPAN class=gensmall><%=AppConstants.formatZiSaptaminaData(categoryInfo.getLastDate())%></SPAN>
            </TD>
        </TR>
    <%}%>
    <tr style="font-weight:bold;">
            <td class="gsapthead" colspan="2" align="right">&nbsp;Total:&nbsp;</td>
            <td class="gsapthead" align="center"><%=nrIncidenteTotal%></td>
            <td class="gsapthead">&nbsp;</td>
        </tr>
    <%}%>    
</TABLE>


<script type="text/javascript">

function makeVisible() {
    document.getElementById('search_menu').style.display = "block";
    document.getElementById('search_box').focus();
}

function makeInvisible() {
    document.getElementById('search_menu').style.display = "none";
}

function checkClickOut() {
    document.getElementById('search_menu').style.display = "none";
}
</script>


