<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.lpod.db.ComandaSAPAccessDB" %>
<%@ page import="ro.emid.lpod.obj.*" %>
<%@ page import="ro.emid.common.types.binder.LucrareProgramataBinder" %>
<%@ page import="java.util.List" %>
<%@ page import="ro.emid.lpod.action.lucrariProgramate.EditorLucrareHelper" %>
<%@ page import="ro.emid.common.components.sugest.base.SugestConstants" %>
<%@ page import="java.util.Map" %>
<%@ page import="ro.emid.common.constants.*" %>
<%@ page import="ro.emid.common.types.*" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ page import="ro.emid.common.constants.CategoriiInstalatii" %>
<%@ page import="ro.emid.common.action.browse.adrese.BrowseAdresaAction" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="ro.emid.lpod.LpodSessionUtils" %>
<%@ page import="ro.emid.lib.view.LucrareProgramataxFieldsView" %>

<%@ taglib prefix="emid" tagdir="/WEB-INF/tags" %>

<%
    final User user = LpodSessionUtils.getUserLogat(session);
    final Category centruExploatare = LpodSessionUtils.getCentru(session);
    final Category formatiaDeLucru = LpodSessionUtils.getFormatia(session);
    final boolean printVersion = request.getParameter("printVersion") != null && "true".equals( request.getParameter("printVersion")) || request.getAttribute("printVersion") != null && "true".equals( request.getAttribute("printVersion")) ;


    final LucrareProgramataBinder binder = EditorLucrareHelper.getBinder(request);
    final LucrareProgramata bean = (LucrareProgramata) binder.getBean();

    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 Map customValidationMessages = binder.getCustomValidationMessages();

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

    int[] codeFlags = FisaUtils.getCodeFlags(map);
	
	LucrareProgramataxFieldsView lpxView = new LucrareProgramataxFieldsView();

%>

<emid:template-lp title="Lucrare programata">
    <jsp:attribute name="breadcrumb">
        <emid:localizare-lp>
            <span class="slash">/</span> Lucrări programate
        </emid:localizare-lp>
    </jsp:attribute>
    <jsp:attribute name="body">

        <table border=1 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" id="formTable">
        <tr>
            <th class="gsapthead" colSpan=2 height=25 noWrap>&nbsp;Fişa lucrare programată&nbsp;</th>
        </tr>

        <FORM NAME="zaforma" ACTION="<%=AppConstants.APP_NAME%>?action=save-lucrare" METHOD=POST onsubmit="return onSubmit()">
        <INPUT TYPE="hidden" NAME="<%=LucrareProgramataConstants.JSP.ID%>" VALUE="<%=bean.getId()%>"/>
        <INPUT TYPE="hidden" NAME="<%=LucrareProgramataConstants.JSP.FILIALA_ID%>" VALUE="<%=bean.getFilialaId()%>"/>
        <INPUT TYPE="hidden" NAME="<%=LucrareProgramataConstants.JSP.SUCURSALA_ID%>" VALUE="<%=bean.getSucursalaId()%>"/>
        <INPUT TYPE="hidden" NAME="<%=LucrareProgramataConstants.JSP.SECTIE_ID_TO_SAVE%>" VALUE="<%=bean.getCentruId()%>"/>

        <TR>
            <TD width="25%">
                <b>1.</b> Numar curent lucrare:
            </TD>

            <TD width="75%">
                <span style="float:right;">v. <%=ObjectUtils.getStringValue(bean.getVersion())%></span>
                <INPUT class="gsapinputtext" TYPE="TEXT" readonly name="<%=LucrareProgramataConstants.JSP.NUMAR%>"
                       VALUE="<%=LucrareProgramataUtils.getNumar(bean)%>">
            </TD>
        </TR>
        <script type="text/javascript">
            var input = jQuery("input[name=" + "<%=LucrareProgramataConstants.JSP.NUMAR%>" + "]");
        </script>

        <TR>
        <TD valign=top>
            <b>2.</b> Localizare lucrare:
            <%
                ComandaSAP comanda = null;
                if (!StringUtils.isZeroLength(bean.getNumarComanda())) {
                    comanda = ComandaSAPAccessDB.getByNumar(bean.getNumarComanda());
                }
            %>
            <%if (comanda != null) {%>
            <br>

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

            <div id="dateEveniment" style="display: none">
                <b>NR_COMANDA :</b> <%=comanda.getNrComanda()%><br>
                <b>NR_NOTIFICARE :</b> <%=comanda.getNrNotificare()%><br>
                <b>ULPI:</b> <%=comanda.getUlpi()%><br>
                <b>ID_OBIECT:</b> <%=comanda.getIdObiect()%><br>
                <b>NR_ECHIPAMENT:</b> <%=comanda.getNrEchipament()%><br>
                <b>DESC.:</b> <%=comanda.getDescriereObiectTehnic()%><br>
                <b>TIP_OB_TEHNIC:</b> <%=comanda.getTipObiectTehnic()%><br>
                <b>TEXT_TIP_OB_TEHNIC:</b> <%=comanda.getTextTipObiectTehnic()%><br>
                <b>LOC_FUNCTIONAL:</b> <%=comanda.getLocFunctional()%><br>
                <b>TEXT_LOC_FUNCTIONAL:</b> <%=comanda.getTextLocFuctional()%><br>
                <b>TEXT:</b> <%=comanda.getText()%><br>
                <b>DATA_COM:</b> <%=AppConstants.format(comanda.getDataComanda())%><br>
            </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> 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="<%=LucrareProgramataConstants.JSP.CENTRU_ID%>" value="<%=centruBean.getId()%>">
                <input type="hidden" name="<%=LucrareProgramataConstants.JSP.CENTRU_ID%>h" value="<%=centruBean.getCodSap()%>"
                       codSapOriginal="<%=centruBean.getCodSap()%>">

                &nbsp;&nbsp;<b>2.3.1</b>&nbsp; Formatia de lucru:
                <select class="gSAPSelect"
                        name="<%=LucrareProgramataConstants.JSP.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><strong>Nivel tensiune:</strong></TD>
            <td colspan="3">
                <span <% if (!centruBean.isJT()) {%> style="display: none"  <% } %> >
                    <input type="radio" id="nt_jt"
                           name="<%=LucrareProgramataConstants.JSP.NIVEL_TENSIUNE%>"
                        <%=NivelTensiune.is( bean.getNivelTensiune(), NivelTensiune.JT) ? "checked" : ""%>
                           value="<%=NivelTensiune.JT%>"
                           onclick="showNivelTensiuneFields()"> <label for="nt_jt">JT</label>
                    &nbsp;&nbsp;
                </span>

                <span <% if (!centruBean.isMT()) {%> style="display: none" <% } %> >
                    <input type="radio" id="nt_mt" name="<%=LucrareProgramataConstants.JSP.NIVEL_TENSIUNE%>"
                        <%=NivelTensiune.is( bean.getNivelTensiune(), NivelTensiune.MT) ? "checked" : ""%>
                           value="<%=NivelTensiune.MT%>" onclick="showNivelTensiuneFields()"> <label for="nt_mt">MT</label>
                    &nbsp;&nbsp;
                </span>

                <span <% if (!centruBean.isIT()) {%> style="display: none"  <% } %>>
                    <input type="radio" id="nt_it"
                           name="<%=LucrareProgramataConstants.JSP.NIVEL_TENSIUNE%>" <%=NivelTensiune.is( bean.getNivelTensiune(), NivelTensiune.IT) ? "checked" : ""%>
                           value="<%=NivelTensiune.IT%>" onclick="showNivelTensiuneFields()"> <label for="nt_it">IT</label>
                </span>

                <% if (CategoryUtils.hasNoNivelTensiune(centruBean)) {%>
                <span style="color: red"> Atentie! Centrul <%=centruBean.getName()%> nu este repartizat pe nici-un nivel de tensiune (IT, MT sau JT).</span>
                <% } %>

                <script type="text/javascript">

                    function showNivelTensiuneFields() {
                        $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").readOnly = false;
                        $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>").readOnly = false;

                        $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").onclick = null;
                        $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>").onclick = null;

                        showJtFields(false);
                        showItFields(false);


                        if ($("nt_jt").checked) {
                            showItFields(false);
                            showJtFields(true);

                            if ($("nt_mt").checked) {
                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").readOnly = true;

                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").onclick = function () {
                                    alert("Ati selectat nivel tensiune MT. Nu puteti completa utilizatori de IT");
                                };
                            }

                            if ($("nt_jt").checked) {
                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").readOnly = true;

                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>").onclick = function () {
                                    alert("Ati selectat nivel tensiune JT. Nu puteti completa utilizatori de IT");
                                };

                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>").readOnly = true;
                                $("<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>").onclick = function () {
                                    alert("Ati selectat nivel tensiune JT. Nu puteti completa utilizatori de MT");
                                };
                            }

                        } else if ($("nt_mt").checked) {
                            showJtFields(false);
                            showMtFields(true);
                        } else if ($("nt_it").checked) {
                            showJtFields(false);
                            showItFields(true);
                        }
                    }

                    function showJtFields(show) {
                        commonShowNivelTensiuneFields("<%=NivelTensiune.JT%>", show);
                        showAdreseTable(true);
                    }

                    function showAdreseTable(show) {
                        var adreseTable = $('adreseTable');
                        if (show) {
                            Element.show(adreseTable);
                        } else {
                            Element.hide(adreseTable);
                        }
                    }

                    function showMtFields(show) {
                        commonShowNivelTensiuneFields("<%=NivelTensiune.IT%>", show);
                        showAdreseTable(true);
                    }

                    function showItFields(show) {
                        commonShowNivelTensiuneFields("<%=NivelTensiune.IT%>", show);
                        showAdreseTable(false);
                    }

                    function commonShowNivelTensiuneFields(nivelTensiune, show) {
                        var list = $("formTable").getElementsByTagName("tr");
                        for (var i = 0; i < list.length; i++) {
                            var el = list[i];
                            var attrNivelTensiune = el.getAttribute("nivelTensiune");
                            if (attrNivelTensiune && nivelTensiune == attrNivelTensiune) {
                                if (show) {
                                    Element.show(el);
                                } else {
                                    Element.hide(el);
                                }
                            }
                        }

                        if (show) {
                            Element.show("butonulBrowse");
                        } else {
                            Element.hide("butonulBrowse");
                        }
                    }
                </script>
            </td>
        </TR>

        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD>
                <b>2.4</b> Ansamblu functional:
            </TD>
            <TD colspan="3">
                <SELECT name="<%=LucrareProgramataConstants.JSP.ANSAMBLU_ID%>" class="gSAPSelect"
                        onChange="on_ansamblu_changed();">
                    <OPTION value="-1">Selectati:</OPTION>
                    <% Util.showNomOptions(out, NomConstants.NOM_ANSAMBLURI, bean.getAnsambluId()); %>
                </SELECT>
                <SELECT name="<%=LucrareProgramataConstants.JSP.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="<%=LucrareProgramataConstants.JSP.EXPLICATII%>"
                                                           value="<%=ObjectUtils.getStringValue( bean.getExplicatii())%>">
            </TD>
        </TR>

        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD>
                <b>2.5</b> Statie:
            </TD>
            <TD>
           <span id="<%=TipInstalatie.STATIE%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.STATIE_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.STATIE_ID%>" value="<%=bean.getStatieId()%>"/>
               <input type="hidden" id="<%=LucrareProgramataConstants.JSP.STATIE_COD%>"
                      name="<%=LucrareProgramataConstants.JSP.STATIE_COD%>" value="<%=AppConstants.format(bean.getStatieCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.STATIE_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.STATIE_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getStatieDen())%>"/>
             </span>
            </TD>
            <td nowrap="nowrap">
                <b>2.5.1</b> Bobina:
            </td>
            <td width="1000">
            <span id="<%=TipInstalatie.BOBINA%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.BOBINA_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.BOBINA_ID%>" value="<%=bean.getBobinaId()%>"/>
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.BOBINA_COD%>"
                       name="<%=LucrareProgramataConstants.JSP.BOBINA_COD%>" value="<%=AppConstants.format(bean.getBobinaCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.BOBINA_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.BOBINA_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getBobinaDen())%>"/>
            </span>
            </TD>
        </TR>

        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD>
                <b>2.6</b> Celula:
            </TD>
            <TD>
            <span id="<%=TipInstalatie.CELULA%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.CELULA_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.CELULA_ID%>" value="<%=bean.getCelulaId()%>"/>
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.CELULA_COD%>"
                       name="<%=LucrareProgramataConstants.JSP.CELULA_COD%>" value="<%=AppConstants.format(bean.getCelulaCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.CELULA_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.CELULA_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getCelulaDen())%>"/>
            </span>
            </TD>
            <td nowrap="nowrap">
                <b>2.6.1</b> Bara:
            </td>
            <td>
            <span id="<%=TipInstalatie.BARA%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.BARA_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.BARA_ID%>" value="<%=bean.getBaraId()%>"/>
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.BARA_COD%>"
                       name="<%=LucrareProgramataConstants.JSP.BARA_COD%>" value="<%=AppConstants.format(bean.getBaraCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.BARA_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.BARA_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getBaraDen())%>"/>
            </span>
            </TD>
        </TR>

        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD>
                <b>2.7</b> Linie:
            </TD>
            <TD>
             <span id="<%=TipInstalatie.LINIE%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.LINIE_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.LINIE_ID%>" value="<%=bean.getLinieId()%>"/>
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.LINIE_COD%>"
                        name="<%=LucrareProgramataConstants.JSP.LINIE_COD%>" value="<%=AppConstants.format(bean.getLinieCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.LINIE_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.LINIE_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getLinieDen())%>"/>
            </span>
            </TD>
            <td nowrap="nowrap">
                <b>2.7.1</b> Derivatie:
            </td>
            <td>
            <span id="<%=TipInstalatie.DERIVATIE%>div">
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.DERIVATIE_ID%>"
                       name="<%=LucrareProgramataConstants.JSP.DERIVATIE_ID%>" value="<%=bean.getDerivatieId()%>"/>
                <input type="hidden" id="<%=LucrareProgramataConstants.JSP.DERIVATIE_COD%>"
                       name="<%=LucrareProgramataConstants.JSP.DERIVATIE_COD%>" value="<%=AppConstants.format(bean.getDerivatieCod())%>"/>
                <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.DERIVATIE_DEN%>"
                       name="<%=LucrareProgramataConstants.JSP.DERIVATIE_DEN%>" maxlength="100" style="width: 285px"
                       sugestWidth="285" value="<%=AppConstants.format(bean.getDerivatieDen())%>"/>
            </span>
            </TD>
        </TR>

        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD><b>2.8</b> PA/PT:</TD>
            <TD colspan="3">
                <span id="<%=TipInstalatie.PA_PT%>div">
                    <input type="hidden" id="<%=LucrareProgramataConstants.JSP.PAPT_ID%>"
                           name="<%=LucrareProgramataConstants.JSP.PAPT_ID%>" value="<%=bean.getPA_PT_Id()%>"/>
                    <input type="hidden" id="<%=LucrareProgramataConstants.JSP.PAPT_COD%>"
                           name="<%=LucrareProgramataConstants.JSP.PAPT_COD%>" value="<%=AppConstants.format(bean.getPaptCod())%>"/>
                    <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.PAPT_DEN%>"
                           name="<%=LucrareProgramataConstants.JSP.PAPT_DEN%>" maxlength="100" style="width: 285px"
                           sugestWidth="285" value="<%=AppConstants.format(bean.getPaptDen())%>"/>
                </span>
            </TD>
        </TR>
        <TR class="gSAPGroup" nivelTensiune="<%=NivelTensiune.IT%>">
            <TD><b>2.9</b> Trafo:</TD>
            <TD colspan="3">
                <span id="<%=TipInstalatie.TRAFO%>div">
                    <input type="hidden" id="<%=LucrareProgramataConstants.JSP.TRAFO_ID%>"
                           name="<%=LucrareProgramataConstants.JSP.TRAFO_ID%>" value="<%=bean.getTrafoId()%>"/>
                     <input type="hidden" id="<%=LucrareProgramataConstants.JSP.TRAFO_COD%>"
                            name="<%=LucrareProgramataConstants.JSP.TRAFO_COD%>" value="<%=AppConstants.format(bean.getTrafoCod())%>"/>
                    <input class="gsapinputtext" id="<%=LucrareProgramataConstants.JSP.TRAFO_DEN%>"
                           name="<%=LucrareProgramataConstants.JSP.TRAFO_DEN%>" maxlength="100" style="width: 285px"
                           sugestWidth="285" value="<%=AppConstants.format(bean.getTrafoDen())%>"/>
                </span>
            </TD>
        </TR>

        <tr class="gSAPGroup" nivelTensiune="<%=NivelTensiune.JT%>">
            <td>Categoria de instalatii:</td>
            <td colspan="3">
                <select class="gSAPSelect" name="<%=LucrareProgramataConstants.JSP.CAT_INSTALATII%>">
                    <OPTION VALUE="-1">Selectati:</OPTION>
                    <% for (int i = 1; i < CategoriiInstalatii.CAT_INSTALATII.length; i++) {
                        final String catInstalatii = CategoriiInstalatii.CAT_INSTALATII[i];%>
                    <option value="<%=i%>" <%=bean.getCatInstalatii() == i ? "selected" : ""%> ><%=catInstalatii%>
                    </option>
                    <% }%>
                </select>
            </td>
        </tr>
        <tr class="gSAPGroup" nivelTensiune="<%=NivelTensiune.JT%>">
            <td>Instalatia:</td>
            <td>
                <SELECT NAME="<%=LucrareProgramataConstants.JSP.INSTALATIA%>" class="gSAPSelect">
                    <option value="-1">Selectati:</option>
                    <% for (int i = 1; i < CategoriiInstalatii.INSTALATII.length; i++) {
                        final String instalatia = CategoriiInstalatii.INSTALATII[i];%>
                    <option value="<%=i%>" <%=bean.getInstalatia() == i ? "selected" : ""%> ><%=instalatia%>
                    </option>
                    <% }%>
                </select>

                &nbsp;&nbsp;
                Nr./Denumire: <input type="text" size="40" class="gsapinputtext"
										name="<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>"
										id="<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>" 
										value="<%=AppConstants.format( bean.getDenumireInstalatie())%>">
								
								<input type="hidden" id="<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>_ID">
								<input type="hidden" id="<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>_COD">
            </td>
			
        </tr>
        <tr class="gSAPGroup" nivelTensiune="<%=NivelTensiune.JT%>" id="adreseTable">
            <td>Adrese</td>
            <td colspan="3">

                <%
                    final List adrese = bean.getAdreseLucrare();
                %>
                <a href="#" class="link" onclick="document.zaforma.action='<%=AppConstants.APP_NAME%>?action=addAdresaForLucrare';document.zaforma.submit(); return false;">Adaugă adresă</a>
                <%--|--%>
                <%--<a href="javascript: void( null)" class="link" onclick="adaugaAdreseMultiple(); return false;">Adauga adrese</a>--%>
                <table cellpadding=2 cellspacing=1 width="100%" class="table">
                    <thead>
                        <tr>
                            <th height=25 nowrap>Localitate/Comuna:</th>
                            <th nowrap>Sat:</th>
                            <th nowrap>Denumire:</th>
                            <th nowrap>Tip artera:</th>
                            <th nowrap>Numar:</th>
                            <th nowrap>Bloc:</th>
                            <th nowrap>Judet:</th>
                            <th width="1%" noWrap>&nbsp;</th>
                        </tr>
                    </thead>
                    <tbody>
                        <% if (ListItemUtils.getSize(adrese) == 0) { %>
                        <tr>
                            <td colspan="10" class="no-data">Fară adrese completate ...</td>
                        </tr>
                            <% } else for (int i = 0; i < adrese.size(); i++) {
                            final Adresa adresa = (Adresa) adrese.get(i);

                            if (adresa.toDelete()) continue; %>

                        <tr align="center">
                            <td>
                                <input type="hidden" id="<%=AdresaConstants.COD_LOCALITATE + i%>" name="<%=AdresaConstants.COD_LOCALITATE + i%>"
                                       value="<%=AppConstants.format( adresa.getCodLocalitate())%>"/>
                                <input class="gsapinputtext" maxlength="100" style="width: 170px" sugestWidth="250"
                                       id="<%=AdresaConstants.LOCALITATE + i%>" name="<%=AdresaConstants.LOCALITATE + i%>"
                                       value="<%=AppConstants.format( adresa.getLocalitate())%>"/>
                                <% final String vLocalitate = (String) customValidationMessages.get(AdresaConstants.LOCALITATE + i);
                                    if (vLocalitate != null) { %>
                                <br/>
                                            <span style="color: red">
                                                <%=vLocalitate%>
                                            </span>
                                <% } %>
                            </td>
                            <td>
                                <input type="hidden" id="<%=AdresaConstants.COD_LOCALITATE2 + i%>" name="<%=AdresaConstants.COD_LOCALITATE2 + i%>"
                                       value="<%=AppConstants.format( adresa.getCodLocalitate2())%>"/>
                                <input class="gsapinputtext" maxlength="100" style="width: 170px" sugestWidth="250"
                                       id="<%=AdresaConstants.LOCALITATE2 + i%>" name="<%=AdresaConstants.LOCALITATE2 + i%>"
                                       value="<%=AppConstants.format( adresa.getLocalitate2())%>"/>
                                <%
                                    final String vLocalitate2 = (String) customValidationMessages.get(AdresaConstants.LOCALITATE2 + i);
                                    if (vLocalitate2 != null) { %>
                                <br/>
                                            <span style="color: red">
                                                <%=vLocalitate2%>
                                            </span>
                                <% } %>
                            </td>
                            <td>
                                <input type="hidden" name="<%=AdresaConstants.COD_STRADA + i%>" id="<%=AdresaConstants.COD_STRADA + i%>"
                                       value="<%=AppConstants.format( adresa.getCodStrada())%>"/>
                                <input class="gsapinputtext" maxlength="100" style="width: 200px"
                                       name="<%=AdresaConstants.DEN_STRADA  + i%>" id="<%=AdresaConstants.DEN_STRADA + i%>"
                                       value="<%=AppConstants.format( adresa.getDenStrada())%>">
                                <% final String vDenStrada = (String) customValidationMessages.get(AdresaConstants.DEN_STRADA + i);
                                    if (vDenStrada != null) { %>
                                <br/>
                                            <span style="color: red">
                                                <%=vDenStrada%>
                                            </span>
                                <% } %>
                            </td>
                            <td>
                                <input class="gsapinputtext" maxlength="50" style="width: 60px" type=text
                                       id="<%=AdresaConstants.TIP_ARTERA + i%>" name="<%=AdresaConstants.TIP_ARTERA + i%>"
                                       value="<%=AppConstants.format( adresa.getTipArtera()) %>">
                                <% final String vTipArtera = (String) customValidationMessages.get(AdresaConstants.TIP_ARTERA + i);
                                    if (vTipArtera != null) { %>
                                <br/>
                                            <span style="color: red">
                                                <%=vTipArtera%>
                                            </span>
                                <% } %>
                            </td>
                            <td>
                                <input class="gsapinputtext" type="text" maxlength="50" size="5" id="<%=AdresaConstants.NR + i%>"
                                       name="<%=AdresaConstants.NR + i%>" value="<%=AppConstants.format( adresa.getNr())%>">
                            </td>
                            <td>
                                <input class="gsapinputtext" type="text" size="5" id="<%=AdresaConstants.BLOC + i%>"
                                       name="<%=AdresaConstants.BLOC + i%>" value="<%=AppConstants.format( adresa.getBloc())%>">
                            </td>
                            <td>
                                <input class="gsapinputtext" type="text" size="8" readonly id="<%=AdresaConstants.JUDET + i%>"
                                       name="<%=AdresaConstants.JUDET + i%>" value="<%=AppConstants.format( adresa.getJudet())%>">
                            </td>
                            <td>
                                <nobr>
                                    <a href="#" class="link" onclick="if( confirm('Stergeti adresa selectata ?')) { document.zaforma.action='<%=AppConstants.APP_NAME%>?action=deleteAdresaFromLucrare&index=<%=i%>'; document.zaforma.submit();} return false;">Șterge</a>
                                </nobr>
                            </td>
                        </tr>
                            <% } %>
                    </tbody>
                </table>
            </td>
        </tr>
        </TABLE>

        </TD>
        </TR>
		
		<tr>
			<TD>
                <b>3.</b> Nume utilizatori:
            </TD>
			<td>
				<input type="text" name="numeUtilizatori" value="<%=lpxView.getNumeUtilizatori(bean.getId())%>" />
			</td>
		</tr>
		
        <TR>
            <TD>
                <b>4.</b> Mediul:
            </TD>
            <TD>
                <INPUT id="urban" type=radio value="<%=Mediu.URBAN%>" <%=Mediu.is( bean.getMediu(), Mediu.URBAN)?"checked":""%>
                       name="<%=LucrareProgramataConstants.JSP.MEDIU%>"> <LABEL for="urban">Urban</LABEL> &nbsp;
                <INPUT id="rural" type=radio value="<%=Mediu.RURAL%>" <%=Mediu.is( bean.getMediu(), Mediu.RURAL)?"checked":""%>
                       name="<%=LucrareProgramataConstants.JSP.MEDIU%>"> <LABEL for="rural">Rural</LABEL>
            </TD>
        </TR>

        <%
            String tipInterval = "";
            List intervale = null;
            String jsFunctionCalculDurata = "";
        %>

        <script type="text/javascript">
            function adaugaInterval(tip) {
                document.zaforma.action = '<%=AppConstants.APP_NAME%>?action=addIntervalForLucrare&<%=IntervalLucrareConstants.TIP%>=' + tip;
                document.zaforma.submit();
            }

            function stergeInterval(index, tip) {
                if (confirm("Stergeti intervalul ?")) {
                    document.zaforma.action = '<%=AppConstants.APP_NAME%>?action=deleteIntervalFromLucrare&<%=IntervalLucrareConstants.TIP%>=' + tip + "&index=" + index;
                    document.zaforma.submit();
                }
            }
        </script>

        <TR>
            <TD vAlign=top><B>5.</B> Durata programata:</TD>
            <TD vAlign=center>
                <%
                    tipInterval = IntervalLucrare.Tip.INTERVAL_LUCRARE_PROGR;
                    intervale = bean.getIntervaleLucrareProgramata();
                    jsFunctionCalculDurata = "calculeazaDurataProgramata";
                %>
                <table border="0">
                    <tr>
                        <td>
                            Data start: <INPUT class=gsapinputtext
                                               id="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_START%>"
                                               style="WIDTH: 120px"
                                               value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_PROGRAMARE_START)%>"
                                               name="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_START%>"
                                               onblur=" calculeazaDurataProgramata()"
                                >
                            <a id="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_START%>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;
                        </td>
                        <td>
                            Data stop: <INPUT class=gsapinputtext id="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>"
                                              style="WIDTH: 120px"
                                              value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP)%>"
                                              name="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>"
                                              onblur=" calculeazaDurataProgramata()"
                                >
                            <a id="<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>trigger" href="#"><img
                                    src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"
                                    alt="Apasa pt. a selecta data"></a>

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

                                Calendar.setup({
                                    inputField: "<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>",         // ID of the input field
                                    ifFormat: "%d.%m.%Y %H:%M",       // the date format
                                    button: "<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>trigger",         // ID of the button
                                    showsTime: true,
                                    onUpdate: calculeazaDurataProgramata
                                });

                                function calculeazaDurataProgramata() {
                                    var durataTotala = getDiferentaDate(
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_STOP%>'),
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_PROGRAMARE_START%>')
                                    );

                                    durataTotala += calculeazaDurataIntervale<%=tipInterval%>();        //definita in _intervalale.jspf


                                    var ore = Math.floor(durataTotala / 60);
                                    var minute = (durataTotala % 60);

                                    $("durataProgramata_").innerHTML = ore + "h " + minute + "' ";
                                }
                            </script>
                        </td>
                        <td>
                            &nbsp;&nbsp;
                            <input type="button" style="font-size:10px" onClick="adaugaInterval('<%=tipInterval%>')"
                                   value="Adaugă interval"/>
                        </td>
                    </tr>
                    <%@ include file="_intervale.jspf" %>

                    <tr>
                        <td colspan="3" style="color: green;border-top:1px solid gray">
                            Durata : <span id="durataProgramata_"></span>
                        </td>
                    </tr>
                </table>
            </TD>
        </TR>

        <TR>
            <TD vAlign=top>
                <B>6.</B> Durata realizarii lucrarii:
            </TD>
            <TD>
                <table border="0">
                    <tr>
                        <td>
                            <%
                                tipInterval = IntervalLucrare.Tip.INTERVAL_LUCRARE;
                                intervale = bean.getIntervaleLucrare();
                                jsFunctionCalculDurata = "calculeazaDurataRealizare";
                            %>
                            Data start: <INPUT class=gsapinputtext id="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_START%>"
                                               style="WIDTH: 120px"
                                               value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_LUCRARE_START)%>"
                                               name="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_START%>"
                                               onblur=" calculeazaDurataRealizare()"
                                />
                            <a id="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_START%>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;
                        </td>
                        <td>
                            Data stop: <INPUT class=gsapinputtext id="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>"
                                              style="WIDTH: 120px"
                                              value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP)%>"
                                              name="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>"
                                              onblur=" calculeazaDurataRealizare()"
                                />

                            <a id="<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>trigger" href="#"><img
                                    src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"
                                    alt="Apasa pt. a selecta data"></a>
                        </td>
                        <td>
                            &nbsp;&nbsp;
                            <input type="button" style="font-size:10px" onClick="adaugaInterval('<%=tipInterval%>')"
                                   value="Adaugă interval"/>

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

                                Calendar.setup({
                                    inputField: "<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>",         // ID of the input field
                                    ifFormat: "%d.%m.%Y %H:%M",       // the date format
                                    button: "<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>trigger",         // ID of the button
                                    showsTime: true,
                                    onUpdate: calculeazaDurataRealizare
                                });

                                function calculeazaDurataRealizare() {
                                    var durataTotala = getDiferentaDate(
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_STOP%>'),
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_LUCRARE_START%>')
                                    );

                                    durataTotala += calculeazaDurataIntervale<%=tipInterval%>();        //definita in _intervalale.jspf


                                    var ore = Math.floor(durataTotala / 60);
                                    var minute = (durataTotala % 60);

                                    $("durataRealizare_").innerHTML = ore + "h " + minute + "' ";
                                }
                            </script>
                        </td>
                    </tr>
                    <%@ include file="_intervale.jspf" %>
                    <tr>
                        <td colspan="3" style="color: green;border-top:1px solid gray">
                            Durata : <span id="durataRealizare_"></span>
                        </td>
                    </tr>
                </table>
            </TD>
        </TR>


        <TR valign="top">
            <TD>
                <b>7.</b> Durata intreruperii consumatorilor:
            </TD>
            <td>
                <%
                    tipInterval = IntervalLucrare.Tip.INTERVAL_INTRERUPERE;
                    intervale = bean.getIntervaleIntrerupere();
                    final String messageNoItem = "Fara intreruperea consumatorilor";
                    jsFunctionCalculDurata = "calculeazaDurataIntrerupere";
                %>

                <%--<%@ include file="_intervale2.jspf"%>--%>
                <table border="0">
                    <tr>
                        <td>
                            Data start: <INPUT class=gsapinputtext
                                               id="<%=LucrareProgramataConstants.JSP.DATA_INTR_START%>"
                                               style="WIDTH: 120px"
                                               value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_INTR_START)%>"
                                               name="<%=LucrareProgramataConstants.JSP.DATA_INTR_START%>"
                                               onblur=" calculeazaDurataIntrerupere()"
                                />
                            <a id="<%=LucrareProgramataConstants.JSP.DATA_INTR_START%>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;
                        </td>
                        <td>
                            Data stop: <INPUT class=gsapinputtext
                                              id="<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>"
                                              style="WIDTH: 120px"
                                              value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.DATA_INTR_STOP)%>"
                                              name="<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>"
                                              onblur=" calculeazaDurataIntrerupere()"
                                />
                            <a id="<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>trigger" href="#"><img
                                    src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0"
                                    alt="Apasa pt. a selecta data"></a>

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

                                Calendar.setup({
                                    inputField: "<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>",         // ID of the input field
                                    ifFormat: "%d.%m.%Y %H:%M",       // the date format
                                    button: "<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>trigger",         // ID of the button
                                    showsTime: true,
                                    onUpdate: calculeazaDurataIntrerupere
                                });

                                function getDurataTotalaIntrerupere() {
                                    var durataTotala = getDiferentaDate(
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_INTR_STOP%>'),
                                            getDate('<%=LucrareProgramataConstants.JSP.DATA_INTR_START%>')
                                    );

                                    durataTotala += calculeazaDurataIntervale<%=tipInterval%>();        //definita in _intervalale.jspf

                                    return durataTotala;
                                }

                                function calculeazaDurataIntrerupere() {
                                    var durataTotala = getDurataTotalaIntrerupere();

                                    var ore = Math.floor(durataTotala / 60);
                                    var minute = (durataTotala % 60);

                                    $("durataIntrerupere_").innerHTML = ore + "h " + minute + "' ";
                                }
                            </script>

                            &nbsp;&nbsp;
                            <input type="button" style="font-size:10px" onClick="adaugaInterval('<%=tipInterval%>')"
                                   value="Adaugă interval"/>
                        </td>
                    </tr>
                    <%@ include file="_intervale.jspf" %>
                    <tr>
                        <td colspan="3" style="color: green;border-top:1px solid gray">
                            Durata : <span id="durataIntrerupere_"></span>
                        </td>
                    </tr>
                </table>
            </TD>
        </TR>

        <TR
        <%--niveltensiune="<%=NivelTensiune.IT%>"--%>
                >
            <TD>
                <b>8.</b> Energia electrica nelivrata consumatorilor:
            </TD>
            <td>
                <INPUT class="gsapinputtext" TYPE="TEXT" size=5 NAME="<%=LucrareProgramataConstants.JSP.ENERGIE_NELIVR%>"
                       VALUE="<%=AppConstants.format2( bean.getEnergieNelivrata())%>"> kWh

                <span id="butonulBrowse">
                    &nbsp;&nbsp;
                    <input type="button" title="Selectati instalatiile afectate de lucrare" onclick="openBrowseInstalatii()"
                           value="Browse"/>

                    <span id="nrInstalatiiSpan"><%=bean.getInstalatiiAfectate() != null && bean.getInstalatiiAfectate().size() > 0 ? String.valueOf(bean.getInstalatiiAfectate().size()) : "fara" %></span>
                    instalatii selectate
                </span>

                <script type="text/javascript">

                    function getDate(inputId) {
                        var strDate = $(inputId).value;
                        if (strDate.length != 16) return null;
                        return Date.parseDate(strDate, "%d.%m.%Y %H:%M");
                    }

                    var browseFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,height=650,left=20,top=10,width=1000";
                    function buildParamsForCheckPaPt() {
                        var statieId = -1;
                        try {
                            statieId = document.zaforma.<%=LucrareProgramataConstants.JSP.STATIE_ID%>.value;
                        } catch (ex) {
                        }

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

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

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


                        var durataTotalaIntr = getDurataTotalaIntrerupere();

                        var durataOre = Math.floor(durataTotalaIntr / 60);
                        var durataMinute = (durataTotalaIntr % 60);

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

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

                        var url = "<%=AppConstants.APP_NAME%>?action=openBrowseInstalatii&tipParent=LP&afterSaveAction=saveLfForLucrare" + buildParamsForCheckPaPt();
                        _browseLFSearch = window.open(url, '', browseFeatures);
                    }
                </script>
            </TD>
        </TR>

        <TR>
            <TD vAlign=top><B>9.</B> Descriere lucrare:</TD>
            <TD>
                <TEXTAREA name=<%=LucrareProgramataConstants.JSP.DESCRIERE%> rows=3 cols=65><%=StringUtils.getNullSafe(bean.getDescriereLucrare())%></TEXTAREA>
            </TD>
        </TR>

        <TR>
            <TD><B>10.</B> Nr. utilizatori intrerupti:</TD>
            <TD>
                <TABLE class=gSAPTHEAD cellSpacing=1 width="100%">
                    <TBODY>
                    <TR class=gSAPGroup align=middle>
                        <TD>Inalta(IT)</TD>
                        <TD>Medie(MT)</TD>
                        <TD>Joasa(JT)</TD>
                    </TR>
                    <TR>
                        <TD align=middle>
                            <INPUT class=gsapinputtext style="TEXT-ALIGN: right"
                                   id="<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>"
                                   name="<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>"
                                   value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.UTILIZATORI_IT)%>"
                                   onfocus="notifyUser()"
                                   onkeyup="updateTotalConsumatori()"
                                    />
                        </TD>
                        <TD align=middle>
                            <INPUT class=gsapinputtext style="TEXT-ALIGN: right"
                                   id="<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>"
                                   name="<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>"
                                   value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.UTILIZATORI_MT)%>"
                                   onkeyup="updateTotalConsumatori()"
                                   onfocus="notifyUser()"
                                   onkeyup="updateTotalConsumatori()"
                                    />
                        </TD>
                        <TD align=middle>
                            <INPUT class=gsapinputtext style="TEXT-ALIGN: right"
                                   id="<%=LucrareProgramataConstants.JSP.UTILIZATORI_JT%>"
                                   name="<%=LucrareProgramataConstants.JSP.UTILIZATORI_JT%>"
                                   value="<%=binder.getPropertyValue( LucrareProgramataConstants.JSP.UTILIZATORI_JT)%>"
                                   onfocus="notifyUser()"
                                   onkeyup="updateTotalConsumatori()"
                                    />
                        </TD>
                    </TR>
                    <tr>
                        <%
                            final long totalUtilizatori =
                                    bean.getUtilizatoriIT() +
                                            bean.getUtilizatoriMT() +
                                            bean.getUtilizatoriJT();
                        %>
                        <td colspan="2" align="right">
                            <b>Total:</b>
                        </td>
                        <td align="center">
                            <input class=gsapinputtext
                                   type="text" readonly style="TEXT-ALIGN: right"
                                   value="<%=totalUtilizatori%>"
                                   name="<%=LucrareProgramataConstants.JSP.TOTAL_UTILIZATORI%>"
                                    />
                        </td>
                    </tr>
                    </TBODY>
                </TABLE>
            </TD>
        </TR>
        <TR>
            <TD vAlign=top><B>11.</B> Propuneri/Masuri finale:</TD>
            <TD>
                <TEXTAREA name=propuneri rows=3 cols=65><%=StringUtils.getNullSafe(bean.getPropuneri())%></TEXTAREA>
            </TD>
        </TR>

        <tr>
            <td><b>12.</b> Echipa de lucru</td>
            <td>
                <input type="radio" id="echipaLucruSISE" onClick="showSISEData()"
                       name="<%=LucrareProgramataConstants.JSP.TIP_ECHIPA%>"
                       value="<%=TipEchipaDeLucru.SISE%>" <%=TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.SISE) ? "checked" : ""%> /><label
                    for="echipaLucruSISE">SISE</label>
                <input type="radio" id="echipaLucruTERTI" onClick="showTERTIData()"
                       name="<%=LucrareProgramataConstants.JSP.TIP_ECHIPA%>"
                       value="<%=TipEchipaDeLucru.TERTI%>" <%=TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.TERTI) ? "checked" : ""%>  /><label
                    for="echipaLucruTERTI">Terti</label>
                <input type="radio" id="echipaLucruPersonalPr" onClick="showPersonalPropriuData()"
                       name="<%=LucrareProgramataConstants.JSP.TIP_ECHIPA%>"
                       value="<%=TipEchipaDeLucru.PERSONAL_PR%>" <%=TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.PERSONAL_PR) ? "checked" : ""%>  /><label
                    for="echipaLucruPersonalPr">Personal Propriu</label>

                <br/>
                <span id="dateSISE" style="display:none">Numele persoanei: </span>

                <span id="dateTERTI" style="display:none">Numele firmei: </span>

                <span id="datePersonalPr" style="display:none">Numele persoanei: </span>

                <span id="denEchipa" style="display:none">
                    <input type="text" size="50" class=gsapinputtext name="<%=LucrareProgramataConstants.JSP.DENUMIRE_ECHIPA%>"
                           value="<%=StringUtils.getNullSafe( bean.getEchipaDeLucruDen())%>"/>
                </span>

                <script type="text/javascript">
                    function showSISEData() {
                        Element.show("dateSISE");
                        Element.hide("dateTERTI");
                        Element.hide("datePersonalPr");
                        Element.show("denEchipa");
                    }

                    function showTERTIData() {
                        Element.hide("dateSISE");
                        Element.show("dateTERTI");
                        Element.hide("datePersonalPr");
                        Element.show("denEchipa");
                    }

                    function showPersonalPropriuData() {
                        Element.hide("dateSISE");
                        Element.hide("dateTERTI");
                        Element.show("datePersonalPr");
                        Element.show("denEchipa");
                    }

                    <% if( TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.SISE)){%>
                    showSISEData();
                    <% } %>

                    <% if( TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.TERTI)){%>
                    showTERTIData();
                    <% } %>

                    <% if( TipEchipaDeLucru.is(bean.getEchipaDeLucruTip(), TipEchipaDeLucru.PERSONAL_PR)){%>
                    showPersonalPropriuData();
                    <% } %>
                </script>
            </td>
        </tr>
        <TR>
            <TD colSpan=2><B>13.</B>
                Lucrarea a fost realizata de:
                <INPUT class=gsapinputtext size=40 value="<%=StringUtils.getNullSafe( bean.getRealizataDe())%>"
                       name="<%=LucrareProgramataConstants.JSP.REALIZAT_DE%>">. &nbsp;&nbsp;&nbsp;&nbsp;

                Conducatorul sub-unitatii de exploatare:
                <INPUT class=gsapinputtext size=40 value="<%=StringUtils.getNullSafe( bean.getConducatorUnitateExpl())%>"
                       name="<%=LucrareProgramataConstants.JSP.CONDUCATOR_SUBUNITATE%>">.
            </TD>
        </TR>
        <TR>
            <TD colSpan=2><B>14. </B>Lucrarea a fost receptionata de:
                <INPUT class=gsapinputtext size=40 value="<%=StringUtils.getNullSafe( bean.getReceptionatDe())%>"
                       name="<%=LucrareProgramataConstants.JSP.RECEPTIONATA_DE%>">. &nbsp;&nbsp;&nbsp;&nbsp;
                <%--Inspector incidente: <INPUT class=gsapinputtext size=40 value="<%=StringUtils.getNullSafe( bean.getInspectorIncidente())%>" name="<%=LucrareProgramataConstants.JSP.INSPECTOR_INCIDENTE%>">.--%>

                Admitent la lucrare:
                <INPUT class="gsapinputtext" TYPE="TEXT" title="nume + prenume" size=40
                       NAME="<%=LucrareProgramataConstants.JSP.ADMITENT_LUCRARE%>"
                       VALUE="<%=AppConstants.format( bean.getAdmitentLucrare())%>">

            </TD>
        </TR>

        <TR>
            <TD align="center" valign=top colspan="2">
                <input type="submit" value="Salvează"/> &nbsp;&nbsp;&nbsp;
                <input type="button" onclick="window.location = '<%=AppConstants.APP_NAME%>?action=renuntaEditLucrare'" value="Renunţă"/>
            </TD>
        </TR>
        </FORM>
        </table>


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

        <script type="text/javascript">
            var localitateDataProvider = new AjaxDataProvider(function () {
                return "<%=AppConstants.APP_NAME%>?action=suggest-localitate&<%=SugestConstants.SUGEST_Q_QUERY%>=";
            });

            var tipArteraDataProvider = new AjaxDataProvider(function () {
                return "<%=AppConstants.APP_NAME%>?action=suggest-tip-artera&<%=SugestConstants.SUGEST_Q_QUERY%>=";
            });

            function initAdreseSugests() {
                <% for( int i = 0; i < adrese.size(); i++) { %>
                new InputSugest($("<%=AdresaConstants.LOCALITATE + i%>"), $("<%=AdresaConstants.COD_LOCALITATE + i%>"), localitateDataProvider, {
                    isValidSearchInput: function () {
                        return this.txtBox.value.length >= 2;
                    },

                    onSelect: function (item) {
                        $("<%=AdresaConstants.LOCALITATE + i%>").value = item.localitate;
                        $("<%=AdresaConstants.JUDET + i%>").value = item.judet;
                        $("<%=AdresaConstants.COD_LOCALITATE2 + i%>").value = '';
                        $("<%=AdresaConstants.LOCALITATE2 + i%>").value = '';

                        $('<%=AdresaConstants.COD_STRADA + i%>').value ='';
                        $('<%=AdresaConstants.DEN_STRADA + i%>').value ='';
                        $('<%=AdresaConstants.TIP_ARTERA + i%>').value ='';


                        if( item.countCopii == 1 ){

                            //completam denumirea si codul localitatii daca este doar una singura
                            $("<%=AdresaConstants.LOCALITATE2 + i%>").value = item.denCopil;
                            $("<%=AdresaConstants.COD_LOCALITATE2 + i%>").value = item.codCopil;

                            //setam focusul direct pe strada
                            $("<%=AdresaConstants.COD_STRADA + i%>").value = '';
                            $("<%=AdresaConstants.DEN_STRADA + i%>").value = '';
                            $("<%=AdresaConstants.DEN_STRADA + i%>").focus();

                        } else if (item.countCopii == 0){
                            //setam focusul direct pe strada
                            $("<%=AdresaConstants.COD_STRADA + i%>").value = '';
                            $("<%=AdresaConstants.DEN_STRADA + i%>").value = '';
                            $("<%=AdresaConstants.DEN_STRADA + i%>").focus();
                        }else{
                            $("<%=AdresaConstants.LOCALITATE2 + i%>").focus();
                        }
                    },

                    beforeRequest: function () {
                        $("<%=AdresaConstants.COD_LOCALITATE2 + i%>").value = '';
                        $("<%=AdresaConstants.LOCALITATE2 + i%>").value = '';
                        $("<%=AdresaConstants.JUDET + i%>").value = '';
                    }
                });

                var l2dp<%=i%> = new AjaxDataProvider(function () {
                    return "<%=AppConstants.APP_NAME%>?action=suggest-localitate2"
                            +"&mun=" + $("<%=AdresaConstants.LOCALITATE + i%>").value
                            +"&codMun=" + $("<%=AdresaConstants.COD_LOCALITATE + i%>").value
                            + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
                });

                new InputSugest($("<%=AdresaConstants.LOCALITATE2 + i%>"), $("<%=AdresaConstants.COD_LOCALITATE2 + i%>"), l2dp<%=i%>, {
                    isValidSearchInput: function () {
                        return true;
                        //return this.txtBox.value.length >= 2;
                    },

                    onSelect: function (item) {
                        $("<%=AdresaConstants.LOCALITATE + i%>").value = item.localitate;
                        $("<%=AdresaConstants.LOCALITATE2 + i%>").value = item.localitate2;
                        $("<%=AdresaConstants.JUDET + i%>").value = item.judet;

                        $("<%=AdresaConstants.DEN_STRADA + i%>").value = '';
                        $("<%=AdresaConstants.DEN_STRADA + i%>").focus();
                    },

                    beforeRequest: function () {
                        $("<%=AdresaConstants.JUDET + i%>").value = '';
                    }
                });

                new InputSugest($("<%=AdresaConstants.TIP_ARTERA + i%>"), $(), tipArteraDataProvider, {
                    isValidSearchInput: function () {
                        return true;
                    },

                    onSelect: function (item) {
                        <%--alert($('<%=AdresaConstants.DEN_STRADA + i%>').value);--%>
                        $('<%=AdresaConstants.DEN_STRADA + i%>').value ='';
                        $('<%=AdresaConstants.DEN_STRADA + i%>').focus();
                    },

                    beforeRequest: function () {
                    }
                });

                new InputSugest($("<%=AdresaConstants.DEN_STRADA + i%>"), $("<%=AdresaConstants.COD_STRADA + i%>"),
                        new AjaxDataProvider(function () {
                            var codMun = $('<%=AdresaConstants.COD_LOCALITATE + i%>').value;
                            var mun = $('<%=AdresaConstants.LOCALITATE + i%>').value;
                            var codLoc = $('<%=AdresaConstants.COD_LOCALITATE2 + i%>').value;
                            var loc = $('<%=AdresaConstants.LOCALITATE2 + i%>').value;
                            var tipArtera = $('<%=AdresaConstants.TIP_ARTERA + i%>').value;

                            if( mun != null  && mun.trim().length > 0)
                                return "<%=AppConstants.APP_NAME%>?action=suggest-artera"
                                        + "&codLocalitate=" + codMun
                                        + "&localitate=" + mun
                                        + "&codLocalitate2=" + codLoc
                                        + "&localitate2=" + loc
                                        + "&tipArtera=" + tipArtera
                                        + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";
                            else return null;

                            <%--return "<%=AppConstants.APP_NAME%>?action=suggest-artera&localitate=" + $("<%=AdresaConstants.LOCALITATE + i%>").value +  "&localitate2=" + $("<%=AdresaConstants.LOCALITATE2 + i%>").value +--%>
                            <%--"&tipArtera=" + $("<%=AdresaConstants.TIP_ARTERA + i%>").value + "&<%=SugestConstants.SUGEST_Q_QUERY%>=";--%>
                        }),
                        {
                            isValidSearchInput: function () {
                                //return this.txtBox.value.length >= 2;
                                return true;
                            },

                            onSelect: function (item) {
                                $("<%=AdresaConstants.TIP_ARTERA + i%>").value = item.tipArtera;
                                $("<%=AdresaConstants.DEN_STRADA + i%>").value = item.denArtera;
                            },

                            beforeRequest: function () {
                            }
                        });

                <% }%>
            }

            setTimeout("initAdreseSugests()", 500);

            function onSubmit() {
                try {
                    if ($("nt_mt").checked || $("nt_it").checked) {
                        var energie = parseFloat(document.zaforma.<%=LucrareProgramataConstants.JSP.ENERGIE_NELIVR%>.value);

                        var deVerificat = "";
                        if (isNaN(energie) || energie <= 0) {
                            deVerificat += "   - Energia nelivrata trebuie sa fie completata";
                        }

                        if (deVerificat.length > 0) {
                            return confirm(
                                    "Atentie! Va rugam sa verificati urmatoarele campuri : \n\n" +
                                            deVerificat +
                                            "\n\nContinuati operatiunea ?"
                            );
                        }
                    }

                    return true;
                } catch (e) {
                    alert("Eroare js la salvare date: " + e.message);
                    return false;
                }
            }

            var hasInstalatiiSelected = <%=bean.hasInstalatiiAfectateSelectate()%>;

            function notifyUser() {
                if (hasInstalatiiSelected) {

                    alert('Ati selectat instalatii in fereastra Browse. Nu puteti completa manual numarul de consumatori');
                    //todo here
        //            alert(jQuery("#utilizatoriJt"));
        //
        //            jQuery("#utilizatoriJt").attr("disabled", true);
        //            jQuery("#utilizatoriMt").attr("disabled", true);
        //            jQuery("#utilizatoriIt").attr("disabled", true);

                }
            }

            function updateTotalConsumatori() {
                var sIT = document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>.value;
                var sJT = document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_JT%>.value;
                var sMT = document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>.value;

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

            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();

            }

            /*
             apelata din browse
             */
            function setTotalEnergieNelivrata(energie, enable) {
                document.zaforma.<%=LucrareProgramataConstants.JSP.ENERGIE_NELIVR%>.value = energie;
                document.zaforma.<%=LucrareProgramataConstants.JSP.ENERGIE_NELIVR%>.readOnly = !enable;
            }

            /*
             apelata din browse
             */
            function setTotalconsumatori(nr) {
                document.zaforma.<%=LucrareProgramataConstants.JSP.TOTAL_UTILIZATORI%>.value = nr;
            }

            /*
             apeldata din browse
             */
            function setConsumatoriPeNivelTensiune(nrConsIT, nrConsMT, nrConsJT, nrLfSelected) {
                document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_IT%>.value = nrConsIT;
                document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_MT%>.value = nrConsMT;
                document.zaforma.<%=LucrareProgramataConstants.JSP.UTILIZATORI_JT%>.value = nrConsJT;

                try {
                    hasInstalatiiSelected = nrLfSelected > 0;
                    $("nrInstalatiiSpan").innerHTML = nrLfSelected == 0 ? "fara" : "" + nrLfSelected;
                } catch (e) {
                    alert(e.message)
                }
            }

            function onChangeSelect(oSelect) {
            }

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

            function tensiuniValide() {
                var txt = document.zaforma.<%=LucrareProgramataConstants.JSP.TENSIUNE%>.value;
                var tensiuni = txt.split("/");
                if (tensiuni == null || tensiuni.length != 3) return false;

                var t1 = tensiuni[0];
                var t2 = tensiuni[1];
                var t3 = tensiuni[2];
                return ( t1.isInt() && t2.isInt() && t3.isInt() && (( 1 * t1 > 0) || ( 1 * t2 > 0) || (1 * t3 > 0)));
            }


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

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

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


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

            function adaugaAdreseMultiple() {
                browseGEO();
            }

            var browseGEOWindow = null;
            function browseGEO() {
                if (browseGEOWindow != null) browseGEOWindow.close();
                browseGEOWindow = window.open('<%=AppConstants.APP_NAME%>?action=browseGeo&m=<%=BrowseAdresaAction.MODE_CHECK%>&<%=BrowseAdresaAction.P_JSCBF%>=onAdreseSelected()'
                        , 'browseGeo', 'top=50,left=50,width=600 height=500,scrollbars=yes, status=yes,resizable=yes,dependent=yes,alwaysRaised=yes');
            }

            function onAdreseSelected() {
                document.zaforma.action = "<%=AppConstants.APP_NAME%>?action=addAdreseLucrare";
                document.zaforma.submit();
            }

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

            showNivelTensiuneFields();

            calculeazaDurataProgramata();
            calculeazaDurataRealizare();
            calculeazaDurataIntrerupere();


            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("#" + "<%=LucrareProgramataConstants.JSP.STATIE_DEN%>");
                var linieInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.LINIE_DEN%>");
                var paptInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.PAPT_DEN%>");
                var bobinaInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.BOBINA_DEN%>");
                var celulaInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.CELULA_DEN%>");
                var baraInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.BARA_DEN%>");
                var derivatieInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.DERIVATIE_DEN%>");
                var trafoInput = jQuery("#" + "<%=LucrareProgramataConstants.JSP.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");
                    }
                }
            }


        /* 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 = $("<%=LucrareProgramataConstants.JSP.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 parentId = $("<%=LucrareProgramataConstants.JSP.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 = $("<%=LucrareProgramataConstants.JSP.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 = $("<%=LucrareProgramataConstants.JSP.LINIE_ID%>").value;

            var parentStatieId = $("<%=LucrareProgramataConstants.JSP.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 initSuggestsLocalizareLucrareProgramata() {
            new InputSugest($("<%=LucrareProgramataConstants.JSP.STATIE_DEN%>"), $("<%=LucrareProgramataConstants.JSP.STATIE_ID%>"), statiiDataProvider, {
                isValidSearchInput: function () {
                    return true;
                },

                beforeRequest: function () {

                    $("<%=LucrareProgramataConstants.JSP.STATIE_COD%>").value = '';

                },
                onSelect: function (item) {

                    // clear bobine, linii, posturi, derivatii

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

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

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

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

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

            });

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

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

                },

                onSelect: function (item) {

                    $("<%=LucrareProgramataConstants.JSP.BOBINA_COD%>").value = item.cod;

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

                }
            });

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

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

                },

                onSelect: function (item) {
                    $("<%=LucrareProgramataConstants.JSP.CELULA_COD%>").value = item.cod;
                }
            });

            new InputSugest($("<%=LucrareProgramataConstants.JSP.BARA_DEN%>"), $("<%=LucrareProgramataConstants.JSP.BARA_ID%>"), bareDataProvider, {
                isValidSearchInput: function () {
                    return true;
                },

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

                },

                onSelect: function (item) {
                    $("<%=LucrareProgramataConstants.JSP.BARA_COD%>").value = item.cod;
                }
            });

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

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

                },

                onSelect: function (item) {

                    $("<%=LucrareProgramataConstants.JSP.LINIE_COD%>").value = item.cod;

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

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

                }
            });


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

                beforeRequest: function () {
                    $("<%=LucrareProgramataConstants.JSP.DERIVATIE_COD%>").value = '';

                },

                onSelect: function (item) {

                    $("<%=LucrareProgramataConstants.JSP.DERIVATIE_COD%>").value = item.cod;

                    $('<%=LucrareProgramataConstants.JSP.LINIE_ID%>').value = item.idInstalatieParent;
                    $('<%=LucrareProgramataConstants.JSP.LINIE_DEN%>').value = item.descInstalatieParent;


                }
            });

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

                beforeRequest: function () {
                    $("<%=LucrareProgramataConstants.JSP.PAPT_COD%>").value = '';
                },

                onSelect: function (item) {
                    $("<%=LucrareProgramataConstants.JSP.PAPT_COD%>").value = item.cod;
                }
            });

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

                beforeRequest: function () {
                    $("<%=LucrareProgramataConstants.JSP.TRAFO_COD%>").value = '';
                },

                onSelect: function (item) {
                    $("<%=LucrareProgramataConstants.JSP.TRAFO_COD%>").value = item.cod;
                }
            });
            new InputSugest($("<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>"), $("<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>_ID"), paptDataProvider, {
                isValidSearchInput: function () {
                    return true;
                },

                beforeRequest: function () {
                    $("<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>_COD").value = '';
                },

                onSelect: function (item) {
                    $("<%=LucrareProgramataConstants.JSP.DENUMIRE_INSTALATIE%>_COD").value = item.cod;
                }
            });


        }
        setTimeout(initSuggestsLocalizareLucrareProgramata, 1000);


        </script>

    </jsp:attribute>
</emid:template-lp>
