<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.constants.RoleConstants" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.sql.Timestamp" %>
<%@ page import="ro.emid.common.types.Nomenclator" %>
<%@ page import="ro.emid.common.db.NomAccessDB" %>
<%@ page import="ro.emid.common.constants.NomConstants" %>
<%@ page import="ro.emid.callcenter.obj.*" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>


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

<% if (request.getAttribute("act") !=null) {%>
<script type="text/javascript">
    try{
        opener.reloadListaLucrariProgramate();
    }catch( e){
    }
    window.close();
</script>
<%}else{%>

<%
    final FiltruLucrariProgramate filtru = CallcenterSessionUtils.getFiltruLucrariProgramate( session);
    
    final Timestamp dataStart = filtru.getDataStart();
    final Timestamp dataStop  = filtru.getDataStop();

    final boolean perioadaChecked = filtru.isPerioadaChecked();
    final String value_data_start = AppConstants.format(dataStart);
    final String value_data_stop = AppConstants.format(dataStop);

//    final int stareInLucru = filtru.getStare();
    final boolean stareInLucru = filtru.isStareInLucru();
    final boolean stareIncheiate = filtru.isStareIncheiate();
    final boolean stareProgramate = filtru.isStareProgramate();

    final String numarIncident   = filtru.getNumarLucrare() > 0 ? String.valueOf(filtru.getNumarLucrare()) : "";
    final String numarReclamatie = filtru.getNumarReclamatie() > 0 ? String.valueOf(filtru.getNumarReclamatie()) : "";
%>

<style type="text/css">
    legend{
        font-weight: bold;
    }
</style>

<TABLE class="gsapthead" align=center border=0 cellPadding=10 cellSpacing=0 width="100%">
    <TBODY>
        <TR>
            <TD>
                <TABLE align=center border=0 cellPadding=1 cellSpacing=0 width="100%" class="gsaptd">
                    <FORM NAME="zaforma" ACTION="<%=GlobalAppConstants.APP_NAME%>" METHOD=POST style="margin: 0">
                        <INPUT TYPE="hidden" NAME="action" VALUE="adaugaFiltruLucrariProgramate" />
                        <TBODY>
                            <TR>
                                <TD colspan="2">
                                    <CENTER><h3>Configurare FILTRU Lucrari programate</h3></CENTER>
                                </TD>
                            </TR>
                            <tr>
                                <td>
                                    <fieldset>
                                        <legend><input VALUE="1" type="checkbox" name="perioada_checked" id="perioada_checked" onclick="enableDateInputs( this)" <%=perioadaChecked ? "checked" : ""%> > <label for="perioada_checked">Perioada</label></legend>
                                        &nbsp;&nbsp;<input type="text" id="data_start" name="data_start" size="14" value="<%=value_data_start%>" <%=perioadaChecked ? "" : "disabled"%>  /> <a href="#" id="trigger_data_start" ><img src="<%=AppConstants.WEB_RESOURCE_PATH%>/images/cal.gif" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a> -
                                        <input type="text" id="data_stop" name="data_stop" size="14" value="<%=value_data_stop%>" <%=perioadaChecked ? "" : "disabled"%> /> <a href="#"  id="trigger_data_stop" ><img src="<%=AppConstants.WEB_RESOURCE_PATH%>/images/cal.gif" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>
                                    </fieldset>

                                    <script type="text/javascript">
                                        function enableDateInputs( check){
                                            $("data_start").disabled = !check.checked;
                                            $("data_stop").disabled = !check.checked;

                                            if( check.checked){
                                                $("trigger_data_start").style.visibility = '';
                                                $("trigger_data_stop").style.visibility = '';
                                            }else{
                                                $("trigger_data_start").style.visibility = 'hidden';
                                                $("trigger_data_stop").style.visibility = 'hidden';
                                            }
                                        }
                                    </script>

                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <fieldset>
                                        <legend>Starea lucrarilor ce vor fi afisate</legend>
                                        <input type="checkbox" name="stareInLucru" id="inLucru" <%=stareInLucru ? "checked" : "" %>  value="1"> <label for="inLucru">In Lucru</label>
                                        <input type="checkbox" name="stareIncheiata" id="incheiate" <%=stareIncheiate ? "checked" : "" %>  value="1"> <label for="incheiate">Incheiata</label>
                                        <input type="checkbox" name="stareProgramata" id="programate" <%=stareProgramate ? "checked" : "" %>  value="1"> <label for="programate">Programate</label>

                                        <%--<input type="checkbox" name="fd_status_rezolvate" id="rezolvare" <%=showRezolvate ? "checked" : "" %>  value="1"> <label for="rezolvare">Rezolvate</label>--%>

                                        <%--<input type="radio" name="stare" id="inLucru" <%=stare == 1 ? "checked" : "" %>  value="1"> <label for="inLucru">In Lucru</label>--%>
                                        <%--<input type="radio" name="stare" id="rezolvare" <%=stare == 2 ? "checked" : "" %>  value="2"> <label for="rezolvare">Rezolvate</label>--%>
                                        <%--<input type="radio" name="stare" id="toate" <%=stare == 3 ? "checked" : "" %>  value="3"> <label for="toate">Toate</label>--%>
                                    </fieldset>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <fieldset>
                                        Numar Lucrare: <input name="numar_lucrare" class="gsapinputtext" value="<%=numarIncident%>" /> &nbsp;&nbsp;&nbsp;
                                        Numar Reclamatie: <input name="numar_reclamatie" class="gsapinputtext" value="<%=numarReclamatie%>" />
                                    </fieldset>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center">
                                    <input type="button" value="Aplica filtru" onclick="this.form.submit()">&nbsp;&nbsp;
                                    <input type="button" onClick="resetFiltru()" value="Reset">&nbsp;&nbsp;
                                    <input type="button" value="Inchide" onclick="window.close()">
                                </td>
                            </tr>
                        </TBODY>
                    </FORM>
                </TABLE>
            </TD>
        </TR>
    </TBODY>
</TABLE>


<script type="text/javascript">
    function resetFiltru(){
        var elements = Form.getElements(document.zaforma);
        for( var i = 0; i < elements.length; i++){
            var el = elements[i];
            if( el.type == "checkbox") el.checked =  false;
            else if( el.type == "text") el.value = "";
            else if( el.type == "radio") el.checked = false;
        }

        var selects = document.zaforma.getElementsByTagName("select");
        for( var i = 0; i < selects.length; i++){
            var selectu = selects[i];
            selectu.selectedIndex = 0;
        }
    }

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

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

  enableDateInputs($("perioada_checked"));  

</script>
<%}%>