<%@ page import="ro.emid.common.components.sugest.base.SugestConstants" %>
<%@ page import="ro.emid.common.constants.CriteriuFiltruIncidenteConstants" %>
<%@ page import="ro.emid.common.constants.IncidentConstants" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.db.NomAccessDB" %>
<%@ page import="ro.emid.common.types.CriteriuFiltruIncidente" %>
<%@ page import="ro.emid.common.types.Nomenclator" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="ro.emid.common.utils.Util" %>
<%@ page import="ro.emid.common.constants.NomConstants" %>

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

<%  Logger LOG = Logger.getLogger("editcriteriuFiltrareIncidente.jsp");

    CriteriuFiltruIncidente bean = (CriteriuFiltruIncidente) request.getAttribute( CriteriuFiltruIncidenteConstants.BEAN);
    if( bean == null) bean = new CriteriuFiltruIncidente();

    String codCe = centruExploatare.getCodSap();

    LOG.debug("CodCE :"+  codCe);


    if( request.getAttribute("act") != null){%>
    <script type="text/javascript">
        parent.refreshData();
    </script>
<%}else{%>


<form name="zaforma" action="<%=ro.emid.common.constants.AppConstants.APP_NAME%>" method="post" style="margin: 0">
<input type="hidden" name="action" value="saveCriteriuFiltrareIncidente" />
<input type="hidden" name="<%=CriteriuFiltruIncidenteConstants.INDEX%>" value="<%=bean.getIndex()%>" />
<input type="hidden" name="<%=IncidentConstants.SECTIE_ID%>" value="<%=centruExploatare.getId()%>">
<input type="hidden" name="<%=IncidentConstants.SECTIE_ID%>h" value="<%=centruExploatare.getCodSap()%>" codSapOriginal="<%=centruExploatare.getCodSap()%>">


<TABLE class="gsapthead" width="100%">
<tr >
    <td colspan="2">
        Afiseaza
        <select name="<%=CriteriuFiltruIncidenteConstants.INCLUSIV_EXCUSIV%>" class="gSAPSelect">
            <option value="<%=CriteriuFiltruIncidenteConstants.VALUE_INCLUSIV%>" <%=bean.getInclusivExclusiv() == CriteriuFiltruIncidenteConstants.VALUE_INCLUSIV ? "selected" : ""%> >Inclusiv</option>
            <option value="<%=CriteriuFiltruIncidenteConstants.VALUE_EXCLUSIV%>" <%=bean.getInclusivExclusiv() == CriteriuFiltruIncidenteConstants.VALUE_EXCLUSIV ? "selected" : ""%> >Exclusiv</option>
        </select>
        intrarile care au:
    </td>

</tr>
<TR class="gSAPGroup">
     <td nowrap>
         <%=sucursala.isCuSectiiSiCentre() ? "Centru exploatare" : "Formatia de lucru"%>:
     </td>
     <td nowrap>
         <span id="formatiaDiv">
            <select class="gSAPSelect"  name="<%=IncidentConstants.FORMATIA_DE_LUCRU_ID%>" onchange="onFormatieChanged()" >
                <option value="-1">Selectati:</option>
                <% final Category[] formatii = CategoryAccessDB.getAllCategoriesByParentId( centruExploatare.getId());
                    if (formatii != null) for (int i = 0; i < formatii.length; i++) {%>
                    <OPTION <%=(formatii[i].getId() == bean.getFormatiaId()) ? "selected=\"true\" " : ""%>value="<%=formatii[i].getId()%>"><%=formatii[i].getName()%></OPTION>
                <%} %>
            </select>
         </span>
     </td>
</tr>
<tr class="gSAPGroup">
    <TD nowrap>
        Ansamblu functional:
    </TD>
    <TD>
        <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>
    </TD>
</TR>

<TR class="gSAPGroup">

    <table border = 1 class="gsapthead" width="100%">
        <tr class="gSAPGroup">
    <TD>
        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">
        Bobina:
    </td>
    <td >
        <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>
        Celula:
    </TD>
    <TD>
        <input type="hidden" id="<%=IncidentConstants.CELULA_ID%>" name="<%=IncidentConstants.CELULA_ID%>"
               value="<%=bean.getCelulaId()%>"/>
        <input type="hidden" id="<%=IncidentConstants.CELULA_COD%>" name="<%=IncidentConstants.CELULA_COD%>"
               value="<%=AppConstants.format(bean.getCelulaCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.CELULA_DEN%>"
                       name="<%=IncidentConstants.CELULA_DEN%>" maxlength="200" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getCelulaDen())%>"/>
    </TD>
    <td nowrap="nowrap">
        Bara:
    </td>
    <td>
        <input type="hidden" id="<%=IncidentConstants.BARA_ID%>" name="<%=IncidentConstants.BARA_ID%>"
                value="<%=bean.getBaraId()%>"/>
        <input type="hidden" id="<%=IncidentConstants.BARA_COD%>" name="<%=IncidentConstants.BARA_COD%>"
               value="<%=AppConstants.format(bean.getBaraCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.BARA_DEN%>" name="<%=IncidentConstants.BARA_DEN%>"
                       maxlength="200" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getBaraDen())%>"/>
    </TD>
</TR>
<TR class="gSAPGroup">
    <TD>
        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">
       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>
        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>
        Trafo:
    </TD>
    <TD colspan="3">

         <input type="hidden" id="<%=IncidentConstants.TRAFO_ID%>" name="<%=IncidentConstants.TRAFO_ID%>"
                value="<%=bean.getTrafoId()%>"/>
        <input type="hidden" id="<%=IncidentConstants.TRAFO_COD%>" name="<%=IncidentConstants.TRAFO_COD%>"
               value="<%=AppConstants.format(bean.getTrafoCod())%>"/>
                <input class="gsapinputtext" id="<%=IncidentConstants.TRAFO_DEN%>"
                       name="<%=IncidentConstants.TRAFO_DEN%>" maxlength="100" style="width: 285px" sugestWidth="285"
                       value="<%=AppConstants.format(bean.getTrafoDen())%>"/>

    </TD>
</TR>
        </tr>
    </table>

<TR>
 <TD>
    Grupa:
 </TD>
<td>
    <% if ( IncidenteSessionUtils.isFiltruIncidente( session)){%>
        <SELECT name="<%=IncidentConstants.CAUZA_GR_ID%>" class="gSAPSelect" onChange="fill_cauze_select();">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showNomOptions(out, NomConstants.NOM_CAUZE_GRUPE, bean.getCauzaGrupaId()); %>
        </SELECT>
    <%}else if(IncidenteSessionUtils.isFiltruEchipamente( session)) {%>
        <SELECT name="<%=IncidentConstants.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>
    <%}%>
</td>
</TR>
<tr>
    <td>Cauza:</td>
    <td>
      <SELECT name="<%=IncidentConstants.CAUZA_ID%>" class="gSAPSelect" length=25>
          <option value="-1">Selectati:</option>
      </SELECT>
    </TD>
</TR>

<% if ( IncidenteSessionUtils.isFiltruIncidente( session)){%>
<tr>
    <td>Energia nelivrata</td>
    <td>
        <select name="en_op" class="gSAPSelect">
            <option value=""></option>
            <option value="=" <%="=".equals(bean.getEnOp()) ? "selected" : ""%> >=</option>
            <option value="&lt;"  <%="<".equals(bean.getEnOp()) ? "selected" : ""%> desc="mai mic">&lt;</option>
            <option value="&gt;"  <%=">".equals(bean.getEnOp()) ? "selected" : ""%> desc="mai mare">&gt;</option>
            <option value="&lt;=" <%="<=".equals(bean.getEnOp()) ? "selected" : ""%> desc="mai mic sau egal">&lt;=</option>
            <option value="&gt;=" <%=">=".equals(bean.getEnOp()) ? "selected" : ""%> desc="mai mare sau egal">&gt;=</option>
        </select>
        <input type="text" name="<%=IncidentConstants.ENERGIE_NELIVR%>" value="<%=ro.emid.common.utils.Util.isZeroLenght( bean.getEnOp()) ? "" : String.valueOf(bean.getEnergieNelivrata())%>" /> kWh
    </td>
</tr>

<tr>
    <td>Mod completare consumatori:</td>
    <td>
        <select name="<%=IncidentConstants.MOD_COMPLETARE_CONSUMATORI%>" class="gSAPSelect">
            <option value="-1">Selectati:</option>
            <option value="<%=IncidentConstants.ConsumatoriCompletati.AUTOMAT%>" <%=bean.getModCompletareConsumatori()==IncidentConstants.ConsumatoriCompletati.AUTOMAT?"selected":""%> >Automat</option>
            <option value="<%=IncidentConstants.ConsumatoriCompletati.MANUAL%>" <%=bean.getModCompletareConsumatori()==IncidentConstants.ConsumatoriCompletati.MANUAL?"selected":""%> >Manual</option>
        </select>
    </td>
</tr>
<tr>
    <td>Mediu:</td>
    <td>
        <select name="<%=IncidentConstants.MEDIU%>" class="gSAPSelect">
            <option value="-1">Selectati:</option>
            <option value="<%=IncidentConstants.Mediul.DIN_NOMENCLATOR%>" <%=bean.getMediul()==IncidentConstants.Mediul.DIN_NOMENCLATOR?"selected":""%> >Conform nomenclator</option>
            <option value="<%=IncidentConstants.Mediul.URBAN%>" <%=bean.getMediul()==IncidentConstants.Mediul.URBAN?"selected":""%> >Urban</option>
            <option value="<%=IncidentConstants.Mediul.RURAL%>" <%=bean.getMediul()==IncidentConstants.Mediul.RURAL?"selected":""%> >Rural</option>
        </select>
    </td>
</tr>
<%}%>

<tr>
    <td colspan="2" align="left">
        <input type="submit" value="<%=bean.getIndex() == -1 ? "Adauga" : "Modifica"%> Criteriu">&nbsp;&nbsp;
    </td>
</tr>
</table>
</form>

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


<script type="text/javascript">
    function on_ansamblu_changed(){
        enable_ansamble_selects();


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

        fillEqOrfane();
    }

    function onFormatieChanged(){
        <% if( sucursala.isCuSectiiSiCentre()){%>
            resetLocalizareSelects( true);
            setHiddenCodSectieIfIsC1_or_C2();
        <%}%>
    }

    function resetLocalizareSelects( disableLocalizareSelects, firstShow){
        if( firstShow){
            selectOption( document.zaforma.<%=IncidentConstants.ANSAMBLU_ID%>, <%=bean.getAnsambluId()%>);
        }else{
            document.zaforma.<%=IncidentConstants.ANSAMBLU_ID%>.selectedIndex = 0;
        }

        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.STATIE_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.BOBINA_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.CELULA_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.BARA_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.LINIE_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.DERIVATIE_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.PAPT_ID%>, disableLocalizareSelects);
        resetComboLeaveFirstOptionAndDisable( document.zaforma.<%=IncidentConstants.TRAFO_ID%>, disableLocalizareSelects);
    }

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

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



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

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

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

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

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

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

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


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


</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 parentId = $("<%=IncidentConstants.STATIE_ID%>").value;

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

var derivatiiDataProvider = new AjaxDataProvider(function () {

    // derivatie's parent is linie

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

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

var paptDataProvider = new AjaxDataProvider(function () {

    // papt's parent is linie

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

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

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

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

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

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

        onSelect: function (item) {

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

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

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

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

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

    });

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

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

        },

        onSelect: function (item) {
            $("<%=IncidentConstants.BOBINA_COD%>").value = item.cod;
            $('<%=IncidentConstants.STATIE_ID%>').value = item.idInstalatieParent;
            $('<%=IncidentConstants.STATIE_DEN%>').value = item.descInstalatieParent;

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

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

        },

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

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

        },

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

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

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

        },

        onSelect: function (item) {
            $("<%=IncidentConstants.LINIE_COD%>").value = item.cod;

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

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

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

        }
    });

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

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

        },

        onSelect: function (item) {

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


        }
    });

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

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

        },

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

        }
    });

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

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

        },

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

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


</script>