<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.types.Fisa" %>
<%@ page import="ro.emid.common.types.Instalatie" %>
<%@ page import="ro.emid.common.types.TipInstalatie" %>
<%@ page import="ro.emid.common.utils.BrowseController" %>
<%@ page import="ro.emid.common.utils.BrowseData" %>
<%@ page import="ro.emid.common.utils.StringUtils" %>
<%@ page import="java.util.List" %>

<%@include file="../../../layout/includes-emid.jspf"%>

<%
    //variabile care intervin in luarea deciziei "Ce nivel se afiseaza ?" sunt:
    // sucursala, statia, linia, showNivel
    //raspunsuri posibile:
    //      Linie -> Post
    //      Statie -> Linie -> Post
    //      Sucursala -> Statie -> Linie -> Post

    final BrowseData data = BrowseController.getBrowseData(session);
    final Fisa fisa = BrowseController.getBrowseFisa( session);

    final List editList = BrowseController.getListaInstalatiiSelectate( session);

    final String mesajEroare = "";
%>

<style type="text/css">

    html,body{
        background-color: #ffffff !important;
    }

    .sucursala{
        color: black;
    }

    .statie{
        color: #000099;
    }

    .linie{
        color:#990000;
    }

    .linie label{
        margin-right: 10px;
    }

    .deleted{
        text-decoration: line-through;
    }

    .linie td{
        padding-left: 20px;
    }

    .post{
        color:#339900;
    }

    .post td{
        padding-left: 40px;
    }

    /*.LFContainer{*/
        /*padding-left: 5px;*/
        /*background-color: white;*/
        /*border: 1px solid gray;*/
        /*overflow: auto;*/
        /*height: 480px*/
    /*}*/

    .childsContainer{
        padding-left:30px;
    }

    .highlitedLablel{
        background-color:#fefeaa;
    }

</style>

<script type="text/javascript">
    function createPlusForLinie( plusId, childsContinerId, codEmidLinie, codSapLinie){
        return new PlusDinamic( plusId, childsContinerId, {
                dataLoaded : false,
                loadUrl : "<%=AppConstants.APP_NAME%>?action=getPosturiForBrowse",
                requestParameters : "codEmidLinie="+codEmidLinie + "&codSapLinie="+codSapLinie,
                onDataLoaded : function ( originalRequest, plusObject){
                    var responseText  = getResponseMesg( originalRequest.responseText);
                    var result;

                    var oneDivFound = responseText.indexOf("div") >= 0;
                    responseText = responseText.trim();

                    if( oneDivFound){
                        result = PlusDinamicConstants.STATUS_MINUS;
                        injectPusturi( plusObject.plusForId, responseText);
                    }else if( responseText.length == 0){
                        result = PlusDinamicConstants.STATUS_HIDDEN;
                    }else{
                        result = PlusDinamicConstants.STATUS_MINUS;
                        $( plusObject.plusForId ).innerHTML = responseText;
                    }
                    return result;
                }
            });
    }

    function injectPusturi(containerId, htmlPosturi){
        $( containerId).innerHTML = htmlPosturi;
    }

    function injectLinii(containerId, arrLinii){
        var html = "";
        for( var i = 0; i < arrLinii.length; i++){
            html += "<div class='linie'>"+
                        "<span>"+
                            "<span id=\"plusLinie" + arrLinii[i].codSap + "\">&nbsp;</span>" +
                            "<input type=checkbox name=\"<%=BrowseData.COD_LF%>\" value=\""+ arrLinii[i].codSap + "\" " + (arrLinii[i].checked ? "checked" : "")  + "  />"+
                            "<label id=\"label" + arrLinii[i].codSap + "\"  class=\""+ (arrLinii[i].sters==true ? "deleted":"") + "\" onclick='highlightLabel( this); showDetaliiLF( \""+ arrLinii[i].codSap +"\")'>"+ arrLinii[i].denumire + "</label>"+
                            "[<a href=\"javascript: toggleSelectionOfChilds( '"+arrLinii[i].codSap + "')\" class=\"link\">Check all</a>]" +
                        "</span>"+
                        "<div id=\"posturiLinie" + arrLinii[i].codSap + "\" class=\"childsContainer\">"+
                        "</div>"+
                    "</div>";
        }
        $( containerId).innerHTML = html;

        for( i = 0; i < arrLinii.length; i++){
            createPlusForLinie( "plusLinie" + arrLinii[i].codSap, "posturiLinie"+arrLinii[i].codSap, arrLinii[i].codEmid, arrLinii[i].codSap);
        }
    }
</script>

<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="97%" style="background-color: #ffffff; margin: 5px;" >
    <TBODY>
        <%if( mesajEroare != null){%>
        <tr>
            <td><%=mesajEroare%></td>
        </tr>
        <%}%>
        <tr>
            <td align="left">
                <%if( data.getNivel() == BrowseData.NIVEL_LINIE){%>
                    [<a title="Afiseaza toate liniile" class="link" href="<%=AppConstants.APP_NAME%>?action=browseUp&nivelRequest=<%=BrowseData.NIVEL_STATIE%>" >up</a>]
                <%}else if( data.getNivel() == BrowseData.NIVEL_STATIE) {%>
                    [<a title="Afiseaza toate statiile" class="link" href="<%=AppConstants.APP_NAME%>?action=browseUp&nivelRequest=<%=BrowseData.NIVEL_SUCURSALA%>" >up</a>]
                <%}else if( data.getNivel() == BrowseData.NIVEL_SUCURSALA){%>

                <%}else{%>
                    nivel necunoscut "<%=data.getNivel()%>"
                <%}%>

                &nbsp;[<a title="Deselecteaza toate" class="link" href="javascript: void( null)" onclick="deselectAll()">deselect all</a>]
            </td>
        </tr>
        <TR valign="top">
            <TD>
                <form name="zaforma" action="<%=AppConstants.APP_NAME%>" method="post" style="margin:0">
                    <input name="action" type="hidden" value="saveInstalatiiAfectate" />
                    <input name="mode" type="hidden" value="tree" />

                    <div class="LFContainer">
                    <%if( data.getNivel() == BrowseData.NIVEL_LINIE){%>
                        <% final Instalatie linia = data.getLinia();%>
                        <div class="linie">
                            <span>
                                <span id="plusLinie"></span>
                                <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=linia.getCod()%>" <%=fisa.isLfChecked( linia.getCod()) ? "checked" : ""%>  />
                                <label id="label<%=linia.getCod()%>" class="<%=linia.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( linia.getCod())%>")' >
                                    <%=linia.getNume()%>
                                </label>
                                [<a href="javascript: toggleSelectionOfChilds( '<%=linia.getCod()%>')" class="link">Check all</a>]
                            </span>
                            <div id="posturiLinie" class="childsContainer">
                                <%  final Instalatie[] paptLinie = data.getProvider().getLFByParentCodEmid( linia.getTipProducator(), TipInstalatie.PA_PT, data.getFilterCondition());
                                    for (int i = 0; i < paptLinie.length; i++) {
                                        final Instalatie papt = paptLinie[i];%>
                                        <div class="post">
                                            <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=papt.getCod()%>" <%=fisa.isLfChecked( papt.getCod()) ? "checked" : ""%> codParent="<%=linia.getCod()%>" />
                                            <label id="label<%=papt.getCod()%>" class="<%=papt.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( papt.getCod())%>")' >
                                                <%=papt.getNume()%>
                                            </label>
                                            <% final long durataIntreruperePT = fisa.getDurataIntrerupereLF( papt.getCod()); %>
                                            <% final long oreToShow = durataIntreruperePT > 0 ? durataIntreruperePT/60 : data.getDurataParentOre();%>
                                            <% final long minuteToShow = durataIntreruperePT > 0 ? durataIntreruperePT%60 : data.getDurataParentMinute();%>
                                            <a class="link" id="linkDurataIntrerupere<%=papt.getCod()%>"  href="javascript: void( null)"  onclick=" editDurataIntrerupere( '<%=papt.getCod()%>'); return false;" title="Durata intrerupere. Click pentru editare"><%=oreToShow%>h <%=minuteToShow%>'</a>
                                            <span id="inputDurataIntrerupere<%=papt.getCod()%>" style="display: none">
                                                <nobr>
                                                    <input type="hidden" name="codSapParent<%=papt.getCod()%>" value="<%=linia.getCod()%>"/>
                                                    <input name="durataIntrerupereOre<%=papt.getCod()%>" id="inputOre<%=papt.getCod()%>" onkeypress="myonkeypress(event)" type="text" style="width:30px; text-align:right; " class="gsapinputtext" value="<%=oreToShow%>" />h&nbsp;
                                                    <input name="durataIntrerupereMinute<%=papt.getCod()%>" id="inputMinute<%=papt.getCod()%>" onkeypress="myonkeypress(event)"  type="text" style="width:30px; text-align:right;" class="gsapinputtext" value="<%=minuteToShow%>"  />'
                                                </nobr>
                                            </span>
                                        </div>
                                <%  }%>
                            </div>
                        </div>

                        <script type="text/javascript">
                            var plusLinie = new Plus( "plusLinie", "posturiLinie");
                            plusLinie.setMinus();
                        </script>
                    <%}else if( data.getNivel() == BrowseData.NIVEL_STATIE) {%>
                        <div class="statie">
                            <span>
                                <span id="plusStatie"></span>
                                <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=data.getStatia().getCod()%>" <%=fisa.isLfChecked( data.getStatia().getCod()) ? "checked" : ""%> />
                                <label id="label<%=data.getStatia().getCod()%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( data.getStatia().getCod())%>")' ><%=data.getStatia().getNume()%></label>

                            </span>
                            <div id="liniiStatie" class="childsContainer">
                                <%  Instalatie liniiStatie[] = new Instalatie[0];

                                    liniiStatie = data.getProvider().getLFByParentCodEmid(data.getStatia().getTipProducator(), TipInstalatie.LINIE, data.getFilterCondition());
                                    for (int i = 0; i < liniiStatie.length; i++) {
                                        final Instalatie linie = liniiStatie[i];%>
                                        <div class="linie">
                                            <span >
                                                <span id="plusLinie<%=i%>"></span>
                                                <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=linie.getCod()%>" <%=fisa.isLfChecked( linie.getCod()) ? "checked" : ""%>  />
                                                <label id="label<%=linie.getCod()%>" class="<%=linie.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( linie.getCod())%>")' ><%=linie.getNume()%></label>


                                                [<a href="javascript: toggleSelectionOfChilds( '<%=linie.getCod()%>')" class="link">Check all</a>]
                                            </span>

                                            <!-- Expandam linia selectata -->
                                            <%if( (data.getLinia() != null && data.getLinia().getId() == linie.getId()) || fisa.hasLfCopiiChecked(linie.getTipProducator(), linie.getCod())){%>
                                                <div id="posturiLinie<%=i%>" class="childsContainer">
                                                    <%  final String codEmidLinie = linie.getTipProducator(); %>
                                                    <%  final Instalatie[] paptLinie = data.getProvider().getLFByParentCodEmid(codEmidLinie, TipInstalatie.PA_PT, data.getFilterCondition());
                                                        for (int j = 0; j < paptLinie.length; j++) {
                                                            final Instalatie papt = paptLinie[ j];%>
                                                            <div class="post">
                                                                <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=papt.getCod()%>" <%=fisa.isLfChecked( papt.getCod()) ? "checked" : ""%> codParent="<%=linie.getCod()%>" />
                                                                <label id="label<%=papt.getCod()%>" class="<%=papt.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( papt.getCod())%>")' >
                                                                    <%=papt.getNume()%>
                                                                </label>
                                                                <% final long durataIntreruperePT = fisa.getDurataIntrerupereLF( papt.getCod()); %>
                                                                <% final long oreToShow = durataIntreruperePT > 0 ? durataIntreruperePT/60 : data.getDurataParentOre();%>
                                                                <% final long minuteToShow = durataIntreruperePT > 0 ? durataIntreruperePT%60 : data.getDurataParentMinute();%>
                                                                <a class="link" id="linkDurataIntrerupere<%=papt.getCod()%>"  href="javascript: void( null)"  onclick=" editDurataIntrerupere( '<%=papt.getCod()%>'); return false;" title="Durata intrerupere. Click pentru editare"><%=oreToShow%>h <%=minuteToShow%>'</a>
                                                                <span id="inputDurataIntrerupere<%=papt.getCod()%>" style="display: none">
                                                                    <nobr>
                                                                        <input type="hidden" name="codSapParent<%=papt.getCod()%>" value="<%=linie.getCod()%>"/>
                                                                        <input name="durataIntrerupereOre<%=papt.getCod()%>" id="inputOre<%=papt.getCod()%>" onkeypress="myonkeypress(event)" type="text" style="width:30px; text-align:right; " class="gsapinputtext" value="<%=oreToShow%>" />h&nbsp;
                                                                        <input name="durataIntrerupereMinute<%=papt.getCod()%>" id="inputMinute<%=papt.getCod()%>" onkeypress="myonkeypress(event)"  type="text" style="width:30px; text-align:right;" class="gsapinputtext" value="<%=minuteToShow%>"  />'
                                                                    </nobr>
                                                                </span>
                                                            </div>
                                                    <%  }%>
                                                </div>
                                                <script type="text/javascript">
                                                    var plusLinie = new Plus( "plusLinie<%=i%>", "posturiLinie<%=i%>");
                                                    plusLinie.setMinus();
                                                </script>
                                            <%}else{%>
                                                <div id="posturiLinie<%=i%>" class="childsContainer">
                                                </div>
                                                <script type="text/javascript">
                                                    var plusDinamic<%=i%> = createPlusForLinie( "plusLinie<%=i%>", "posturiLinie<%=i%>", "<%=ro.emid.common.utils.Util.escapeToJs( linie.getTipProducator())%>", "<%=ro.emid.common.utils.Util.escapeToJs( linie.getCod())%>");
                                                </script>
                                            <%}%>
                                        </div>
                                <%  }%>
                            </div>
                        </div>

                        <script type="text/javascript">
                            var plusStatie = new Plus( "plusStatie", "liniiStatie");
                            plusStatie.setMinus();
                        </script>
                    <%}else if( data.getNivel() == BrowseData.NIVEL_SUCURSALA){ %>
                        <div class="sucursala">
                            <span>
                                <span id="plusSucursala"></span><%=StringUtils.getNullSafe( data.getSucursala().getName(), "Statii")%>
                            </span>
                            <div id="statiiSucursala" class="childsContainer">

                                <% final List statiiSucursala = data.getProvider().getAllByType( TipInstalatie.STATIE, data.getFilterCondition());
                                   for (int i = 0; i < statiiSucursala.size(); i++) {
                                        final Instalatie statia = (Instalatie) statiiSucursala.get(i);%>
                                        <div class="statie">
                                            <span >
                                                <span id="plusStatie<%=i%>"></span>
                                                <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=statia.getCod()%>" <%=fisa.isLfChecked( statia.getCod()) ? "checked" : ""%>  />
                                                <label id="label<%=statia.getCod()%>" class="<%=statia.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( statia.getCod())%>")' ><%=statia.getNume()%></label>
                                            </span>

                                            <!-- Expandam statia selectata -->
                                            <% if( (data.getStatia() != null && data.getStatia().getId() == statia.getId()) || fisa.hasLfCopiiChecked( statia.getTipProducator())){ %>
                                                <div id="liniiStatie<%=i%>" class="childsContainer">
                                                    <%  final String codEmidStatie =  statia.getTipProducator(); %>
                                                    <%
                                                        Instalatie liniiStatie[] = new Instalatie[0];

                                                        liniiStatie = data.getProvider().getLFByParentCodEmid( codEmidStatie, TipInstalatie.LINIE, data.getFilterCondition());
                                                        for (int j = 0; j < liniiStatie.length; j++) {
                                                            final Instalatie linia = liniiStatie[ j];%>
                                                            <div class="linie">
                                                                <span>
                                                                    <span id="plusLinie<%=j%>"></span>
                                                                    <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=linia.getCod()%>" <%=fisa.isLfChecked( linia.getCod()) ? "checked" : ""%>  />
                                                                    <label id="label<%=linia.getCod()%>" class="<%=linia.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( linia.getCod())%>")' ><%=linia.getNume()%></label>

                                                                    [<a href="javascript: toggleSelectionOfChilds( '<%=linia.getCod()%>')" class="link">Check all</a>]
                                                                </span>

                                                                <!-- Expandam linia selectata -->
                                                                <%if( (data.getLinia() != null && data.getLinia().getId() == linia.getId()) || fisa.hasLfCopiiChecked(linia.getTipProducator(), linia.getCod())){%>
                                                                    <div id="posturiLinie<%=j%>" class="childsContainer">
                                                                        <%  final String codEmidLinie = linia.getCodEmid(); %>
                                                                        <%  final Instalatie[] paptLinie = data.getProvider().getLFByParentCodEmid(codEmidLinie, TipInstalatie.PA_PT, data.getFilterCondition());
                                                                            for (int k = 0; k < paptLinie.length; k++) {
                                                                                final Instalatie papt = paptLinie[ k];%>
                                                                                <div class="post">
                                                                                    <input type="checkbox" name="<%=BrowseData.COD_LF%>" value="<%=papt.getCod()%>" <%=fisa.isLfChecked( papt.getCod()) ? "checked" : ""%> codParent="<%=linia.getCod()%>"/>
                                                                                    <label id="label<%=papt.getCod()%>" class="<%=papt.esteSters()?"deleted":""%>" onclick='highlightLabel( this); showDetaliiLF( "<%=ro.emid.common.utils.Util.escapeToJs( papt.getCod())%>")' >
                                                                                        <%=papt.getNume()%>
                                                                                    </label>
                                                                                    <% final long durataIntreruperePT = fisa.getDurataIntrerupereLF( papt.getCod()); %>
                                                                                    <% final long oreToShow = durataIntreruperePT > 0 ? durataIntreruperePT/60 : data.getDurataParentOre();%>
                                                                                    <% final long minuteToShow = durataIntreruperePT > 0 ? durataIntreruperePT%60 : data.getDurataParentMinute();%>
                                                                                    <a class="link" id="linkDurataIntrerupere<%=papt.getCod()%>"  href="javascript: void( null)"  onclick=" editDurataIntrerupere( '<%=papt.getCod()%>'); return false;" title="Durata intrerupere. Click pentru editare"><%=oreToShow%>h <%=minuteToShow%>'</a>
                                                                                    <span id="inputDurataIntrerupere<%=papt.getCod()%>" style="display: none">
                                                                                        <nobr>
                                                                                            <input type="hidden" name="codSapParent<%=papt.getCod()%>" value="<%=linia.getCod()%>"/>
                                                                                            <input name="durataIntrerupereOre<%=papt.getCod()%>" id="inputOre<%=papt.getCod()%>" onkeypress="myonkeypress(event)" type="text" style="width:30px; text-align:right; " class="gsapinputtext" value="<%=oreToShow%>" />h&nbsp;
                                                                                            <input name="durataIntrerupereMinute<%=papt.getCod()%>" id="inputMinute<%=papt.getCod()%>" onkeypress="myonkeypress(event)"  type="text" style="width:30px; text-align:right;" class="gsapinputtext" value="<%=minuteToShow%>"  />'
                                                                                        </nobr>
                                                                                    </span>
                                                                                </div>
                                                                        <%  }%>
                                                                    </div>

                                                                    <script type="text/javascript">
                                                                        var plusLinie<%=j%> = new Plus( "plusLinie<%=j%>", "posturiLinie<%=j%>");
                                                                        plusLinie<%=j%>.setMinus();
                                                                    </script>
                                                                <%}else{%>
                                                                    <div id="posturiLinie<%=j%>" class="childsContainer">

                                                                    </div>
                                                                    <script type="text/javascript">
                                                                        var plusDinamic<%=j%> = createPlusForLinie( "plusLinie<%=j%>", "posturiLinie<%=j%>",  "<%=ro.emid.common.utils.Util.escapeToJs( linia.getCodEmid())%>", "<%=ro.emid.common.utils.Util.escapeToJs( linia.getCod())%>");
                                                                    </script>
                                                                <%}%>
                                                            </div>
                                                    <%  }%>
                                                </div>
                                                <script type="text/javascript">
                                                    var plusStatie = new Plus( "plusStatie<%=i%>", "liniiStatie<%=i%>");
                                                    plusStatie.setMinus();
                                                </script>
                                            <%}else{%>
                                                <div id="liniiStatie<%=i%>" class="childsContainer">

                                                </div>

                                                <script type="text/javascript">
                                                    var plusDinamic<%=i%> = new PlusDinamic( "plusStatie<%=i%>", "liniiStatie<%=i%>", {
                                                        dataLoaded : false,
                                                        loadUrl : "<%=AppConstants.APP_NAME%>?action=getLiniiForBrowse",
                                                        requestParameters : "codEmidStatie=<%=statia.getCodEmid()%>",
                                                        onDataLoaded : function ( originalRequest, plusObject){
                                                            var responseText  = getResponseMesg( originalRequest.responseText);
                                                            var result;
                                                            var arrLinii = null;

                                                            try{
                                                                arrLinii = eval( responseText);
                                                            }catch(e){}

                                                            if( arrLinii == null){
                                                                $( plusObject.plusForId).innerHTML = responseText;
                                                                result = PlusDinamicConstants.STATUS_MINUS;
                                                            }else if( arrLinii.length == 0){
                                                                result = PlusDinamicConstants.STATUS_HIDDEN;
                                                            }else{
                                                                result = PlusDinamicConstants.STATUS_MINUS;
                                                                injectLinii( plusObject.plusForId, arrLinii);
                                                            }
                                                            return result;
                                                        }
                                                    });
                                                </script>
                                            <%}%>
                                        </div>
                                <% }%>
                            </div>
                        </div>

                        <script type="text/javascript">
                            var plusSucursala = new Plus("plusSucursala", "statiiSucursala");
                            plusSucursala.setMinus();
                        </script>
                    <%}else{%>
                        nivel necunoscut "<%=data.getNivel()%>"
                    <%}%>
                    </div>
                </form>
            </TD>
        </TR>
    </TBODY>
</TABLE>

<script type="text/javascript">

    function showDetaliiLF( codInstalatie){
       window.parent.BrowseWindow.showDetaliiInstalatie( codInstalatie, <%=data.getAn()%>);
    }

    var currentCodPt = null;
    function hideInputsDurataIntrerupere( codPT){
        if( codPT == null) return;

        var minute = getPositiveValue( $("inputOre"+codPT).value)*60+ getPositiveValue( $("inputMinute"+codPT).value);
        var ore = parseInt(""+(minute/60));
        minute = minute%60;
        $("linkDurataIntrerupere"+codPT).innerHTML = ore+"h "+minute+"'";

        Element.show("linkDurataIntrerupere"+codPT);
        Element.hide("inputDurataIntrerupere"+codPT);

        $("inputOre"+codPT).value = ore;
        $("inputMinute"+codPT).value = minute;
    }

    function getPositiveValue( str){
        var result = 0;
        try{
            if( str != null && str.length > 0 && !isNaN( str)){
                result = parseInt( str);

                if( result < 0) result = 0;
            }
        }catch(e){}
        return result;
    }

    function showInputsDurataIntrerupere( codPT){
        Element.hide("linkDurataIntrerupere"+codPT);
        Element.show("inputDurataIntrerupere"+codPT);
    }

    function editDurataIntrerupere( codPT){
        hideInputsDurataIntrerupere( currentCodPt);
        currentCodPt = codPT;
        showInputsDurataIntrerupere( currentCodPt);
        $("inputOre"+codPT).focus();
        $("inputOre"+codPT).select();
    }

    function myonkeypress(event){
        if( event.keyCode==13 || event.keyCode == 27){
            hideInputsDurataIntrerupere( currentCodPt);
            return false;
        }
        return true;
    }


    var currentHighlightedLabel = null;
    function highlightLabel( idLabel){
        unHighlightCurrentLabel();
        currentHighlightedLabel = $( idLabel);

        if( currentHighlightedLabel) {
            Element.addClassName(currentHighlightedLabel, "highlitedLablel");
            //currentHighlightedLabel.className = "highlitedLablel";
        }
    }

    function unHighlightCurrentLabel(){
        if( currentHighlightedLabel ){
            //currentHighlightedLabel.className = "";
            Element.removeClassName(currentHighlightedLabel, "highlitedLablel");
        }
    }


    function deselectAll(){
        var arrInputs = document.getElementsByTagName("input");
        if( arrInputs != null && arrInputs.length > 0){
            for( var i = 0; i < arrInputs.length; i++){
                if( arrInputs[i].type && arrInputs[i].type == "checkbox"){
                    arrInputs[i].checked = false;
                }
            }
        }
    }

    /**
     * link atasat unei liniii
     * @param linku
     */
    function toggleSelectionOfChilds( codLinie ){
        var checks = getChildCheckboxes( codLinie);
        var count = 0;
        for( var i = 0; i < checks.length;  i++){
            if (checks[ i].checked){ count = count + 1;}
            checks[ i].checked = true;
        }
        //uncheck
        if (count == checks.length){
            for( var i = 0; i < checks.length;  i++){
                checks[ i].checked = false;
            }
        }
    }

    function getChildCheckboxes( codParent){
        var arrInputs = document.getElementsByTagName("input");
        var result = [];
        if( arrInputs != null && arrInputs.length > 0){
            for( var i = 0; i < arrInputs.length; i++){
                var checku = arrInputs[i];
                var _codParent = checku.getAttribute("codParent");
                if( _codParent && checku.type && checku.type == "checkbox" && _codParent == codParent){
                    result.push( checku);
                }
            }
        }
        return result;
    }

    function save() {
        var nodes = document.getElementsByName('<%=BrowseData.COD_LF%>');

        var gosubmit  = true;

        var elem = [];
        for (var  i = 0; i < nodes.length; i++) {
            elem.push(nodes[i]);
        }

        var idx_all_selected = 0;

        while (idx_all_selected < elem.length) {

            var idx_verify_remained = idx_all_selected + 1;
            if (elem[idx_all_selected].checked == true) {
                while (idx_verify_remained < elem.length) {

                    if (elem[idx_verify_remained].checked == true) {

                        if (elem[idx_all_selected].value == elem[idx_verify_remained].value){
                            gosubmit = false;
                            alert('Elementul ' + document.getElementById('label' + elem[idx_all_selected].value).innerHTML + ' a fost selectat de mai multe ori. Va rugam selectati doar o singura data.')
                        }
                        idx_verify_remained++;
                    } else {
                        elem.splice(idx_verify_remained, 1);
                    }

                    //alert('2 idx_verify_remained :' + idx_verify_remained + '   list_size:' + elem.length );
                }
                idx_all_selected++;
            } else {
                elem.splice(idx_all_selected, 1);
            }

            //alert('1 idx_all_selected :' + idx_all_selected + '   list_size :' + elem.length);
        }
        if ( gosubmit == true){
            document.zaforma.submit();
        }
    }
</script>