<%@ page import="ro.emid.incidente.obj.binder.EchipamentBinder" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.incidente.obj.*" %>
<%@ page import="ro.emid.common.types.Nomenclator" %>
<%@ page import="ro.emid.common.db.NomAccessDB" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.incidente.db.EvenimentAccessDB" %>
<%@ page import="java.sql.Timestamp" %>
<%@ page import="ro.emid.common.components.sugest.base.SugestConstants" %>
<%@ page import="ro.emid.common.constants.*" %>
<%@ page import="ro.emid.common.utils.Util" %>
<%@ page import="ro.emid.common.types.Echipament" %>
<%@ page import="ro.emid.common.types.Eveniment" %>
<%@ page import="ro.emid.common.types.EvenimentCost" %>
<%@ page import="ro.emid.incidente.obj.util.EchipamenteUtils" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="ro.emid.common.utils.FisaUtils" %>

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

<%
    final EchipamentBinder binder = (EchipamentBinder) request.getAttribute(EchipamentConstants.BEAN);
    final Echipament bean = (binder != null ? (Echipament) binder.getBean() : new Echipament());

    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 String codCe = centruBean.getCodSap();

    final boolean fromIncident = session.getAttribute("fromIncident") != null;

    final Boolean show = new Boolean(false);

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

    int[] codeFlags = FisaUtils.getCodeFlags(map);
%>

<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=5 cellSpacing=1 width="100%" class="gSAPTHEAD">
<TR>
    <TH class="gsapthead" colSpan=2 height=25 noWrap>
        &nbsp;Fisa de Echipament deteriorat&nbsp;<%=bean.getId() > 0 ? bean.getNumarFI_FE() : ""%>
    </TH>
</TR>
<FORM NAME="zaforma" ACTION="<%=AppConstants.APP_NAME%>" METHOD=POST>
<INPUT TYPE="hidden" NAME="action" VALUE="saveEchipament"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.ID%>" VALUE="<%=bean.getId()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.INCIDENT_ID%>" VALUE="<%=bean.getIncidentId()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.FILIALA_ID%>" VALUE="<%=bean.getFilialaId()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.SUCURSALA_ID%>" VALUE="<%=bean.getSucursalaId()%>"/>
<INPUT TYPE="hidden" NAME="<%=ro.emid.common.constants.IncidentConstants.SECTIE_ID_TO_SAVE%>"
       VALUE="<%=bean.getCentruId()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.EVENIMENT_ID%>" VALUE="<%=bean.getEvenimentId()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.AUTOR%>" VALUE="<%=bean.getUserInsert()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.ECHPAMENT_GENERAT%>" VALUE="<%=bean.isEchipamentGenerat() ? 1 : 0%>"/>
<INPUT TYPE="hidden" NAME="<%=IncidentConstants.SQL_COSTURI_FIXE%>" VALUE="<%= bean.getCosturiFixe()%>"/>
<INPUT TYPE="hidden" NAME="<%=EchipamentConstants.NUMAR_INCIDENT%>v" VALUE="<%= bean.getNumarIncident_v()%>"/>
<TR>
    <TD>
        <b>1.</b> Numar curent fisa incident:
    </TD>
    <TD>
        <span style="float:right;">v. <%=ObjectUtils.getStringValue(bean.getVersion())%></span>
        <INPUT <%=bean.getIncidentId() != -1 ? "readonly" : ""%> class="gsapinputtext" TYPE="TEXT"
                                                                 NAME="<%=EchipamentConstants.NUMAR_INCIDENT%>"
                                                                 VALUE="<%=bean.getNumarIncident() != -1 ? String.valueOf(bean.getNumarIncident()) : ""%>">
        <%if (bean.getIncidentId() != -1 && !fromIncident) { %>
        <a class="link" href="<%=AppConstants.APP_NAME%>?action=editIncident&id=<%=bean.getIncidentId()%>"> Mergi la
            F.I. nr. <%=bean.getNumarIncident()%>
        </a>
        <%}%>
    </TD>
</TR>

<TR>
    <TD width="25%">
        <b>2.</b> Numar curent fisa echipament deteriorat:
    </TD>
    <TD width="75%">
        <INPUT class="gsapinputtext" readonly TYPE="TEXT" NAME="<%=EchipamentConstants.NUMAR_ECHIPAMENT%>"
               VALUE="<%=EchipamenteUtils.getNumarEchipament(bean)%>">
    </TD>
</TR>
<script type="text/javascript">
    var input = jQuery("input[name=" + "<%=EchipamentConstants.NUMAR_ECHIPAMENT%>" + "]");

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

<TR>

    <TD>
        <b>3.</b> Data deteriorarii:
    </TD>
    <TD>
        <INPUT class="gsapinputtext" TYPE="TEXT" id="<%=EchipamentConstants.DATA_DETERIORARE%>"
               NAME="<%=EchipamentConstants.DATA_DETERIORARE%>"
               VALUE="<%=AppConstants.format( bean.getDataDeterioarare())%>" onblur="onDataDeteriorareChanged()">
        <a href="#" id="trigger"><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"
                                      alt="Apasa pt. a selecta data"></a>
    </TD>
</TR>

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

    function onDataDeteriorareChanged() {
        setDurataFunctionareDeLaPIF();
        updateDurataIndisponibilitate();
        updateDurataUltimaInterventie();
    }

    function setDurataFunctionareDeLaPIF() {
        var an = document.zaforma.<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>.value;
        if (an == null || an.trim().length == 0 || an.trim() == "0") return;

        var luna = document.zaforma.<%=EchipamentConstants.LUNA_PUNERE_FUNCTIUNE%>.value;
        if (luna == null || luna.trim().length == 0) {
            luna = 1;
        }

        luna -= 1;        //in DB ianuarie este ianuarie este 1, in Javascript ianuarie este 0

        var dataPF = new Date(document.zaforma.<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>.value, luna, 1);

        var dataDeteriorare = Date.parseDate(document.zaforma.<%=EchipamentConstants.DATA_DETERIORARE%>.value, "%d.%m.%Y %H:%M");

        document.zaforma.<%=EchipamentConstants.DURATA_FUNCTIONARE_PIF%>.value = Math.floor(( dataDeteriorare - dataPF) / (60000 * 60 * 100));
    }

</script>


<TR>

    <TD width="25%">
        <b>4.</b> Echipament / componenta:
    </TD>
    <TD wdth="75%">
        <SELECT name="<%=EchipamentConstants.COMPONENTA_ID%>" class="gSAPSelect" length=25>
            <option value=-1>Selectati:</option>
        </SELECT>
    </TD>
</TR>

<TR>
<TD valign=top>

    <b>5.</b> Localizare echipament deteriorat:
    <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>
        #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>
                <b>5.1</b> Cod filiala:
            </TD>
            <TD>
                <INPUT class="gsapinputtext" disabled="true" TYPE="TEXT" NAME="title"
                       VALUE="<%=filialaBean.getName()%>">
            </TD>
        </TR>

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

        <TR class="gSAPGroup">
            <TD>
                <b>5.3</b> Cod sectie/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>5.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>5.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>5.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>5.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>5.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="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getCelulaDen())%>"/>
            </TD>
            <TD nowrap="nowrap">
                <b>5.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="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getBaraDen())%>"/>
            </TD>
        </TR>

        <TR class="gSAPGroup">

            <TD>
                <b>5.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>5.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>5.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>5.9</b> Trafo:
            </TD>

            <TD>
                <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>

    </TABLE>

<TR>
    <TD>
        <b>6.</b> Parametri nominali echipament:
    </TD>
    <TD>
        <b>6.1.1.</b> Tensiune nominala a instalatiei
        <SELECT name="<%=EchipamentConstants.TENSIUNE_NOMINALA%>" class="gSAPSelect">
            <option value="-1">Selectati:</option>
            <option value="6" <%=bean.getTensiuneNominala() == 6 ? "selected" : ""%>>6 kV</option>
            <option value="10" <%=bean.getTensiuneNominala() == 10 ? "selected" : ""%>>10 kV</option>
            <option value="15" <%=bean.getTensiuneNominala() == 15 ? "selected" : ""%>>15 kV</option>
            <option value="20" <%=bean.getTensiuneNominala() == 20 ? "selected" : ""%>>20 kV</option>
            <option value="27.5" <%=bean.getTensiuneNominala() == 27.5 ? "selected" : ""%>>27.5 kV</option>
            <option value="35" <%=bean.getTensiuneNominala() == 35 ? "selected" : ""%>>35 kV</option>
            <option value="110" <%=bean.getTensiuneNominala() == 110 ? "selected" : ""%>>110 kV</option>
        </SELECT> <br/>

        <b>6.1.2.</b> Tensiune maxima de functionare echipament:
        <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.TENSIUNE_MAXIMA%>"
               VALUE="<%=bean.getTensiuneMaxima()%>"> (kV)
        <BR>
        <b>6.2</b> Putere:<INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.PUTERE%>"
                                 VALUE="<%=bean.getPutere()%>">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        (
        <INPUT name="<%=EchipamentConstants.TIP_PUTERE%>" type=radio
               value="1" <%=bean.getTipPutere() == 1 ? "checked" : ""%> id="radioMVA"/><label for="radioMVA">MVA</label>
        &nbsp;
        <INPUT name="<%=EchipamentConstants.TIP_PUTERE%>" type=radio
               value="2" <%=bean.getTipPutere() == 2 ? "checked" : ""%> id="radioMVAr"/><label
            for="radioMVAr">MVAr</label> &nbsp;
        <INPUT name="<%=EchipamentConstants.TIP_PUTERE%>" type=radio
               value="3" <%=bean.getTipPutere() == 3 ? "checked" : ""%> id="radiokVA"/><label for="radiokVA">kVA</label>
        &nbsp;
        <INPUT name="<%=EchipamentConstants.TIP_PUTERE%>" type=radio
               value="4" <%=bean.getTipPutere() == 4 ? "checked" : ""%> id="radiokVAr"/><label
            for="radiokVAr">kVAr</label>
        )
        <br>
        <b>6.3</b> Producator:&nbsp;&nbsp;Tara:
        <SELECT name="<%=EchipamentConstants.PRODUCATOR_TARA_ID%>" class="gSAPSelect" length=25>
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_TARI, bean.getProducatorTaraId()); %>
        </SELECT>
        &nbsp;Firma:<INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.PRODUCATOR_FIRMA%>"
                           VALUE="<%=ObjectUtils.getStringValue( bean.getProducatorFirma())%>" size="25"><BR>
        <b>6.4</b> Furnizor:&nbsp;&nbsp;Tara:
        <SELECT name="<%=EchipamentConstants.FURNIZOR_TARA_ID%>" class="gSAPSelect" length=25>
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_TARI, bean.getFurnizorTaraId()); %>
        </SELECT>
        &nbsp;Firma:<INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.FURNIZOR_FIRMA%>"
                           VALUE="<%=ObjectUtils.getStringValue( bean.getFurnizorFirma())%>" size="25"><BR>
        <b>6.5</b> An fabricatie:<INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.AN_FABRICATIE%>"
                                        VALUE="<%=bean.getAnFabricatie()%>" size="2"><BR>
        <b>6.6</b> An punere in functiune:<INPUT class="gsapinputtext" TYPE="TEXT"
                                                 NAME="<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>"
                                                 VALUE="<%=bean.getAnPunereFunctiune()%>" size="2"
                                                 onblur="setDurataFunctionareDeLaPIF()">
        &nbsp;&nbsp; Luna: <INPUT class="gsapinputtext" TYPE="text"
                                  NAME="<%=EchipamentConstants.LUNA_PUNERE_FUNCTIUNE%>"
                                  onblur="setDurataFunctionareDeLaPIF()"
                                  VALUE="<%=bean.getLunaPunereFunctiune() != 0 ? String.valueOf(bean.getLunaPunereFunctiune()) : "" %>"
                                  size="2">
        &nbsp;&nbsp;<a id="triggerAnPunereFunctiune" href="#"
                       title="Apasati pentru a selecta luna si anul punerii in functiune"><img
            src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"></a> (Selectati luna si anul)

    </TD>
</TR>

<TR>
    <TD valign=top>

        <b>7.</b> Aspecte ale deteriorarii:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=EchipamentConstants.PROPUNERI%>"maxlength="1000" name="<%=EchipamentConstants.PROPUNERI%>" cols=65 rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getPropuneri())%>"><%=ObjectUtils.getStringValue(bean.getPropuneri())%></TEXTAREA>
        <span id="charCount<%=EchipamentConstants.PROPUNERI%>" style="font-size: 10px" ></span>
    </TD>
</TR>
<TR>
    <TD>
        <b>8.</b> Durata de functionare de la PIF:
    </TD>
    <TD>
        <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.DURATA_FUNCTIONARE_PIF%>"
               VALUE="<%=bean.getDurataFunctPIF()%>" size="2"> sute ore
    </TD>

</TR>

<TR>
    <TD>
        <b>9.</b> Durata de functionare de la ultima interventie:
    </TD>
    <TD>
        <INPUT class="gsapinputtext" TYPE="TEXT" id="<%=EchipamentConstants.DURATA_FUNCTIONARE_ULT_INTERV%>" name="<%=EchipamentConstants.DURATA_FUNCTIONARE_ULT_INTERV%>"
               VALUE="<%=bean.getDurataFunctUltimaInterventie()%>" size="2"> zeci ore

        <%
            final Timestamp dataUltimaInterventie = (bean.getId() != -1 && bean.getDataDeterioarare() != null && bean.getDurataFunctUltimaInterventie() != 0 ? new Timestamp(bean.getDataDeterioarare().getTime() + bean.getDurataFunctUltimaInterventie() * 10 * 60 * 60 * 1000) : null);
        %>

        &nbsp;&nbsp;<a id="triggerUltimaInterventie" href="#" title="Apasati pentru a selecta data ultimei interventii"><img
            src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"></a> (Selectati data ultimei
        interventii) <input type="text" id="dataUltimaInterventie" name="dataUltimaInterventie" value="<%=AppConstants.format( dataUltimaInterventie)%>" style="width: 0;opacity: 0;"/>
    </TD>
</TR>

<TR>
    <TD>
        <b>10.</b> Durata indisponibilitatii ansamblului functional:
    </TD>
    <TD>
        <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.DIAF_ORE%>" VALUE="<%=bean.getDiafOre()%>"
               size="2"> ore &nbsp;&nbsp;
        <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.DIAF_MIN%>" VALUE="<%=bean.getDiafMin()%>"
               size="2"> min

        <%
            final Timestamp dataRepunere = bean.getId() != -1 && bean.getDataDeterioarare() != null && bean.getDiafOre() * bean.getDiafMin() != 0 ? new Timestamp(bean.getDataDeterioarare().getTime() + (bean.getDiafOre() * 60 + bean.getDiafMin()) * 60 * 1000) : null;
        %>
        &nbsp;<a id="triggerDataRepunere" href="#" title="Apasati pentru a selecta data repunerii in functiune"><img
            src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"></a> ( Selectati data repunerii
        in functiune )
        <input type="text" id="dataRepunereFunctiune" name="dataRepunereFunctiune" value="<%=AppConstants.format( dataRepunere)%>" style="width: 0;opacity: 0"/>

        <script type="text/javascript">

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

            function onAnPunereFunctiuneChanged(calendar) {
                var an = calendar.date.getYear();
                var luna = calendar.date.getMonth() + 1;

                document.zaforma.<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>.value = an;
                document.zaforma.<%=EchipamentConstants.LUNA_PUNERE_FUNCTIUNE%>.value = luna;

                setDurataFunctionareDeLaPIF();
            }

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

            function updateDurataIndisponibilitate() {
                var strDataRepunereFunctiune = $('dataRepunereFunctiune').value;
                if (strDataRepunereFunctiune == null || strDataRepunereFunctiune.trim().length == 0) return;

                var strDataProducere = document.zaforma.<%=EchipamentConstants.DATA_DETERIORARE%>.value;
                if (strDataProducere == null || strDataProducere.trim().length == 0) return;

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

                document.zaforma.<%=EchipamentConstants.DIAF_ORE%>.value = durataOre;
                document.zaforma.<%=EchipamentConstants.DIAF_MIN%>.value = durataMinute;
            }


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

            function updateDurataUltimaInterventie() {
                var strDataUltimaInterventie = $('dataUltimaInterventie').value;
                if (strDataUltimaInterventie == null || strDataUltimaInterventie.trim().length == 0) return;

                var strDataProducere = document.zaforma.<%=EchipamentConstants.DATA_DETERIORARE%>.value;
                if (strDataProducere == null || strDataProducere.trim().length == 0) return;


                var dataUltimaInterventie = Date.parseDate(strDataUltimaInterventie, "%d.%m.%Y %H:%M");
                var dataProducere = Date.parseDate(strDataProducere, "%d.%m.%Y %H:%M");
                var durata = parseInt("" + ( dataProducere - dataUltimaInterventie) / (1000 * 60 * 60 * 10));

                document.zaforma.<%=EchipamentConstants.DURATA_FUNCTIONARE_ULT_INTERV%>.value = durata;

            }
        </script>
    </TD>
</TR>

<TR>
    <TD>
        <b>11.</b> Profil ultimei interventii:
    </TD>
    <TD valign="MIDDLE">
        <SELECT name="<%=EchipamentConstants.PROFIL_INTERVENTIE_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_REPARATII, bean.getProfilInterventieId()); %>
        </SELECT>
    </TD>
</TR>

<TR>
    <TD>
        <b>12.</b> Ultima incercare profilactica:
    </TD>
    <TD>
        <b>12.1</b> Durata: <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.UIP_DURATA%>"
                                   VALUE="<%=bean.getUipDurata()%>" size="2"> zile<BR>

        <b>12.2</b> Rezultat:
        <SELECT name="<%=EchipamentConstants.UIP_REZULTAT_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_REZ_INCERC_PROFILACTICE, bean.getUipRezultatId()); %>
        </SELECT>
    </TD>
</TR>

<TR>
    <TD>
        <b>13.</b> Cauza:
    </TD>
    <TD>
        <b>13.1</b> Grupa:
        <SELECT name="<%=EchipamentConstants.CAUZA_GR_ID%>" class="gSAPSelect" onChange="fill_cauze_select();">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_GRUPE_CAUZE_ECH, bean.getCauzaGrupaId()); %>
        </SELECT>
        <BR><b>13.2</b> Cauza:
        <SELECT name="<%=EchipamentConstants.CAUZA_ID%>" class="gSAPSelect">
            <OPTION value="-1">Selectati:</OPTION>
        </SELECT>
    </TD>
</TR>

<TR>
    <TD>

        <b>14.</b> Numar total de echipamente identice deteriorate:
    </TD>
    <TD>
        <INPUT class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.NR_ECHIP_DET_IDENTICE%>"
               VALUE="<%=bean.getNumarEchipIdenticeDet()%>">
    </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="<%=EchipamentConstants.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="<%=EchipamentConstants.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="<%=EchipamentConstants.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

                    <input type="hidden" name="<%=EchipamentConstants.SAP_CHELT_MENT%>"
                           value="<%=bean.getSapCheltMentinere()%>">
                    <input type="hidden" name="<%=EchipamentConstants.SAP_CHELT_DAUNE%>"
                           value="<%=bean.getSapCheltDaune()%>">
                    <input type="hidden" name="<%=EchipamentConstants.SAP_CHELT_EXPLOATARE%>"
                           value="<%=bean.getSapCheltExploatare()%>">

                    <input type="hidden" name="<%=EchipamentConstants.CHELT_MENT%>v"
                           value="<%=bean.getCheltMentinere_v()%>">
                    <input type="hidden" name="<%=EchipamentConstants.CHELT_DAUNE%>v"
                           value="<%=bean.getCheltDaune_v()%>">
                    <input type="hidden" name="<%=EchipamentConstants.CHELT_EXPLOATARE%>v"
                           value="<%=bean.getCheltExploatare_v()%>">
                </td>
            </tr>
        </table>
    </TD>
</TR>

<TR>
    <TD valign=top>
        <b>16.</b> Masuri pentru prevenire:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=EchipamentConstants.MASURI_PREV%>" maxlength="100" name="<%=EchipamentConstants.MASURI_PREV%>" cols=45
                  rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getMasuriPrevenire())%>"><%=ObjectUtils.getStringValue(bean.getMasuriPrevenire())%></TEXTAREA>
        <span id="charCount<%=EchipamentConstants.MASURI_PREV%>" style="font-size: 10px" ></span>
    </TD>

</TR>

<TR>
    <TD valign=top>
        <b>17.</b> Observatii:
    </TD>
    <TD>
        <TEXTAREA id="textarea<%=EchipamentConstants.OBS%>" maxlength="100" name="<%=EchipamentConstants.OBS%>" cols=45
                  rows="<%=ro.emid.common.utils.Util.getNrOfLinesForTextarea(bean.getObservatii())%>"><%=ObjectUtils.getStringValue(bean.getObservatii())%></TEXTAREA>
        <span id="charCount<%=EchipamentConstants.OBS%>" style="font-size: 10px" ></span>
    </TD>

</TR>

<TR>
    <TD colspan=2>
        <b>18.</b> Deteriorarea a fost analizata de:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.ANALIZAT_DE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getAnalizatDe())%>">
        &nbsp&nbsp&nbsp&nbspConducatorul sub-unitatii de exploatare:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT"
               NAME="<%=EchipamentConstants.CONDUCATOR_UNITATE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getConducatorUnitate())%>">.
    </TD>
</TR>

<TR>

    <TD colspan="2">
        <b>19.</b> Avizul comisiei tehnice:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT" NAME="<%=EchipamentConstants.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="<%=EchipamentConstants.CONDUCATOR_TEHNIC%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getConducatorTehnic())%>">.
        &nbsp&nbsp&nbsp&nbspInspector incidente:
        <INPUT maxlength="100" size="40" class="gsapinputtext" TYPE="TEXT"
               NAME="<%=EchipamentConstants.INSPECTOR_INCIDENTE%>"
               VALUE="<%=ObjectUtils.getStringValue( bean.getInspectorIncidente())%>">.
    </TD>

</TR>

<TR>
    <TD align="center" valign=top colspan="2">
        <% if (bean.getIncidentId() != -1) { %>
        <input type="checkbox" value=1 name="<%=EchipamentConstants.MAI_SUNT_ECHIP_AF%>" id="maiSuntEchiamenteAfectate"><label
            for="maiSuntEchiamenteAfectate">Mai exista echipamente afectate</label>&nbsp;&nbsp;&nbsp;&nbsp;
        <% }%>
        &nbsp;&nbsp;
        <input type="button" onclick="{ this.disabled = true; this.form.submit();}" value="Salvează"/> &nbsp;&nbsp;&nbsp;
        <input type="button" onclick="window.location = '<%=AppConstants.APP_NAME%>?action=renuntaEditEchipament'"
               value="Renunță"/>
    </TD>
</TR>

</FORM>
</TABLE>

<%@ 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%>");

        // 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 () {
    return "<%=AppConstants.APP_NAME%>?action=suggestCelule&codCe=<%=codCe%>&<%=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 codLinie = $("<%=IncidentConstants.LINIE_COD%>").value;

    return "<%=AppConstants.APP_NAME%>?action=suggestLinii&codCe=<%=codCe%>" + "&<%=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) {

            $("<%=IncidentConstants.STATIE_COD%>").value = item.cod;

            // clear bobine, linii, posturi, derivatii

            $('<%=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;
        }
    });
}

setTimeout(initSugestsLocalizareIncident, 1000);

function fill_componente_select() {
    <% final Nomenclator[] grupAnsambluri = NomAccessDB.getAllNom( NomConstants.NOM_ANSAMBLURI); %>
    ansambluri = new Array(<%=grupAnsambluri.length%>);
    <%for(int i = 0; i < grupAnsambluri.length; i++) {
        final Nomenclator grupCauza = grupAnsambluri[i]; %>
    ansambluri[<%=i%>] = new Array(<%=grupCauza.getId()%>, <%=grupCauza.getCod()%>);
    <%}%>

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


    resetComboLeaveFirstOption(zaforma.<%=EchipamentConstants.COMPONENTA_ID%>);

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

    indexx = 0;
    for (i = 0; i < cauze_select.length; i++) {
        if (codGrupa == cauze_select[i][1] || ( (codGrupa == 50 || codGrupa == 51) && (cauze_select[i][1] == 50 || cauze_select[i][1] == 51) )) {
            //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.<%=EchipamentConstants.COMPONENTA_ID%>.options[++indexx] = optNewOption;
            //indexx++;
        }
    }
}


function fill_cauze_select() {
    <% final Nomenclator[] grupCauze = NomAccessDB.getAllNom( NomConstants.NOM_GRUPE_CAUZE_ECH); %>
    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_ECH); %>
    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.<%=EchipamentConstants.CAUZA_ID%>);
    <%--for (i = 0; zaforma.<%=EchipamentConstants.CAUZA_ID%>.options.length > 0;) {--%>
    <%--zaforma.<%=EchipamentConstants.CAUZA_ID%>.options[i] = null;--%>
    <%--}--%>

    cauzaGrupId = zaforma.<%=EchipamentConstants.CAUZA_GR_ID%>.options[zaforma.<%=EchipamentConstants.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);

            // optNewOption.selected = selectedValue && cauze_select[i][0] == selectedValue;
            zaforma.<%=EchipamentConstants.CAUZA_ID%>.options[ ++indexx] = optNewOption;
            //indexx++;
        }
    }
}

function on_ansamblu_changed() {
    enable_ansamble_selects();
    fill_componente_select();
    fill_statii_selects();
    fill_linii_selects();
    fill_pa_pt_selects();

    fillEqOrfane();
}

function fillAllOnEdit() {
    //alert( 'fill all selects' );
    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 onChangeSelect(oSelect) {
    document.zaforma.<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>.value = '';
    new Ajax.Request('<%=AppConstants.APP_NAME%>?action=getDataPIF',
            {
                method: 'post',
                parameters: 'idEq=' + getSelectedValue(oSelect),
                onComplete: getDataPifResponse
            });
}

function getDataPifResponse(originalRequest) {
    var response = getResponseMesg(originalRequest.responseText);
    if (response != null) {
        response = response.trim();
        if (response.indexOf(",") > 0) {
            var arr = response.split(",");
            document.zaforma.<%=EchipamentConstants.AN_PUNERE_FUNCTIUNE%>.value = arr[0];
            document.zaforma.<%=EchipamentConstants.LUNA_PUNERE_FUNCTIUNE%>.value = arr[1];

            setDurataFunctionareDeLaPIF();
        }
    }
}

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

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

fill_componente_select();
selectOption(document.zaforma.<%=EchipamentConstants.COMPONENTA_ID%>, <%=bean.getComponentaId()%>);

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

<script type='text/javascript'>
    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<%=EchipamentConstants.PROPUNERI%>','charCount<%=EchipamentConstants.PROPUNERI%>')},55);
    setInterval(function(){CharacterCount('textarea<%=EchipamentConstants.MASURI_PREV%>','charCount<%=EchipamentConstants.MASURI_PREV%>')},55);
    setInterval(function(){CharacterCount('textarea<%=EchipamentConstants.OBS%>','charCount<%=EchipamentConstants.OBS%>')},55);

</script>
