<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.types.DataObj" %>
<%@ page import="ro.emid.common.db.DataDB" %>
<%@ page import="ro.emid.common.constants.NomConstants" %>
<%@ page import="ro.emid.incidente.IncidenteSessionUtils" %>
<%@ page import="ro.emid.common.types.Category" %>
<%@ page import="ro.emid.common.utils.Util" %>
<%
    final int tipNom = ObjectUtils.getIntValue(request.getParameter("tipNom"), -1);
    final String codParent = ObjectUtils.getStringValue(request.getParameter("codParent")).trim();
    final String codSapCE = ObjectUtils.getStringValue(request.getParameter("codSapCE")).trim();
    final int nrOfParent = ObjectUtils.getIntValue(request.getParameter("nrOfParent"), 1);
    final DataObj[] datas;
    final boolean printVersion = ObjectUtils.getStringValue(request.getParameter("printVersion")).equals("true");

    if (nrOfParent == 1) {
        final Category filiala = IncidenteSessionUtils.getFiliala(session);
        final Category sucursala = IncidenteSessionUtils.getSucursala(session);
        final Category centru = IncidenteSessionUtils.getCentru(session);
        if( filiala.isMunteniaSud() && centru.isCentruPRAM()){   //show all LF from Sucursala
            datas = DataDB.getAllByCodSucursala(sucursala.getCodSap(), tipNom, "");
        }else{
            datas = DataDB.getAllByCodCe(codParent, tipNom, "");
        }
    } else if ("-1".equals(codParent)) {    //cand Statia este pe "Selectati:"
        datas = DataDB.getAllEQByCodCEOrfane(codSapCE, tipNom);
    } else if( -2 == nrOfParent ){
        datas = DataDB.getAllByCodCe( codSapCE, tipNom, "");
    } else {
        datas = DataDB.getAllEQByCodLocFunctional(codParent, tipNom);
    }


    final long selectedValue = ObjectUtils.getLongValue(request.getParameter("selectedValue"), -1);


    final String selectName = ObjectUtils.getStringValue(request.getParameter("selectName"));

%>
<respmesg>
    <% if (tipNom == NomConstants.NOM_STATII){%>
        <select name="<%=selectName%>" class="gSAPSelect" onchange="on_statie_changed()" <%=printVersion?"disabled":""%> >
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showDataOptionsValueIsId( out, datas, selectedValue, false); %>
        </select>

        <select name="<%=selectName%>h" class="gSAPSelect" style="display: none">
            <OPTION value="-1">Selectati:</OPTION>
            <%    Util.showDataOptionsValueIsCod(out, datas);%>
        </select>
    <% }else if(tipNom == NomConstants.NOM_LINII){%>
        <select name="<%=selectName%>" class="gSAPSelect" onchange="on_linie_changed();" <%=printVersion?"disabled":""%> >
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showDataOptionsValueIsId( out, datas, selectedValue, false); %>
        </select>

        <select name="<%=selectName%>h" class="gSAPSelect" style="display: none">
            <OPTION value="-1">Selectati:</OPTION>
            <%    Util.showDataOptionsValueIsCod( out, datas);%>
        </select>
    <% }else {%>
        <select name="<%=selectName%>" class="gSAPSelect" <%=printVersion?"disabled":""%> onchange="onChangeSelect( this)">
            <OPTION value="-1">Selectati:</OPTION>
            <% Util.showDataOptionsValueIsId( out, datas, selectedValue, false); %>
        </select>
    <% }%>
</respmesg>
