<%@ page import="ro.emid.common.components.sugest.base.SugestConstants" %>
<%@ page import="ro.emid.common.constants.*" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.db.EchipamentAccessDB" %>
<%@ page import="ro.emid.common.db.NomAccessDB" %>
<%@ page import="ro.emid.common.types.*" %>
<%@ page import="ro.emid.common.utils.FisaUtils" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.utils.Util" %>
<%@ page import="ro.emid.incidente.db.EvenimentAccessDB" %>
<%@ page import="ro.emid.incidente.obj.binder.IncidentBinder" %>
<%@ page import="ro.emid.incidente.obj.util.IncidentUtils" %>
<%@ page import="ro.emid.lib.view.IncidentxFieldsView" %>

<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>

<%@ include file="declaratii.jsp" %>
<%
        final IncidentBinder binder = (IncidentBinder) session.getAttribute(IncidentConstants.BEAN);
        final Incident bean = (binder != null ? (Incident) binder.getBean() : new Incident());
        session.setAttribute(SessionConstants.INCIDENT, bean);

        Category filialaBean = CategoryAccessDB.getById(bean.getFilialaId());
        if (filialaBean == null) filialaBean = new Category();

        Category sucursalaBean = CategoryAccessDB.getById(bean.getSucursalaId());
        if (sucursalaBean == null) sucursalaBean = new Category();

        Category centruBean = CategoryAccessDB.getById(bean.getCentruId());
        if (centruBean == null) centruBean = new Category();

        final List incidentLfInfo = bean.getInstalatiiAfectate();
        if (incidentLfInfo != null && incidentLfInfo.size() > 0) ;

        final String codCe = centruBean.getCodSap();

        final boolean hasLfSelected = incidentLfInfo != null && incidentLfInfo.size() > 0;

        HashMap map = (HashMap) request.getAttribute(IncidentConstants.EQ_LF_NOM_MAP);

        int[] codeFlags = FisaUtils.getCodeFlags(map);
		
		IncidentxFieldsView incFieldView = new IncidentxFieldsView();
		ArrayList<HashMap> intervale = incFieldView.getIntervale(bean.getId());
%>


<TABLE border=0 cellPading=0 cellSpacing=0 width="100%">
    <TR>
        <TD>
            <%@ include file="../header-localizare.jsp" %>
        </TD>
        <TD align="RIGHT">
            <%--<A href="javascript: alert('[to-do]');" class="link">Lista ultimelor 10 incidente per total</A>--%>
            <%--<IMG alt=FAQ border=0 width=12 height=13 hspace=3 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/icon_mini_search.gif" %>">--%>
        </TD>
    </TR>
</TABLE>

<%@ include file="../layout/messages.jspf" %>

<TABLE border=1 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD">
<TR>
    <TH class="gsapthead" colSpan=2 height=25 noWrap>&nbsp;Fisa de Incident&nbsp;</TH>
</TR>

<form id="zaforma" name="zaforma" action="<%=AppConstants.APP_NAME%>" method=post>
<INPUT TYPE="hidden" NAME="action" VALUE="saveIncident"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.ID%>" VALUE="<%=bean.getId()%>"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.FILIALA_ID%>" VALUE="<%=bean.getFilialaId()%>"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.SUCURSALA_ID%>" VALUE="<%=bean.getSucursalaId()%>"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.SECTIE_ID_TO_SAVE%>" VALUE="<%=bean.getCentruId()%>"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.EVENIMENT_ID%>" VALUE="<%=bean.getEvenimentId()%>"/>
<TR>
    <TD width="25%">
        <b>1.</b> Numar curent incident:
    </TD>

    <TD wdth="75%">
        <span style="float:right;">v. <%=ObjectUtils.getStringValue(bean.getVersion())%></span>
        <INPUT class="gsapinputtext" TYPE="TEXT" readonly name="<%=IncidentConstants.NUMAR_INCIDENT%>"
               VALUE="<%=IncidentUtils.getNumarIncident(bean)%>">
    </TD>
</TR>
<script type="text/javascript">

    var input = jQuery("input[name=" + "<%=IncidentConstants.NUMAR_INCIDENT%>" + "]");

    if (input.val() == "") {
        input.css("background-color", "rgb(219, 219, 219)");
    }

</script>

<TR>
<TD valign=top>
    <b>2.</b> Localizare incident: <br>
    <%
        Eveniment eveniment = null;
        if (bean.getEvenimentId() != -1) {
            eveniment = EvenimentAccessDB.getById(bean.getEvenimentId());
        } else if (bean.getId() > 0 && bean.getNumarComandaSap() > 0) {
            eveniment = EvenimentAccessDB.getById(bean.getNumarComandaSap());
        }

        if (eveniment != null && eveniment.getCountCosturi() > 0) {
            eveniment.setListaCosturi(EvenimentAccessDB.getCosturi(String.valueOf(eveniment.getNrComanda())));
        }
    %>
    <% if (bean.getNumarComandaSap() > 0 && eveniment == null) { %>
    <span style="color: red">Comanda <%=bean.getNumarComandaSap()%> - nu exista</span>
    <% } else if (eveniment != null) {%>

    <div onclick=" Element.toggle('dateEveniment');"
         style="cursor:pointer; margin-top: 10px; color: blue; font-size: 12px"> Eveniment
    </div>
    <style type="text/css">
        #dateEveniment {
            background-color: #befebe;
            font-size: 10px;
            overflow: inherit;
        }
    </style>

    <div id="dateEveniment" style="display: none">
        <b>NR_COMANDA :</b> <%=eveniment.getNrComanda()%><br>
        <b>NR_NOTIFICARE :</b> <%=eveniment.getNrNotificare()%><br>
        <b>ULPI:</b> <%=eveniment.getUlpi()%><br>
        <b>ID_OBIECT:</b> <%=eveniment.getIdObiect()%><br>
        <b>NR_ECHIPAMENT:</b> <%=eveniment.getNrEchipament()%><br>
        <b>DESC.:</b> <%=eveniment.getDescriereObiectTehnic()%><br>
        <b>TIP_OB_TEHNIC:</b> <%=eveniment.getTipObiectTehnic()%><br>
        <b>TEXT_TIP_OB_TEHNIC:</b> <%=eveniment.getTextTipObiectTehnic()%><br>
        <b>LOC_FUNCTIONAL:</b> <%=eveniment.getLocFunctional()%><br>
        <b>TEXT_LOC_FUNCTIONAL:</b> <%=eveniment.getTextLocFuctional()%><br>
        <b>TEXT:</b> <%=eveniment.getText()%><br>
        <b>DATA_COM:</b> <%=AppConstants.format(eveniment.getDataComanda())%><br>

        <% if (eveniment != null && eveniment.getListaCosturi().length > 0) { %>
        <br/>
        <b>Costuri:</b><br/>
        <table style="font-size:10px; margin:2px; background-color:white; border:1px solid #cccccc" width="100%">
            <tr style="background-color: #cccccc" align="center">
                <td>Nr. notifi.</td>
                <td>Serv.</td>
                <td>Ment.</td>
                <td>Data</td>
            </tr>
            <% for (int i = 0; i < eveniment.getListaCosturi().length; i++) {
                final EvenimentCost cost = eveniment.getListaCosturi()[i]; %>
            <tr>
                <td align="center"><%=AppConstants.format(cost.getNrNotificare())%>
                </td>
                <td align="right">
                    <%=AppConstants.format(cost.getValServicii())%>
                    <%=AppConstants.format(cost.getMonedaServicii())%>
                </td>
                <td align="right">
                    <%=AppConstants.format(cost.getValRest())%>
                    <%=AppConstants.format(cost.getMonedaRest())%>
                </td>
                <td align="center">
                    <%=AppConstants.format(cost.getDataClsid())%>
                </td>
            </tr>
            <% } %>
        </table>
        <% } %>
    </div>
    <%}%>
</TD>
<TD>
    <TABLE class="gsapthead">

        <TR class="gSAPGroup">
            <TD nowrap="nowrap">
                <b>2.1</b> Cod filiala:
            </TD>
            <TD colspan="3">
                <INPUT class="gsapinputtext" disabled="true" TYPE="TEXT" NAME="title"
                       VALUE="<%=filialaBean.getName()%>">
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD nowrap="nowrap">
                <b>2.2</b> Cod sucursala:
            </TD>
            <TD colspan="3">
                <INPUT class="gsapinputtext" disabled="true" TYPE="TEXT" NAME="title"
                       VALUE="<%=sucursalaBean.getCodSap()%> - <%=sucursalaBean.getName()%>">
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD nowrap="nowrap">
                <b>2.3</b> Cod C.E.:
            </TD>
            <TD valign="MIDDLE" width="100%" colspan="3">
                <INPUT class="gsapinputtext" style="width: 230px" disabled="true" TYPE="TEXT" NAME="title"
                       VALUE="<%=centruBean.getCodSap()%> - <%=centruBean.getName()%>">
                <input type="hidden" name="<%=IncidentConstants.SECTIE_ID%>" value="<%=centruBean.getId()%>">
                <input type="hidden" name="<%=IncidentConstants.SECTIE_ID%>h" value="<%=centruBean.getCodSap()%>"
                       codSapOriginal="<%=centruBean.getCodSap()%>">

                &nbsp;&nbsp;<b>2.3.1</b>&nbsp; <%=isCuSectiiSiCentre ? "Centru exploatare" : "Formatia de lucru"%>:
                <select class="gSAPSelect"
                        name="<%=IncidentConstants.FORMATIA_DE_LUCRU_ID%>" <%if (centruExploatare.isCentruCuFormatiiShmekere()) {%>
                        onchange="onFormatieChanged()"  <%}%> >
                    <% if (user.getIeLevel() == RoleConstants.NIVEL_FORMATIE) { %>
                    <option codSapAsCentru="<%=AppConstants.format( formatiaDeLucru.getCodSapAsCentru())%>"
                            value="<%=formatiaDeLucru.getId()%>"><%=formatiaDeLucru.getName()%>
                    </option>
                    <% } else {%>
                    <% final Category[] formatii = CategoryAccessDB.getAllCategoriesByParentId(centruBean.getId()); %>
                    <option value="-1">Selectati:</option>
                    <% for (int i = 0; i < formatii.length; i++) {
                        final Category formatia = formatii[i];%>
                    <option codSapAsCentru="<%=AppConstants.format( formatia.getCodSapAsCentru())%>"
                            value="<%=formatia.getId()%>" <%=formatia.getId() == bean.getFormatiaDeLucruId() ? "selected" : ""%> ><%=formatia.getName()%>
                    </option>
                    <% }%>
                    <% }%>
                </select>
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD>
                <b>2.4</b> Ansamblu functional:
            </TD>
            <TD colspan="3">
                <SELECT name="<%=IncidentConstants.ANSAMBLU_ID%>" class="gSAPSelect" onChange="on_ansamblu_changed();">
                    <OPTION value="-1">Selectati:</OPTION>
                    <% Util.showNomOptions(out, NomConstants.NOM_ANSAMBLURI, bean.getAnsambluId()); %>
                </SELECT>
                <SELECT name="<%=IncidentConstants.ANSAMBLU_ID%>x" class="gSAPSelect" style="display:none;">
                    <OPTION value="-1">Selectati:</OPTION>
                    <% Util.showNomOptionsCod(out, NomConstants.NOM_ANSAMBLURI, bean.getAnsambluId()); %>
                </SELECT>
                &nbsp;<br> <b>2.4.1</b> Explicatii: <input class="gsapinputtext" style="background-color: white;"
                                                           size="50" type="text"
                                                           name="<%=IncidentConstants.EXPLICATII%>"
                                                           value="<%=ObjectUtils.getStringValue( bean.getExplicatii())%>">
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD>
                <b>2.5</b> Statie:
            </TD>
            <TD>

            <input type="hidden" id="<%=IncidentConstants.STATIE_ID%>" name="<%=IncidentConstants.STATIE_ID%>"
                           value="<%=bean.getStatieId()%>"/>
            <input type="hidden" id="<%=IncidentConstants.STATIE_COD%>" name="<%=IncidentConstants.STATIE_COD%>"
                   value="<%=AppConstants.format(bean.getStatieCod())%>"/>
            <input class="gsapinputtext" id="<%=IncidentConstants.STATIE_DEN%>"
                   name="<%=IncidentConstants.STATIE_DEN%>" maxlength="100" style="width: 285px" sugestWidth="285"
                   value="<%=AppConstants.format(bean.getStatieDen())%>"/>
            </TD>
            <td nowrap="nowrap">
                <b>2.5.1</b> Bobina:
            </td>
            <td width="10000">
                <input type="hidden" id="<%=IncidentConstants.BOBINA_ID%>" name="<%=IncidentConstants.BOBINA_ID%>"
                       value="<%=bean.getBobinaId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.BOBINA_COD%>" name="<%=IncidentConstants.BOBINA_COD%>"
                       value="<%=AppConstants.format(bean.getBobinaCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.BOBINA_DEN%>"
                       name="<%=IncidentConstants.BOBINA_DEN%>" maxlength="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getBobinaDen())%>"/>
            </TD>
        </TR>
        <TR class="gSAPGroup">
            <TD>
                <b>2.6</b> Celula:
            </TD>
            <TD>
                <input type="hidden" id="<%=IncidentConstants.CELULA_ID%>" name="<%=IncidentConstants.CELULA_ID%>"
                       value="<%=bean.getCelulaId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.CELULA_COD%>" name="<%=IncidentConstants.CELULA_COD%>"
                       value="<%=AppConstants.format(bean.getCelulaCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.CELULA_DEN%>"
                       name="<%=IncidentConstants.CELULA_DEN%>" maxlength="200" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getCelulaDen())%>"/>
            </TD>
            <td nowrap="nowrap">
                <b>2.6.1</b> Bara:
            </td>
            <td>
                <input type="hidden" id="<%=IncidentConstants.BARA_ID%>" name="<%=IncidentConstants.BARA_ID%>"
                       value="<%=bean.getBaraId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.BARA_COD%>" name="<%=IncidentConstants.BARA_COD%>"
                       value="<%=AppConstants.format(bean.getBaraCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.BARA_DEN%>" name="<%=IncidentConstants.BARA_DEN%>"
                       maxlength="200" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getBaraDen())%>"/>
            </TD>
        </TR>
        <TR class="gSAPGroup">
            <TD>
                <b>2.7</b> Linie:
            </TD>
            <TD>
                <input type="hidden" id="<%=IncidentConstants.LINIE_ID%>" name="<%=IncidentConstants.LINIE_ID%>"
                       value="<%=bean.getLinieId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.LINIE_COD%>" name="<%=IncidentConstants.LINIE_COD%>"
                       value="<%=AppConstants.format(bean.getLinieCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.LINIE_DEN%>"
                       name="<%=IncidentConstants.LINIE_DEN%>" maxlength="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getLinieDen())%>"/>
            </TD>
            <td nowrap="nowrap">
                <b>2.7.1</b> Derivatie:
            </td>
            <td>
                <input type="hidden" id="<%=IncidentConstants.DERIVATIE_ID%>" name="<%=IncidentConstants.DERIVATIE_ID%>"
                       value="<%=bean.getDerivatieId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.DERIVATIE_COD%>" name="<%=IncidentConstants.DERIVATIE_COD%>"
                       value="<%=AppConstants.format(bean.getDerivatieCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.DERIVATIE_DEN%>"
                       name="<%=IncidentConstants.DERIVATIE_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getDerivatieDen())%>"/>
            </TD>
        </TR>
        <TR class="gSAPGroup">
            <TD>
                <b>2.8</b> PA/PT:
            </TD>
            <TD colspan="3">
                <input type="hidden" id="<%=IncidentConstants.PAPT_ID%>" name="<%=IncidentConstants.PAPT_ID%>"
                       value="<%=bean.getPA_PT_Id()%>"/>
                <input type="hidden" id="<%=IncidentConstants.PAPT_COD%>" name="<%=IncidentConstants.PAPT_COD%>"
                       value="<%=AppConstants.format(bean.getPaptCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.PAPT_DEN%>" name="<%=IncidentConstants.PAPT_DEN%>"
                       maxlength="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getPaptDen())%>"/>
            </TD>
        </TR>
        <TR class="gSAPGroup">
            <TD>
                <b>2.9</b> Trafo:
            </TD>
            <TD colspan="3">
                <input type="hidden" id="<%=IncidentConstants.TRAFO_ID%>" name="<%=IncidentConstants.TRAFO_ID%>"
                       value="<%=bean.getTrafoId()%>"/>
                <input type="hidden" id="<%=IncidentConstants.TRAFO_COD%>" name="<%=IncidentConstants.TRAFO_COD%>"
                       value="<%=AppConstants.format(bean.getTrafoCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.TRAFO_DEN%>"
                       name="<%=IncidentConstants.TRAFO_DEN%>" maxlength="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getTrafoDen())%>"/>
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD>
                <b>2.10</b> Parametri nominali:
            </TD>
            <TD colspan="3">
                <b>2.10.1</b> Putere: &nbsp;&nbsp;&nbsp;<INPUT class="gsapinputtext" TYPE="TEXT"
                                                               NAME="<%=IncidentConstants.PUTERE%>"
                                                               VALUE="<%=bean.getPutere()%>">
                (
                <INPUT name="<%=IncidentConstants.TIP_PUTERE%>" type=radio
                       value="1" <%=bean.getTipPutere() == 1 ? "checked" : ""%> id="radioMVA"/> <label for="radioMVA">MVA</label>
                &nbsp;
                <INPUT name="<%=IncidentConstants.TIP_PUTERE%>" type=radio
                       value="2" <%=bean.getTipPutere() == 2 ? "checked" : ""%> id="radioMVAr"/><label for="radioMVAr">MVAr</label>
                &nbsp;
                <INPUT name="<%=IncidentConstants.TIP_PUTERE%>" type=radio
                       value="3" <%=bean.getTipPutere() == 3 ? "checked" : ""%> id="radiokVA"/><label
                    for="radiokVA">kVA</label> &nbsp;
                <INPUT name="<%=IncidentConstants.TIP_PUTERE%>" type=radio
                       value="4" <%=bean.getTipPutere() == 4 ? "checked" : ""%> id="kVAr"/><label
                    for="kVAr">kVAr</label>
                ) <br>
                <b>2.10.2</b>
                Tensiune:
                <SELECT name="<%=IncidentConstants.TENSIUNE%>" class="gSAPSelect">
                    <option value="0">-</option>
                    <option value="6" <%=bean.getTensiune() == 6 ? "selected" : ""%>>6</option>
                    <option value="10" <%=bean.getTensiune() == 10 ? "selected" : ""%>>10</option>
                    <option value="15" <%=bean.getTensiune() == 15 ? "selected" : ""%>>15</option>
                    <option value="20" <%=bean.getTensiune() == 20 ? "selected" : ""%>>20</option>
                    <option value="27.5" <%=bean.getTensiune() == 27.5 ? "selected" : ""%>>27.5</option>
                    <option value="35" <%=bean.getTensiune() == 35 ? "selected" : ""%>>35</option>
                    <option value="110" <%=bean.getTensiune() == 110 ? "selected" : ""%>>110</option>
                </SELECT> /
                <SELECT name="<%=IncidentConstants.TENSIUNE2%>" class="gSAPSelect">
                    <option value="0">-</option>
                    <option value="6" <%=bean.getTensiune2() == 6 ? "selected" : ""%>>6</option>
                    <option value="10" <%=bean.getTensiune2() == 10 ? "selected" : ""%>>10</option>
                    <option value="15" <%=bean.getTensiune2() == 15 ? "selected" : ""%>>15</option>
                    <option value="20" <%=bean.getTensiune2() == 20 ? "selected" : ""%>>20</option>
                    <option value="27.5" <%=bean.getTensiune2() == 27.5 ? "selected" : ""%>>27.5</option>
                    <option value="35" <%=bean.getTensiune2() == 35 ? "selected" : ""%>>35</option>
                    <option value="110" <%=bean.getTensiune2() == 110 ? "selected" : ""%>>110</option>
                </SELECT> /
                <SELECT name="<%=IncidentConstants.TENSIUNE3%>" class="gSAPSelect">
                    <option value="0">-</option>
                    <option value="6" <%=bean.getTensiune3() == 6 ? "selected" : ""%>>6</option>
                    <option value="10" <%=bean.getTensiune3() == 10 ? "selected" : ""%>>10</option>
                    <option value="15" <%=bean.getTensiune3() == 15 ? "selected" : ""%>>15</option>
                    <option value="20" <%=bean.getTensiune3() == 20 ? "selected" : ""%>>20</option>
                    <option value="27.5" <%=bean.getTensiune3() == 27.5 ? "selected" : ""%>>27.5</option>
                    <option value="35" <%=bean.getTensiune3() == 35 ? "selected" : ""%>>35</option>
                    <option value="110" <%=bean.getTensiune3() == 110 ? "selected" : ""%>>110</option>
                </SELECT> kV
                <%if(bean.getTensiuneOld() != null){%>
                    &nbsp;&nbsp;&nbsp;
                    <b>Tensiune bkp:</b> <%=bean.getTensiuneOld()%> kV
                <%}%>
            </TD>
        </TR>

        <TR class="gSAPGroup">
            <TD>
                <b>2.11</b> Mod de tratare neutru:
            </TD>
            <TD colspan="3">
                <SELECT name="<%=IncidentConstants.MOD_TR_NEUTRU%>" class="gSAPSelect">
                    <OPTION value="-1">Selectati:</OPTION>
                    <% Util.showNomOptions(out, NomConstants.NOM_MOD_TRATARE_NEUTRU, bean.getModTratareNeutruId()); %>
                </SELECT>
            </TD>
        </TR>
    </TABLE>
</TD>
</TR>

<TR>
    <TD>
        <b>3.</b> Forma de manifestare:
    </TD>

    <TD>
        <SELECT name="<%=IncidentConstants.FORMA_MANIFESTARE_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_MANIFESTARI, bean.getFormaManifestareId()); %>
        </SELECT>
    </TD>

</TR>

<TR>
    <TD>
        <b>4.</b> Prilej:
    </TD>
    <TD>
        <SELECT name="<%=IncidentConstants.PRILEJ_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_PRILEJURI, bean.getPrilejId()); %>
        </SELECT>
    </TD>
</TR>

<TR>
    <TD>
        <b>5.</b> Cauza:
    </TD>

    <TD>
        <b>5.1</b> Grupa:
        <SELECT name="<%=IncidentConstants.CAUZA_GR_ID%>" class="gSAPSelect" onChange="fill_cauze_select();">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_CAUZE_GRUPE, bean.getCauzaGrupaId()); %>
        </SELECT>
        <BR><b>5.2</b> Cauza:
        <SELECT name="<%=IncidentConstants.CAUZA_ID%>" class="gSAPSelect" length=25>
            <option value="-1">Selectati:</option>
        </SELECT>
		<BR><b>5.3</b> Subcauza:
		<SELECT id="subcauzeSelect" name="subcauze_inc" class="gSAPSelect" length=25>
            <option value="-1" selected>Selectati:</option>
        </SELECT>
		<input type="hidden" id="subcauzeId" "name="subcauzaId" value="<%=incFieldView.getSubcauzaIdView(bean.getId())%>" />
		<%--<button id="updateValueSubcauze">Update Subcauza</button>--%>
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>6.</b> Data producerii:
    </TD>
    <TD valign="middle">
        <input class="gsapinputtext" style="width: 80px" type="text" id="<%=IncidentConstants.DATA%>"
               name="<%=IncidentConstants.DATA%>"
               value="<%=bean.getDataProducere() != null ? AppConstants.formatx( bean.getDataProducere()) : ""%>"/>
        <a id="trigger" href="#"><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"
                                      alt="Apasa pt. a selecta data"></a>

        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ora: <input type="text" class="gsapinputtext" style="width: 30px"
                                                        name="<%=IncidentConstants.ORA_PRODUCERE%>"
                                                        value="<%=AppConstants.formatOra( bean.getDataProducere())%>">&nbsp;&nbsp;&nbsp;
        Minute: <input type="text" class="gsapinputtext" style="width: 30px"
                       name="<%=IncidentConstants.MINUTE_PRODUCERE%>"
                       value="<%=AppConstants.formatMinute( bean.getDataProducere())%>">
    </TD>
</TR>
<script type="text/javascript">
    Calendar.setup(
            {
                inputField: "<%=IncidentConstants.DATA%>",         // ID of the input field
                ifFormat: "%d.%m.%Y",    // the date format
                button: "trigger"       // ID of the button
            }
    );
</script>


<TR>
    <TD>
        <b>7.</b> Clasificare incident:
    </TD>
    <TD>
        <b>7.1</b> <INPUT
            onClick="zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.disabled=1; zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.value='0'; "
            name="<%=IncidentConstants.TIP_INCIDENT%>" type=radio
            value="1" <%=( bean.getTipIncident() == 1) ? "checked": ""%> id="radioIzolat"> <label for="radioIzolat">Izolat</label>
        <INPUT onClick="zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.disabled=1; zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.value=zaforma.<%=IncidentConstants.NUMAR_INCIDENT%>.value;"
               name="<%=IncidentConstants.TIP_INCIDENT%>" type=radio
               value="2" <%=( bean.getTipIncident() == 2) ? "checked": ""%> id="radioPrimar"><label for="radioPrimar">Primar</label>
        <INPUT onClick="zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.disabled=0; zaforma.<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>.value='0';"
               name="<%=IncidentConstants.TIP_INCIDENT%>" type=radio
               value="3" <%=( bean.getTipIncident() == 3) ? "checked": ""%> id="radioAsociat"><label for="radioAsociat">Asociat</label>
        &nbsp;&nbsp;&nbsp;
        <b>7.2</b> Numar incident primar:<INPUT <%=bean.getTipIncident() == 3 ? "" : "disabled"%> class="gsapinputtext"
                                                                                                  type="text"
                                                                                                  name="<%=IncidentConstants.NUMAR_INCIDENT_PRIMAR%>"
                                                                                                  value="<%=bean.getNumarIncidentPrimar()%>">
    </TD>
</TR>

<TR>
    <TD>
        <b>8.</b> Durata incident:
    </TD>

    <td>
        Ore:<INPUT name="<%=IncidentConstants.DURATA_INCIDENT_ORE%>" class="gsapinputtext" TYPE="TEXT" size=2
                   VALUE="<%=bean.getDurataIncident()/60%>" onblur="updateEnergieNelivrata()">&nbsp;
        Minute:<INPUT NAME="<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>" class="gsapinputtext" TYPE="TEXT" size=2
                      VALUE="<%=bean.getDurataIncident()%60%>" onchange="updateEnergieNelivrata()">

        &nbsp;<a id="trigger2" href="#"><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"></a>
        <input style="display: none" id="data2"
               value="<%=bean.getDataProducere() != null ? AppConstants.formatx( new Date( bean.getDataProducere().getTime() + bean.getDurataIncident() * 60 * 1000)) : ""%>"/>
    </td>
</tr>
<tr>
    <TD>
        <b>9.</b> Durata indisponibilitate:
    </TD>

    <td>
        Ore:<INPUT name="<%=IncidentConstants.DURATA_INDISP_ORE%>" class="gsapinputtext" TYPE="TEXT" size=2
                   VALUE="<%=(int)bean.getDurataIndisponibilitate()/60%>">&nbsp
        Minute:<INPUT class="gsapinputtext" TYPE="TEXT" size=2 NAME="<%=IncidentConstants.DURATA_INDISP_MINUTE%>"
                      VALUE="<%=(int)bean.getDurataIndisponibilitate()%60%>">

        &nbsp;<a id="trigger3" href="#"><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"></a>
        <input style="display: none" id="data3"
               value="<%=bean.getDataProducere() != null ? AppConstants.formatx( new Date( bean.getDataProducere().getTime() + bean.getDurataIndisponibilitate() * 60 * 1000)) : ""%>"/>

        <script type="text/javascript">
            Calendar.setup(
                    {
                        inputField: "data2",         // ID of the input field
                        ifFormat: "%d.%m.%Y %H:%M",          // the date format
                        button: "trigger2",                 // ID of the button
                        onUpdate: updateDurataIncident,
                        showsTime: true
                    }
            );

            Calendar.setup(
                    {
                        inputField: "data3",         // ID of the input field
                        ifFormat: "%d.%m.%Y %H:%M",    // the date format
                        button: "trigger3",     // ID of the button
                        onUpdate: updateDurataIndisponibilitate,
                        showsTime: true
                    }
            );

            function updateDurataIncident(calendar) {
                var strDataProducere = document.zaforma.<%=IncidentConstants.DATA%>.value;
                strDataProducere += " " + document.zaforma.<%=IncidentConstants.ORA_PRODUCERE%>.value;
                strDataProducere += ":" + document.zaforma.<%=IncidentConstants.MINUTE_PRODUCERE%>.value;

                var dataProducere = Date.parseDate(strDataProducere, "%d.%m.%Y %H:%M");
                var durataMinute = parseInt("" + (calendar.date - dataProducere) / 60000);
                var durataOre = parseInt("" + durataMinute / 60);
                durataMinute = durataMinute % 60;

                document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.value = durataOre;
                document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.value = durataMinute;

                updateEnergieNelivrata();
            }


            function updateDurataIndisponibilitate(calendar) {
                var strDataProducere = document.zaforma.<%=IncidentConstants.DATA%>.value;
                strDataProducere += " " + document.zaforma.<%=IncidentConstants.ORA_PRODUCERE%>.value;
                strDataProducere += ":" + document.zaforma.<%=IncidentConstants.MINUTE_PRODUCERE%>.value;

                var dataProducere = Date.parseDate(strDataProducere, "%d.%m.%Y %H:%M");
                var durataMinute = parseInt("" + (calendar.date - dataProducere) / 60000);
                var durataOre = parseInt("" + durataMinute / 60);
                durataMinute = durataMinute % 60;

                document.zaforma.<%=IncidentConstants.DURATA_INDISP_ORE%>.value = durataOre;
                document.zaforma.<%=IncidentConstants.DURATA_INDISP_MINUTE%>.value = durataMinute;
            }

            function updateEnergieNelivrata() {
                var ore = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.value;
                var minute = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.value;

                if (isNaN(ore) || parseInt(ore) != ore || parseInt(ore) < 0) {
                    <%--alert("Introduceti corect durata Incidentului");--%>
                    <%--document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.select();--%>
                    <%--document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.focus();--%>
                    return;
                }

                if (isNaN(minute) || parseInt(minute) != minute || parseInt(minute) < 0) {
                    <%--alert("Introduceti corect durata Incidentului");--%>
                    <%--document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.select();--%>
                    <%--document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.focus();--%>
                    return;
                }

                var durataIntrerupereIncident = parseInt(ore) * 60 + parseInt(minute);

                var params = '&durataIntrerupereIncident=' + durataIntrerupereIncident;
                new Ajax.Request('<%=AppConstants.APP_NAME%>?action=getEnergieNelivrataForIncident',
                        {
                            method: 'post',
                            parameters: params,
                            onComplete: updateEnergieNelivrataResponse
                        });
            }

            function updateEnergieNelivrataResponse(originalRequest) {

                var response = getResponseMesg(originalRequest.responseText);
                var energieNelivrata = 0.0;

                if (response != null) {
                    response = response.trim();
                    energieNelivrata = response;
                    if (isNaN(energieNelivrata)) {
                        alert(response);
                        energieNelivrata = 0.0;
                    }
                }
                document.zaforma.<%=IncidentConstants.ENERGIE_NELIVR%>.value = energieNelivrata;
            }
        </script>
    </td>
</TR>

<TR>
    <TD>
        <b>10.</b> Energia electrica nelivrata consumatorilor:
    </TD>
    <td>
        <INPUT class="gsapinputtext" TYPE="TEXT" size=5 NAME="<%=IncidentConstants.ENERGIE_NELIVR%>"
               VALUE="<%=AppConstants.format2( bean.getEnergieNelivrata())%>"> kWh
        &nbsp;&nbsp;

        <input type="button" id="browseButton"
                <%=bean.getModCompletareConsumatori() == IncidentConstants.ConsumatoriCompletati.AUTOMAT ? "" : "disabled"%>
               onclick="openBrowseInstalatii()" title="Selectati instalatiile afectate de incident" value="Browse"/>
		
		<input type="button" onclick="showHideIntervale()" value="Arata/Ascunde" />
        
		<span id="nrInstalatiiSpan"><%=bean.getInstalatiiAfectate() != null && bean.getInstalatiiAfectate().size() > 0 ? String.valueOf(bean.getInstalatiiAfectate().size()) : "fara" %></span>
        instalatii selectate

        <span style="width: 150px">&nbsp;</span>
        <input disabled type="checkbox" id="fortaMajora" name="<%=IncidentConstants.FORTA_MAJORA%>" value="1" <%=bean.getFortaMajora() > 0 ? "checked" : ""%> >
		<label for="fortaMajora">Forta majora</label>

		<span style="width: 150px">&nbsp;</span>
        <input id="incidentDeosebit" type="checkbox" name="incidentDeosebit" value="1" <%=incFieldView.getIncDeosebitView(bean.getId()) > 0 ? "checked" : ""%> />
		<label for="incidentDeosebit">Incident deosebit ANRE</label>
		
		<span style="width: 150px">&nbsp;</span>
        <input id="conditiiMeteo" type="checkbox" name="conditii_meteo" value="1" <%=incFieldView.getConditiiMeteoView(bean.getId()) > 0 ? "checked" : ""%> />
		<label for="conditiiMeteo">Conditii meteo deosebite</label>
		
		<span style="width: 150px">&nbsp;</span>
        <input id="copaciCazuti" type="checkbox" name="copaciCazuti" value="1" <%=incFieldView.getCopaciCazutiView(bean.getId()) > 0 ? "checked" : ""%> <%=incFieldView.getConditiiMeteoView(bean.getId()) > 0 ? "" : "disabled"%> />
		<label for="">Copaci căzuţi în reţea</label>
		
		<br>
		
		<div id="intervale-content">
			<table id="intervaleInstalatii">
				<thead>
					<tr>
						<th rowspan="2">Durata</th>
						<th rowspan="2">Nr.instalatii</th>
						<th colspan="3">Consumatori alimentati</th>
						<th colspan="3">Consumatori nealimentati</th>
					</tr>
					<tr>
						<th>JT</th>
						<th>MT</th>
						<th>IT</th>
						<th>JT</th>
						<th>MT</th>
						<th>IT</th>
					</tr>
				</thead>
				<tbody>
				
			<%
					
				for(int i = 0; i < intervale.size(); i++) {
					%>
					<tr>
						<td><%=intervale.get(i).get("DURATA_INTRERUPERE").toString()%></td>
						<td><%=intervale.get(i).get("CNT").toString()%></td>
						<td><%=intervale.get(i).get("JT_A").toString()%></td>
						<td><%=intervale.get(i).get("MT_A").toString()%></td>
						<td><%=intervale.get(i).get("IT_A").toString()%></td>
						<td><%=intervale.get(i).get("JT_N").toString()%></td>
						<td><%=intervale.get(i).get("MT_N").toString()%></td>
						<td><%=intervale.get(i).get("IT_N").toString()%></td>
					</tr>
					<%
				}
			%>
				<%=intervale.size() == 0 ? "<tr><td colspan='8'>Niciun rezultat</td></tr>" : ""%>
				</tbody>
			</table>
		</div>
    </TD>
</TR>

<TR>
    <TD colspan=2>
        <b>11.</b> Schema de principiu a instalatiilor afectate:
        <input type="hidden" name="<%=IncidentConstants.FILE_NAME%>"
               value="<%=AppConstants.format(bean.getFileName())%>">
    <span id="<%=IncidentConstants.FILE_NAME%>link">
        <% if (bean.getFileName() != null) { %>
        <a href="#" title="Vizualizare Schema"
           onclick="openSchema('<%=AppConstants.WEB_RESOURCE_PATH%>/scheme/<%=bean.getFileName()%>'); return false;"><%=bean.getFileName()%>
        </a><br>
        <% } else { %>
        netras<br>
        <% } %>
    </span>
        <script type="text/javascript">
            var chemaWindow = null;
            function openSchema(url) {
                if (chemaWindow != null) chemaWindow.close();
                chemaWindow = window.open(url, 'Schema', 'width=500,height=500,scrollbars=yes,status=yes,resizable=yes,top=100,left=100,dependent=yes,alwaysRaised=yes')
            }

            function updateFileUrl(fileName) {
                document.zaforma.<%=IncidentConstants.FILE_NAME%>.value = fileName;
                $('<%=IncidentConstants.FILE_NAME%>link').innerHTML = "<a href=\"#\" title=\"Vizualizare Schema\" onclick=\"openSchema('<%=AppConstants.WEB_RESOURCE_PATH%>/scheme/" + fileName + "'); return false;\">" + fileName + "</a><br>";
            }


        </script>
        <input onClick="window.open('<%=AppConstants.APP_NAME%>?action=upload', 'Upload', 'width=600,height=200,status=yes,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes'); "
               class="gsapbutton" type="button" name="upload"
               value="Upload" <%=bean.getId() == -1 ? "disabled" : ""%>  >
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>12.</b> Desfasurare incident:
    </TD>
    <TD>
        <textarea id="textarea<%=IncidentConstants.DESF_INCIDENT%>" maxlength="1000" name="<%=IncidentConstants.DESF_INCIDENT%>" cols=65 rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea( bean.getDesfasurareIncident())%>"><%=ObjectUtils.getStringValue(bean.getDesfasurareIncident())%></textarea>
        <span id="charCount<%=IncidentConstants.DESF_INCIDENT%>" style="font-size: 10px" ></span>
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>12.1</b> Consumatori afectati:
    </TD>
    <TD>
        <script type="text/javascript">
            var browsePopup = null;
            var browseFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,height=660,left=20,top=10,width=950";

            function buildParamsForCheckPaPt() {
                var statieId = -1;
                try {
                    statieId = document.zaforma.<%=IncidentConstants.STATIE_ID%>.value;
                } catch (ex) {
                }

                var linieId = -1;
                try {
                    linieId = document.zaforma.<%=IncidentConstants.LINIE_ID%>.value;
                } catch (ex) {
                }

                var postId = -1;
                try {
                    postId = document.zaforma.<%=IncidentConstants.PAPT_ID%>.value;
                } catch (ex) {
                }

                var derivatieId = -1;
                try {
                    derivatieId = document.zaforma.<%=IncidentConstants.DERIVATIE_ID%>.value;
                } catch (ex) {
                }

                var durataIncidentOre = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.value;
                var durataIncidentMinute = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.value;

                return "&statieId=" + statieId + "&linieId=" + linieId + "&derivatieId=" + derivatieId + "&postId=" + postId + "&durataOre=" + durataIncidentOre + "&durataMinute=" + durataIncidentMinute;
            }

            function openBrowse() {
                if (browsePopup != null) browsePopup.close();

                var url = "<%=AppConstants.APP_NAME%>?action=showCheckPaPt" + buildParamsForCheckPaPt();
                browsePopup = window.open(url, '', browseFeatures);
            }


            var browse2Popup = null;
            function openBrowse2() {
                if (browse2Popup != null) browse2Popup.close();

                var url = "<%=AppConstants.APP_NAME%>?action=showCheckPaPt3&firstShow=true" + buildParamsForCheckPaPt();
                browse2Popup = window.open(url, '', browseFeatures);
            }

            var browseMSPopup = null;
            function openBrowseMS() {
                if (browseMSPopup != null) browseMSPopup.close();

                var url = "<%=AppConstants.APP_NAME%>?action=showCheckPaPtMS&firstShow=true" + buildParamsForCheckPaPt();
                browseMSPopup = window.open(url, '', browseFeatures);
            }


            var _browseInstalatii = null;
            function openBrowseInstalatii() {
                if (_browseInstalatii != null) _browseInstalatii.close();

                var url = "<%=AppConstants.APP_NAME%>?action=openBrowseInstalatii&afterSaveAction=saveLfForIncident" + buildParamsForCheckPaPt();
                _browseInstalatii = window.open(url, '', browseFeatures);
            }
        </script>
        Nr. consumatori afectati: <input type="text" class="gsapinputtext" size="6" readonly
                                         name="<%=IncidentConstants.NR_CONSUMATORI_AFECTATI%>"
                                         value="<%=bean.getNrConsumatoriAfectati()%>"><br>
        Denumire / Ora producerii / Ora realimentarii / Modul de realimentare / Putere intrerupta / Energie
        nelivrata<BR>
        <TEXTAREA id="textarea<%=IncidentConstants.CONSUMATORI_AFECTATI%>" maxlength="1000" name="<%=IncidentConstants.CONSUMATORI_AFECTATI%>" cols=65
                  rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getConsumatoriAfectati())%>"><%=ObjectUtils.getStringValue(bean.getConsumatoriAfectati())%></TEXTAREA>
        <span id="charCount<%=IncidentConstants.CONSUMATORI_AFECTATI%>" style="font-size: 10px" ></span>
    </TD>

</TR>

<TR>
    <TD>
        <b>12.2</b> Nr. utilizatori:
    </TD>
    <td>
        <nobr>
            Consumatori completati <select id="<%=IncidentConstants.MOD_COMPLETARE_CONSUMATORI%>"
                                           name="<%=IncidentConstants.MOD_COMPLETARE_CONSUMATORI%>"
                                           class="gSAPSelect"
                                           onchange="modCompletareConsumatoriChanged()">
            <option value="<%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>"
                    <%=IncidentConstants.ConsumatoriCompletati.AUTOMAT == bean.getModCompletareConsumatori() ? "selected" : ""%>
                    >automat
            </option>
            <option value="<%=IncidentConstants.ConsumatoriCompletati.MANUAL%>"
                    <%=IncidentConstants.ConsumatoriCompletati.MANUAL == bean.getModCompletareConsumatori() ? "selected" : ""%>
                    >manual
            </option>
        </select>
            &nbsp;
            Mediul in care sunt amplasati consumatorii:
            <select id="<%=IncidentConstants.MEDIU%>" name="<%=IncidentConstants.MEDIU%>" class="gSAPSelect">
                <% if (bean.getModCompletareConsumatori() == IncidentConstants.ConsumatoriCompletati.AUTOMAT) { %>
                <option value="<%=IncidentConstants.Mediul.DIN_NOMENCLATOR%>"
                        <%=IncidentConstants.Mediul.DIN_NOMENCLATOR == bean.getMediu() ? "selected" : ""%>
                        >Conform nomenclator
                </option>
                <% } else { %>
                <option value="-1">Selectati:</option>
                <option value="<%=IncidentConstants.Mediul.URBAN%>"
                        <%=IncidentConstants.Mediul.URBAN == bean.getMediu() ? "selected" : ""%>
                        >Urban
                </option>
                <option value="<%=IncidentConstants.Mediul.RURAL%>"
                        <%=IncidentConstants.Mediul.RURAL == bean.getMediu() ? "selected" : ""%>
                        >Rural
                </option>
                <% } %>
            </select>
        </nobr>
        <br/>
        <table width="100%" cellspacing="1" class="gSAPTHEAD" style="display: none">
            <tr class="gSAPGroup" align="center">
                <td></td>
                <td>Inalta(IT)</td>
                <td>Medie(MT)</td>
                <td>Joasa(JT)</td>
            </tr>
            <tr>
                <td><b>Mari consumatori</b></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.IT_MARI%>"
                                          VALUE="<%= bean.getIT_mariConsumatori()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.MT_MARI%>"
                                          VALUE="<%= bean.getMT_mariConsumatori()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.JT_MARI%>"
                                          VALUE="<%= bean.getJT_mariConsumatori()%>"></td>
            </tr>
            <tr>
                <td><b>Mici consumatori</b></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.IT_MICI%>"
                                          VALUE="<%= bean.getIT_miciConsumatori()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.MT_MICI%>"
                                          VALUE="<%= bean.getMT_miciConsumatori()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.JT_MICI%>"
                                          VALUE="<%= bean.getJT_miciConsumatori()%>"></td>
            </tr>
            <tr>
                <td><b>Casnici consumatori</b></td>
                <td></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.MT_CASNICI%>"
                                          VALUE="<%= bean.getMT_casniciConsumatori()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.JT_CASNICI%>"
                                          VALUE="<%= bean.getJT_casniciConsumatori()%>"></td>
            </tr>
        </table>

        <table width="100%" cellspacing="1" class="gSAPTHEAD">
            <tr class="gSAPGroup" align="center">
                <td>Inalta(IT)</td>
                <td>Medie(MT)</td>
                <td>Joasa(JT)</td>
            </tr>
            <tr>
                <td align="center"><INPUT class="gsapinputtext" onblur="updateTotalConsumatori()"
                                          style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.UTILIZATORI_IT%>" <%if( bean.getModCompletareConsumatori()==IncidentConstants.ConsumatoriCompletati.AUTOMAT){%>
                                          readonly <%}%> VALUE="<%= bean.getUtilizatori_IT()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" onblur="updateTotalConsumatori()"
                                          style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.UTILIZATORI_MT%>" <%if( bean.getModCompletareConsumatori()==IncidentConstants.ConsumatoriCompletati.AUTOMAT){%>
                                          readonly <%}%> VALUE="<%= bean.getUtilizatori_MT()%>"></td>
                <td align="center"><INPUT class="gsapinputtext" onblur="updateTotalConsumatori()"
                                          style=" text-align: right" TYPE="TEXT"
                                          NAME="<%=IncidentConstants.UTILIZATORI_JT%>" <%if( bean.getModCompletareConsumatori()==IncidentConstants.ConsumatoriCompletati.AUTOMAT){%>
                                          readonly <%}%> VALUE="<%= bean.getUtilizatori_JT()%>"></td>
            </tr>
        </table>
    </td>
</TR>

<script type="text/javascript">

    function modCompletareConsumatoriChanged() {
        var modComplCons = $F("<%=IncidentConstants.MOD_COMPLETARE_CONSUMATORI%>");

        document.zaforma.<%=IncidentConstants.UTILIZATORI_IT%>.readOnly = (modComplCons == <%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>);
        document.zaforma.<%=IncidentConstants.UTILIZATORI_MT%>.readOnly = (modComplCons == <%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>);
        document.zaforma.<%=IncidentConstants.UTILIZATORI_JT%>.readOnly = (modComplCons == <%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>);

        $("browseButton").disabled = (modComplCons == <%=IncidentConstants.ConsumatoriCompletati.MANUAL%>);

        var mediuSelect = $("<%=IncidentConstants.MEDIU%>");
        clearCombo(mediuSelect);

        if (modComplCons == <%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>) {
            addElemCombo('<%=IncidentConstants.Mediul.DIN_NOMENCLATOR%>', "Conform nomenclator", mediuSelect);
        } else {
            addElemCombo('-1', "Selectati:", mediuSelect);
            addElemCombo('<%=IncidentConstants.Mediul.URBAN%>', "Urban", mediuSelect);
            addElemCombo('<%=IncidentConstants.Mediul.RURAL%>', "Rural", mediuSelect);
        }
    }
</script>


<TR>
    <TD>
        <b>12.3</b> Fenomene meteo:
    </TD>
    <TD valign="MIDDLE" width="100%">
        <SELECT name="<%=IncidentConstants.METEO_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_METEO, bean.getFenomenMeteoId()); %>
        </SELECT>
    </TD>
</TR>

<TR>
    <TD>
        <b>12.4</b> Incident produs in zona de protectie a descarcatorului:
    </TD>

    <TD>
        <INPUT id="id_da_<%=IncidentConstants.F1%>" name="<%=IncidentConstants.F1%>" value="1" type=radio <%=(bean.isF1()) ? "checked" : ""%> />
        <label for="id_da_<%=IncidentConstants.F1%>" >Da </label>
        <INPUT id="id_nu_<%=IncidentConstants.F1%>" name="<%=IncidentConstants.F1%>" value="0" type=radio <%=(bean.isF1() == false) ? "checked" : ""%> />
        <label for="id_nu_<%=IncidentConstants.F1%>">Nu </label>
    </TD>
</TR>

<TR>
    <TD colspan=2>
        <b>12.5</b> Incident cu deteriorari echip.:
        <input type="hidden" name="incident_cu_deteriorari_old" value="<%=bean.isF2() ? 1 : 0%>">

        <INPUT id="id_da_<%=IncidentConstants.F2%>" name="<%=IncidentConstants.F2%>" value="1" type=radio <%=(bean.isF2()) ? "checked" : ""%> >
        <label for="id_da_<%=IncidentConstants.F2%>" >Da </label>
        <INPUT id="id_nu_<%=IncidentConstants.F2%>" name="<%=IncidentConstants.F2%>" value="0" type=radio <%=(bean.isF2() == false) ? "checked" : ""%>>
        <label for="id_nu_<%=IncidentConstants.F2%>" >Nu </label>

        &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="checkbox" name="<%=IncidentConstants.GENEREAZA_FE%>" id="asdf1" value=1><label for="asdf1">Genereaza
        fisa echipament</label> &nbsp;&nbsp;

        <%--SUUCE:--%>
        <%--<INPUT name="<%=IncidentConstants.F3%>" type=radio value="1" <%=(bean.isF3()) ? "checked" : ""%>>Da--%>
        <%--<INPUT name="<%=IncidentConstants.F3%>" type=radio value="0" <%=(bean.isF3() == false) ? "checked" : ""%>>Nu--%>
    </TD>
</TR>

<%if (bean.getId() > 0) {%>
<TR>
    <TD>
        Echipamente afectate:
    </TD>
    <TD>
        <TABLE border=1 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD">
            <% final Echipament[] echipamente = EchipamentAccessDB.getForIncident(bean.getId());
                if (null == echipamente) {%>
            <TR>
                <TD>Fara echipamente afectate.</TD>
            </TR>
            <%
            } else for (int i = 0; i < echipamente.length; i++) {
                final String td_color = (i % 2 == 0 ? "BACKGROUND-COLOR: #CACADF" : "BACKGROUND-COLOR: #D9D9E8");
            %>
            <TR>
                <TD style="<%=td_color%>" class="row1" width="100%">
                    <SPAN class=forumlink>
                        <A class="link"
                           href="<%=AppConstants.APP_NAME%>?action=editEchipament&fromIncident=true&id=<%=echipamente[i].getId()%>">
                            &nbsp;F.E.
                            nr. <%=(echipamente[i].getNumarEchipament() != -1) ? String.valueOf(echipamente[i].getNumarEchipament()) : "nesetat"%>
                        </A>
                    </SPAN>
                </TD>
            </TR>
            <%}%>
        </TABLE>
    </TD>
</TR>
<%}%>

<TR>
    <TD colspan=2>
        <b>12.6</b> Incident cu perturbatii sistem:
        <INPUT id="id_da_<%=IncidentConstants.F4%>" name="<%=IncidentConstants.F4%>" type=radio value="1" <%=(bean.isF4()) ? "checked" : ""%>>
        <label for="id_da_<%=IncidentConstants.F4%>" >Da </label>
        <INPUT id="id_nu_<%=IncidentConstants.F4%>"  name="<%=IncidentConstants.F4%>" type=radio value="0" <%=(bean.isF4() == false) ? "checked" : ""%> >
        <label for="id_nu_<%=IncidentConstants.F4%>" >Nu </label>
        &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
        <%--SUUCE:--%>
        <%--<INPUT name="<%=IncidentConstants.F5%>" type=radio value="1" <%=(bean.isF5()) ? "checked" : ""%>>Da--%>
        <%--<INPUT name="<%=IncidentConstants.F5%>" type=radio value="0" <%=(bean.isF5() == false) ? "checked" : ""%>>Nu--%>
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>13.</b> Masuri pentru limitare/lichidare:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=IncidentConstants.MASURI_LIM_LIC%>" maxlength="1000"
                  name="<%=IncidentConstants.MASURI_LIM_LIC%>"
                  cols=65
                  rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getMasuriLimitareLichidare())%>"><%=ObjectUtils.getStringValue(bean.getMasuriLimitareLichidare())%></TEXTAREA>
        <span id="charCount<%=IncidentConstants.MASURI_LIM_LIC%>" style="font-size: 10px" ></span>
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>14.</b> Masuri pentru prevenire incidente similare:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=IncidentConstants.MASURI_PREV%>" maxlength="1000" name="<%=IncidentConstants.MASURI_PREV%>" cols=65
                  rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getMasuriPrev())%>"><%=ObjectUtils.getStringValue(bean.getMasuriPrev())%></TEXTAREA>
        <span id="charCount<%=IncidentConstants.MASURI_PREV%>" style="font-size: 10px" ></span>
    </TD>
</TR>

<TR>
    <TD>
        <b>15.</b> Cheltuieli (RON):
    </TD>
    <TD>
        <table width="80%" cellspacing="1" class="gSAPTHEAD">
            <tr class="gSAPGroup">
                <td>
                    <INPUT <%if( bean.isCosturiFixe()){%> style="color: green;" readonly <%}else{%>
                                                          style="color: blue;"<%}%> class="gsapinputtext"
                                                          style=" text-align: right" TYPE="TEXT"
                                                          NAME="<%=IncidentConstants.CHELT_MENT%>"
                                                          VALUE="<%=AppConstants.format2( bean.getCheltMentinere())%>">
                    - Mentenanta - Terti<BR>
                    <INPUT <%if( bean.isCosturiFixe()){%> style="color: green;" readonly <%}else{%>
                                                          style="color: blue;"<%}%> class="gsapinputtext"
                                                          style=" text-align: right" TYPE="TEXT"
                                                          NAME="<%=IncidentConstants.CHELT_DAUNE%>"
                                                          VALUE="<%=AppConstants.format2( bean.getCheltDaune())%>"> -
                    Daune<BR>
                    <INPUT <%if( bean.isCosturiFixe()){%> style="color: green;" readonly <%}else{%>
                                                          style="color: blue;"<%}%> class="gsapinputtext"
                                                          style=" text-align: right" TYPE="TEXT"
                                                          NAME="<%=IncidentConstants.CHELT_EXPLOATARE%>"
                                                          VALUE="<%=AppConstants.format2( bean.getCheltExploatare())%>">
                    - Exploatare / Forte proprii<BR>
                    <INPUT class="gsapinputtext" TYPE="TEXT" NAME="total" disabled="true" style=" text-align: right"
                           VALUE="<%=AppConstants.format2(bean.getCheltMentinere() + bean.getCheltDaune() + bean.getCheltExploatare())%>">
                    - Total
                </td>
            </tr>
        </table>
    </TD>
</TR>

<TR>
    <TD valign=top>

        <b>16.</b> Propuneri:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=IncidentConstants.PROPUNERI%>" maxlength="1000" name="<%=IncidentConstants.PROPUNERI%>" cols=65 rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getPropuneri())%>"><%=ObjectUtils.getStringValue(bean.getPropuneri())%></TEXTAREA>
        <span id="charCount<%=IncidentConstants.PROPUNERI%>" style="font-size: 10px" ></span>

    </TD>
</TR>





<TR>
    <TD colspan=2>
        <b>17.</b> Incidentul a fost analizat de:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT" NAME="<%=IncidentConstants.ANALIZAT_DE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getAnalizatDe())%>">.
        &nbsp;&nbsp;&nbsp;&nbsp;Conducatorul sub-unitatii de exploatare:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT"
               NAME="<%=IncidentConstants.CONDUCATOR_UNITATE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getConducatorUnitate())%>">.
    </TD>
</TR>

<TR>
    <TD colspan="2">
        <b>18.</b> Avizul comisiei tehnice:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT" NAME="<%=IncidentConstants.AVIZ_COMISIE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getAvizComisie())%>">
    </TD>
</TR>

<TR>
    <TD colspan=2>
        <b></b> Conducatorul tehnic:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT"
               NAME="<%=IncidentConstants.CONDUCATOR_TEHNIC%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getConducatorTehnic())%>">.
        &nbsp;&nbsp;&nbsp;&nbsp;Inspector incidente:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT"
               NAME="<%=IncidentConstants.INSPECTOR_INCIDENTE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getInspectorIncidente())%>">.
    </TD>
</TR>



<TR>
    <TD align="center" valign=top colspan="2">
        <input type="button" onclick="if(dataValid()) {this.disabled = true; this.form.submit()}" value="Salvează"/>
        &nbsp;&nbsp;&nbsp;
        <input type="button" onclick="window.location = '<%=AppConstants.APP_NAME%>?action=renuntaEditIncident'"
               value="Renunță"/>
    </TD>
</TR>




</FORM>
</TABLE>
<script type="text/javascript" src="<%=AppConstants.WEB_RESOURCE_PATH%>/scripts/functions.js"></script>

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

<script type="text/javascript">

    var codeFlags = [];

    var url = document.location.href;

    if (url.indexOf("id=") != -1) {

        codeFlags.push("<%=codeFlags[0]%>");
        codeFlags.push("<%=codeFlags[1]%>");
        codeFlags.push("<%=codeFlags[2]%>");
        codeFlags.push("<%=codeFlags[3]%>");
        codeFlags.push("<%=codeFlags[4]%>");
        codeFlags.push("<%=codeFlags[5]%>");
        codeFlags.push("<%=codeFlags[6]%>");
        codeFlags.push("<%=codeFlags[7]%>");

        var statieInput = jQuery("#" + "<%=IncidentConstants.STATIE_DEN%>");
        var linieInput = jQuery("#" + "<%=IncidentConstants.LINIE_DEN%>");
        var paptInput = jQuery("#" + "<%=IncidentConstants.PAPT_DEN%>");
        var bobinaInput = jQuery("#" + "<%=IncidentConstants.BOBINA_DEN%>");
        var celulaInput = jQuery("#" + "<%=IncidentConstants.CELULA_DEN%>");
        var baraInput = jQuery("#" + "<%=IncidentConstants.BARA_DEN%>");
        var derivatieInput = jQuery("#" + "<%=IncidentConstants.DERIVATIE_DEN%>");
        var trafoInput = jQuery("#" + "<%=IncidentConstants.TRAFO_DEN%>");

        <%--var statieId = "<%=bean.getStatieId()%>";--%>
        <%--var linieId = "<%=bean.getLinieId()%>";--%>
        <%--var paptId = "<%=bean.getPA_PT_Id()%>";--%>
        <%--var bobinaId = "<%=bean.getBobinaId()%>";--%>
        <%--var celulaId = "<%=bean.getCelulaId()%>";--%>
        <%--var baraId = "<%=bean.getBaraId()%>";--%>
        <%--var derivatieId = "<%=bean.getDerivatieId()%>";--%>
        <%--var trafoId = "<%=bean.getTrafoId()%>";--%>

        // 0 not found in nom
        // 1 found in nom


        if (0 != statieInput.val().length) {
            if (0 == codeFlags[0]) {
                statieInput.css("color", "red");
            }
        }
        if (0 != linieInput.val().length) {
            if (0 == codeFlags[1]) {
                linieInput.css("color", "red");
            }
        }
        if (0 != paptInput.val().length) {
            if (0 == codeFlags[2]) {
                paptInput.css("color", "red");
            }
        }
        if (0 != bobinaInput.val().length) {
            if (0 == codeFlags[3]) {
                bobinaInput.css("color", "red");
            }
        }
        if (0 != celulaInput.val().length) {
            if (0 == codeFlags[4]) {
                celulaInput.css("color", "red");
            }
        }
        if (0 != baraInput.val().length) {
            if (0 == codeFlags[5]) {
                baraInput.css("color", "red");
            }
        }
        if (0 != derivatieInput.val().length) {
            if (0 == codeFlags[6]) {
                derivatieInput.css("color", "red");
            }
        }
        if (0 != trafoInput.val().length) {
            if (0 == codeFlags[7]) {
                trafoInput.css("color", "red");
            }
        }
    }

</script>

<script type="text/javascript">

/* Suggesters */

var statiiDataProvider = new AjaxDataProvider(function () {
    return "<%=AppConstants.APP_NAME%>?action=suggestStatii&codCe=<%=codCe%>&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var bobineDataProvider = new AjaxDataProvider(function () {

    // bobina's parent is statie

    var codStatie = $("<%=IncidentConstants.STATIE_COD%>").value;

    return "<%=AppConstants.APP_NAME%>?action=suggestBobine&codCe=<%=codCe%>&codParent=" + codStatie + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var celuleDataProvider = new AjaxDataProvider(function () {

    var codStatie = $("<%=IncidentConstants.STATIE_COD%>").value;

    return "<%=AppConstants.APP_NAME%>?action=suggestCelule&codCe=<%=codCe%>&codParent=" + codStatie + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var bareDataProvider = new AjaxDataProvider(function () {
    return "<%=AppConstants.APP_NAME%>?action=suggestBare&codCe=<%=codCe%>&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var liniiDataProvider = new AjaxDataProvider(function () {

    // linie's parent is statie

    var parentId = $('<%=IncidentConstants.STATIE_ID%>').value;

    return "<%=AppConstants.APP_NAME%>?action=suggestLinii&codCe=<%=codCe%>&parentId=" + parentId + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var derivatiiDataProvider = new AjaxDataProvider(function () {

    // derivatie's parent is linie

    var codLinie = $("<%=IncidentConstants.LINIE_COD%>").value;

    return "<%=AppConstants.APP_NAME%>?action=suggestDerivatii&codCe=<%=codCe%>&codParent=" + codLinie + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var paptDataProvider = new AjaxDataProvider(function () {

    // papt's parent is linie

    var parentLinieId = $("<%=IncidentConstants.LINIE_ID%>").value;

    var parentStatieId = $("<%=IncidentConstants.STATIE_ID%>").value;

    return "<%=AppConstants.APP_NAME%>?action=suggestPapt&codCe=<%=codCe%>&parentLinieId="+ parentLinieId + "&parentStatieId=" + parentStatieId + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

var trafoDataProvider = new AjaxDataProvider(function () {
    return "<%=AppConstants.APP_NAME%>?action=suggestTrafo&codCe=<%=codCe%>&<%=SugestConstants.SUGEST_Q_QUERY%>=";
});

function initSugestsLocalizareIncident() {
    new InputSugest($("<%=IncidentConstants.STATIE_DEN%>"), $("<%=IncidentConstants.STATIE_ID%>"), statiiDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.STATIE_COD%>').value = '';
        },

        onSelect: function (item) {

            // clear bobine, linii, posturi, derivatii
            $('<%=IncidentConstants.STATIE_COD%>').value = item.cod;

            $('<%=IncidentConstants.LINIE_ID%>').value = -1;
            $('<%=IncidentConstants.LINIE_DEN%>').value = '';

            $('<%=IncidentConstants.BOBINA_ID%>').value = -1;
            $('<%=IncidentConstants.BOBINA_DEN%>').value = '';

            $('<%=IncidentConstants.PAPT_ID%>').value = -1;
            $('<%=IncidentConstants.PAPT_DEN%>').value = '';

            $('<%=IncidentConstants.DERIVATIE_ID%>').value = -1;
            $('<%=IncidentConstants.DERIVATIE_DEN%>').value = '';
        }

    });

    new InputSugest($("<%=IncidentConstants.BOBINA_DEN%>"), $("<%=IncidentConstants.BOBINA_ID%>"), bobineDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.BOBINA_COD%>').value = '';

        },

        onSelect: function (item) {

            $('<%=IncidentConstants.BOBINA_COD%>').value = item.cod;
            $('<%=IncidentConstants.STATIE_ID%>').value = item.idInstalatieParent;
            $('<%=IncidentConstants.STATIE_DEN%>').value = item.descInstalatieParent;

        }
    });
    new InputSugest($("<%=IncidentConstants.CELULA_DEN%>"), $("<%=IncidentConstants.CELULA_ID%>"), celuleDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.CELULA_COD%>').value = '';

        },

        onSelect: function (item) {
            $('<%=IncidentConstants.CELULA_COD%>').value = item.cod;
        }
    });
    new InputSugest($("<%=IncidentConstants.BARA_DEN%>"), $("<%=IncidentConstants.BARA_ID%>"), bareDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.BARA_COD%>').value = '';

        },

        onSelect: function (item) {
            $('<%=IncidentConstants.BARA_COD%>').value = item.cod;
        }
    });

    new InputSugest($("<%=IncidentConstants.LINIE_DEN%>"), $("<%=IncidentConstants.LINIE_ID%>"), liniiDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.LINIE_COD%>').value = '';

        },

        onSelect: function (item) {

            $('<%=IncidentConstants.LINIE_COD%>').value = item.cod;

            $('<%=IncidentConstants.PAPT_ID%>').value = -1;
            $('<%=IncidentConstants.PAPT_DEN%>').value = '';

            $('<%=IncidentConstants.DERIVATIE_ID%>').value = -1;
            $('<%=IncidentConstants.DERIVATIE_DEN%>').value = '';

            <%--$('<%=IncidentConstants.STATIE_ID%>').value = item.idInstalatieParent;--%>
            <%--$('<%=IncidentConstants.STATIE_DEN%>').value = item.descInstalatieParent;--%>

        }
    });

    new InputSugest($("<%=IncidentConstants.DERIVATIE_DEN%>"), $("<%=IncidentConstants.DERIVATIE_ID%>"), derivatiiDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.DERIVATIE_COD%>').value = '';
        },

        onSelect: function (item) {

            $('<%=IncidentConstants.DERIVATIE_COD%>').value = item.cod;
            $('<%=IncidentConstants.LINIE_ID%>').value = item.idInstalatieParent;
            $('<%=IncidentConstants.LINIE_DEN%>').value = item.descInstalatieParent;
            $('<%=IncidentConstants.LINIE_COD%>').value = item.codInstalatieParent;
        }
    });

    new InputSugest($("<%=IncidentConstants.PAPT_DEN%>"), $("<%=IncidentConstants.PAPT_ID%>"), paptDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.PAPT_COD%>').value = '';

        },

        onSelect: function (item) {

            $('<%=IncidentConstants.PAPT_COD%>').value = item.cod;
            <%--$('<%=IncidentConstants.LINIE_ID%>').value = item.idInstalatieParent;--%>
            <%--$('<%=IncidentConstants.LINIE_DEN%>').value = item.descInstalatieParent;--%>

        }
    });

    new InputSugest($("<%=IncidentConstants.TRAFO_DEN%>"), $("<%=IncidentConstants.TRAFO_ID%>"), trafoDataProvider, {
        isValidSearchInput: function () {
            return true;
        },

        beforeRequest: function () {
            $('<%=IncidentConstants.TRAFO_COD%>').value = '';

        },

        onSelect: function (item) {
            $('<%=IncidentConstants.TRAFO_COD%>').value = item.cod;
        }
    });

    //alert( "suggests initialized");
}
setTimeout(initSugestsLocalizareIncident, 1000);


</script>

<script type="text/javascript">
function updateTotalConsumatori() {
    var sIT = document.zaforma.<%=IncidentConstants.UTILIZATORI_IT%>.value;
    var sJT = document.zaforma.<%=IncidentConstants.UTILIZATORI_JT%>.value;
    var sMT = document.zaforma.<%=IncidentConstants.UTILIZATORI_MT%>.value;

    var total = 0;
    try {
        total = parseInt(sIT) + parseInt(sJT) + parseInt(sMT);
    } catch (e) {
    }
    document.zaforma.<%=IncidentConstants.NR_CONSUMATORI_AFECTATI%>.value = total;
}

function fill_cauze_select() {
    <% final Nomenclator[] grupCauze = NomAccessDB.getAllNom( NomConstants.NOM_CAUZE_GRUPE); %>
    grup_cauze_select = new Array(<%=grupCauze.length%>);
    <%for(int i = 0; i < grupCauze.length; i++) {
        final Nomenclator grupCauza = grupCauze[i]; %>
    grup_cauze_select[<%=i%>] = new Array(<%=grupCauza.getId()%>, <%=grupCauza.getCod()%>);
    <%}%>

    <% final Nomenclator[] cauze = NomAccessDB.getAllNom( NomConstants.NOM_CAUZE); %>
    cauze_select = new Array(<%=cauze.length%>);
    <%for(int i = 0; i < cauze.length; i++) {
        final Nomenclator cauza = cauze[i]; %>
    cauze_select[<%=i%>] = new Array(<%=cauza.getId()%>, <%=cauza.getCodGrupa()%>, <%=cauza.getCod()%>, "<%=cauza.getDescriere()%>");
    <%}%>
    var optNewOption;
    resetComboLeaveFirstOption(zaforma.<%=IncidentConstants.CAUZA_ID%>);

    cauzaGrupId = zaforma.<%=IncidentConstants.CAUZA_GR_ID%>.options[zaforma.<%=IncidentConstants.CAUZA_GR_ID%>.selectedIndex].value;
    codGrupa = -1;
    for (i = 0; i < grup_cauze_select.length; i++) {
        if (grup_cauze_select[i][0] == cauzaGrupId) {
            codGrupa = grup_cauze_select[i][1];
            break;
        }
    }

    indexx = 0;
    for (i = 0; i < cauze_select.length; i++) {
        if (codGrupa == cauze_select[i][1]) {
            //window.document.zaforma.cauza[indexx].value = cauze_select[i][1];
            //window.document.zaforma.cauza[indexx].text = cauze_select[i][2];
            optNewOption = new Option(cauze_select[i][2] + " - " + cauze_select[i][3], cauze_select[i][0], false, false);
            zaforma.<%=IncidentConstants.CAUZA_ID%>.options[++indexx] = optNewOption;
            //indexx++;
        }
    }
}

function fillAllOnEdit() {
//        alert( 'fill all on Edit' );
    fill_celula_selects(<%=bean.getCelulaId()%>);
    fill_linii_selects(<%=bean.getLinieId()%>, true, <%=bean.getDerivatieId()%>);
    fill_pa_pt_selects(<%=bean.getPA_PT_Id()%>);
    fill_trafo_selects(<%=bean.getTrafoId()%>);
    fill_bobine_selects(<%=bean.getBobinaId()%>);
    fill_bare_selects(<%=bean.getBaraId()%>);
}


function on_ansamblu_changed() {
    enable_ansamble_selects();


    fill_statii_selects();
    fill_linii_selects();
    fill_pa_pt_selects();

    fillEqOrfane();
}

function setTotalEnergieNelivrata(energie, enable) {
    document.zaforma.<%=IncidentConstants.ENERGIE_NELIVR%>.value = energie;
    //document.zaforma.<%--=IncidentConstants.ENERGIE_NELIVR--%>.readOnly = !enable;
}

function setTotalconsumatori(nr) {
    document.zaforma.<%=IncidentConstants.NR_CONSUMATORI_AFECTATI%>.value = nr;
}

function setConsumatoriPeNivelTensiune(nrConsIT, nrConsMT, nrConsJT, nrLfSelected) {
    document.zaforma.<%=IncidentConstants.UTILIZATORI_IT%>.value = nrConsIT;
    document.zaforma.<%=IncidentConstants.UTILIZATORI_MT%>.value = nrConsMT;
    document.zaforma.<%=IncidentConstants.UTILIZATORI_JT%>.value = nrConsJT;

    try {
        document.zaforma.<%=IncidentConstants.UTILIZATORI_IT%>.readOnly = (nrLfSelected > 0);
        document.zaforma.<%=IncidentConstants.UTILIZATORI_MT%>.readOnly = (nrLfSelected > 0);
        document.zaforma.<%=IncidentConstants.UTILIZATORI_JT%>.readOnly = (nrLfSelected > 0);
    } catch (e) {
        alert(e.message)
    }

    $("nrInstalatiiSpan").innerHTML = nrLfSelected == 0 ? "fara" : "" + nrLfSelected;
}

function onChangeSelect(oSelect) {
//        alert( oSelect.name);
}

var mesajAvertizare = null;
var countMesageAvertizare = 0;
function appendMesajAvertizare(newMessage) {
    if (mesajAvertizare == null) mesajAvertizare = "Atentie. Verificati datele introduse.";
    mesajAvertizare += "\n   - " + newMessage;
    countMesageAvertizare++;
}

function tensiuniValide() {

    var t1 = $F(document.zaforma.<%=IncidentConstants.TENSIUNE%>);
    var t2 = $F(document.zaforma.<%=IncidentConstants.TENSIUNE2%>);
    var t3 = $F(document.zaforma.<%=IncidentConstants.TENSIUNE3%>);

    return ( t1.isFloat() && t2.isFloat() && t3.isFloat() && (( 1 * t1 > 0) || ( 1 * t2 > 0) || (1 * t3 > 0)));
}

function durateIncidentValide() {
    var dIncH = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_ORE%>.value;
    var dIncM = document.zaforma.<%=IncidentConstants.DURATA_INCIDENT_MINUTE%>.value;
    <%--var dIdispH = document.zaforma.<%=IncidentConstants.DURATA_INDISP_ORE%>.value;--%>
    <%--var dIdispM = document.zaforma.<%=IncidentConstants.DURATA_INDISP_MINUTE%>.value;--%>

    return dIncH.isInt() && dIncM.isInt() && /*dIdispH.isInt() && dIdispM &&*/ ( dIncH * 60 + 1 * dIncM > 0) /*&& ( dIdispH*60+1*dIdispM > 0)*/;
}

function energieNelivrataValida() {
    var txt = document.zaforma.<%=IncidentConstants.ENERGIE_NELIVR%>.value;
    return txt.isFloat() && 1 * txt > 0;
}

function cheltuieliValide() {
    var ch1 = document.zaforma.<%=IncidentConstants.CHELT_DAUNE%>.value;
    var ch2 = document.zaforma.<%=IncidentConstants.CHELT_EXPLOATARE%>.value;
    var ch3 = document.zaforma.<%=IncidentConstants.CHELT_MENT%>.value;
    return ch1.isFloat() && ch2.isFloat() && ch3.isFloat() && 1 * ch1 + 1 * ch2 + 1 * ch3 > 0;
}

function dataValid() {
    countMesageAvertizare = 0;
    mesajAvertizare = null;

    if (document.zaforma.<%=IncidentConstants.ANSAMBLU_ID%>.selectedIndex == 0) {
        appendMesajAvertizare("Selectati 'Ansamblul functional' (2.4)");
    }

    if (!tensiuniValide()) {
        appendMesajAvertizare("Completati 'Tensiunea' instalatiei in care s-a produs incidentul (2.10.2.)");
    }

    if (document.zaforma.<%=IncidentConstants.CAUZA_ID%>.selectedIndex == 0) {
        appendMesajAvertizare("Selectati 'Cauza' producerii incidentului (5.1 si 5.2)");
    }

    if (!durateIncidentValide()) {
        appendMesajAvertizare("Completati 'Durata incident' (8.)");
    }

    if (document.zaforma.<%=IncidentConstants.METEO_ID%>.selectedIndex == 0) {
        appendMesajAvertizare("Selectati 'Fenomenul Meteo' (12.3)");
    }

    if (!energieNelivrataValida()) {
        appendMesajAvertizare("Completati 'Energia nelivrata' (10.)");
    }

    if (countMesageAvertizare > 0) {
        mesajAvertizare += "\n\nContinuati operatiunea ?";
        return confirm(mesajAvertizare);
    }
    return true;
}


<%if( centruExploatare.isCentruCuFormatiiShmekere()){%>
//pentru cazul cand este setat deja
setHiddenCodSectieIfIsC1_or_C2();
<%}%>

fill_cauze_select();
selectOption(document.zaforma.<%=IncidentConstants.CAUZA_ID%>, <%=bean.getCauzaId()%>);


enable_ansamble_selects();
fill_statii_selects(<%=bean.getStatieId()%>, true);


</script>

<script type="text/javascript">

    function charLimit(el, maxLength) {
        if (el.value.length > maxLength) return false;
        return true;
    }
    function characterCount(el, maxLength) {
        var charCount = document.getElementById('charCount');
        if (el.value.length > maxLength) el.value = el.value.substring(0,maxLength);
        if (charCount) charCount.innerHTML = maxLength - el.value.length;
        return true;
    }

    CharacterCount = function(TextArea,FieldToCount){
        var myField = document.getElementById(TextArea);
        var myLabel = document.getElementById(FieldToCount);
        if(!myField || !myLabel){return false}; // catches errors
        var MaxChars =  myField.maxLengh;
        if(!MaxChars){
            MaxChars =  myField.getAttribute('maxlength') ;
        };
        if(!MaxChars){
            return false
        };
        if (myField.value.length > MaxChars) {
            alert('Ati depasit valoarea maxima de caractere!');
            myField.value = myField.value.substring(0,MaxChars);
        };
        var remainingChars =   MaxChars - myField.value.length
        myLabel.innerHTML = remainingChars+" carectere disponibile; Numar maxim "+MaxChars
    }

    //SETUP!!
    setInterval(function(){CharacterCount('textarea<%=IncidentConstants.DESF_INCIDENT%>','charCount<%=IncidentConstants.DESF_INCIDENT%>')},55);
    setInterval(function(){CharacterCount('textarea<%=IncidentConstants.CONSUMATORI_AFECTATI%>','charCount<%=IncidentConstants.CONSUMATORI_AFECTATI%>')},55);
    setInterval(function(){CharacterCount('textarea<%=IncidentConstants.MASURI_LIM_LIC%>','charCount<%=IncidentConstants.MASURI_LIM_LIC%>')},55);
    setInterval(function(){CharacterCount('textarea<%=IncidentConstants.MASURI_PREV%>','charCount<%=IncidentConstants.MASURI_PREV%>')},55);
    setInterval(function(){CharacterCount('textarea<%=IncidentConstants.PROPUNERI%>','charCount<%=IncidentConstants.PROPUNERI%>')},55);
</script>
