<%@ page title="Scheduled Changes Insert Update" language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="ManualControl_ScheduledChangesInsertUpdate, CardAccess.Web.UI_deploy" theme="Office2007Black" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script id="igClientScript" type="text/javascript">
        var neinputno;
        var inputno_oldvalue;

        function CheckAction(oToolbar, oButton, oEvent) {
            //Add code to handle your event here.
            if (oButton.getItem().get_text() == '<%=this.Cancel %>') {
            }
            else if (oButton.getItem().get_text() == '<%=this.Save %>') {
                var relID = document.getElementById("<%=txtDescription.ClientID %>");
                var desc = relID == null ? '' : relID.value.trim();

                var deFrom = $find("<%=deFrom.ClientID %>").get_value();
                deFrom = new Date(deFrom);

                var deTo = $find("<%=deTo.ClientID %>").get_value();
                deTo = new Date(deTo);

                var cboDeviceType = $find("<%= cboDeviceType.ClientID %>");
                var cboDeviceTypeValue = cboDeviceType.get_selectedItem().get_value();

                if (desc.length <= 0) {
                    alert("<%=this.Description %>");
                    oButton.set_cancel(true);
                }
                else if ($find("<%=deFrom.ClientID %>").get_text().length <= 0) {
                    alert("<%=this.DateFrom %>");
                    oButton.set_cancel(true);
                }
                else if ($find("<%=deTo.ClientID %>").get_text().length <= 0) {
                    alert("<%=this.DateTo  %>");
                    oButton.set_cancel(true);
                }
                else if (cboDeviceTypeValue == 0) {
                    alert("<%=this.NoDeviceNameIsSelected  %>");
                    oButton.set_cancel(true);
                }
                else if (deFrom.toString().length > 0 && deTo.toString().length > 0) {
                    var obj = {
                        fromDateDay: deFrom.getDate(),
                        fromDateMon: deFrom.getMonth(),
                        fromDateYear: deFrom.getFullYear(),
                        fromDateHour: deFrom.getHours(),
                        toDateDay: deTo.getDate(),
                        toDateMon: deTo.getMonth(),
                        toDateYear: deTo.getFullYear(),
                        toDateHour: deTo.getHours()
                    };
                    $.ajax({
                        type: "POST",
                        url: "ScheduledChangesInsertUpdate.aspx/CheckEffectiveDateRange",
                        data: JSON.stringify(obj),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: false,
                        success: function (msg) {
                            if (msg.d) {
                                oButton.set_cancel(true);
                                alert("<%=this.DateRangeMsg %>");
                            }
                        },
                        failure: function (msg) {
                            console.log("Failure: CheckEffectiveDateRange");
                        }
                    });
                }
            }
        }

        function sameDay(d1, d2) {
            return d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate();
        }

        function WebDatePicker_CalendarClosed(sender, e) {
            var newValue = e.get_value();

            if (newValue === undefined) return;

            var currntDate = new Date();
            var hour = currntDate.getHours();

            if (sameDay(new Date(newValue), new Date(currntDate.setHours(0, 0, 0, 0)))) {
                newValue.setHours(hour);
                e.set_value(newValue);
            }
        }

    </script>
    <div>
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td>
                    <asp:UpdatePanel ID="upConfigurationEditorToolBar" runat="server">
                        <ContentTemplate>
                            <AEL:ConfigurationEditorToolBar ID="ConfigurationEditorToolBar1" runat="server" OnCancel="editorToolbar_OnCancel"
                                OnSave="ConfigurationEditorToolBar1_OnSave" ClientSideEvent_Click="CheckAction">
                            </AEL:ConfigurationEditorToolBar>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:UpdatePanel ID="WebAsyncRefreshPanel1" runat="server">
                        <ContentTemplate>
                            <ig:WebTab ID="tbScheduledChanges" runat="server" SelectedTab="0" AsyncMode="Off"
                                Height="360px" Style="width: 100% !important; min-width: 100% !important;">
                                <Tabs>
                                    <ig:ContentTabItem Text="General">
                                        <Template>
                                            <table cellpadding="0" cellspacing="3" width="100%">
                                                <tr>
                                                    <td style="width: 120px; padding-left: 5px;">
                                                        <asp:Label ID="lblDescription" Text="Description" runat="server"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <ig:WebTextEditor ID="txtDescription" runat="server" Width="250">
                                                        </ig:WebTextEditor>
                                                    </td>
                                                </tr>
                                                <tr valign="top">
                                                    <td colspan="2">
                                                        <table cellpadding="1" cellspacing="2">
                                                            <tr>
                                                                <td valign="top">
                                                                    <igmisc:WebGroupBox ID="grpDeviceToChange" runat="server" Text="Device to Change"
                                                                        Width="378px" BorderColor="ActiveBorder" BorderWidth="1" BackColor="Transparent">
                                                                        <Template>
                                                                            <table cellpadding="1" cellspacing="2">
                                                                                <tr>
                                                                                    <td style="width: 80px; padding-left: 5px;">
                                                                                        <asp:Label ID="lblDevice" Text="Device" runat="server"></asp:Label>
                                                                                    </td>
                                                                                    <td>
                                                                                        <ig:WebDropDown ID="cboDevice" runat="server" DisplayMode="DropDown" Width="250px"
                                                                                            EnableDropDownAsChild="false" EnableCustomValues="false" DropDownContainerHeight="80px"
                                                                                            AutoPostBackFlags-SelectionChanged="On" OnSelectionChanged="cboDevice_SelectionChanged">
                                                                                            <ClientEvents />
                                                                                        </ig:WebDropDown>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td colspan="2">
                                                                                        <igmisc:WebGroupBox ID="grbPartitions" runat="server" BorderColor="ActiveBorder"
                                                                                            BorderWidth="1" BackColor="Transparent">
                                                                                            <Template>
                                                                                                <table cellpadding="1" cellspacing="2">
                                                                                                    <tr>
                                                                                                        <td>
                                                                                                            <asp:Label ID="lblPartitionFilter" Text="Partition Filter" runat="server" Width="70px"></asp:Label>
                                                                                                        </td>
                                                                                                        <td>
                                                                                                            <ig:WebDropDown ID="cboPartition" runat="server" DisplayMode="DropDown" Width="250px"
                                                                                                                EnableDropDownAsChild="false" EnableCustomValues="false" AutoPostBackFlags-SelectionChanged="On"
                                                                                                                OnSelectionChanged="cboPartition_SelectionChanged">
                                                                                                                <ClientEvents />
                                                                                                            </ig:WebDropDown>
                                                                                                        </td>
                                                                                                    </tr>
                                                                                                </table>
                                                                                            </Template>
                                                                                        </igmisc:WebGroupBox>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td colspan="2">
                                                                                        <igmisc:WebGroupBox ID="gbItem" runat="server" BackColor="Transparent"
                                                                                            BorderColor="ActiveBorder" BorderWidth="1">
                                                                                            <Template>
                                                                                                <table cellpadding="1" cellspacing="2">
                                                                                                    <tr>
                                                                                                        <td>
                                                                                                            <asp:Label ID="lblDeviceType" Text="Reader" runat="server" Width="70px"></asp:Label>
                                                                                                        </td>
                                                                                                        <td>
                                                                                                            <ig:WebDropDown ID="cboDeviceType" runat="server" DisplayMode="DropDown" Width="250px"
                                                                                                                EnableDropDownAsChild="false" EnableCustomValues="false">
                                                                                                                <ClientEvents />
                                                                                                            </ig:WebDropDown>
                                                                                                        </td>
                                                                                                    </tr>
                                                                                                </table>
                                                                                            </Template>
                                                                                        </igmisc:WebGroupBox>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td style="padding-left: 5px;">
                                                                                        <asp:Label ID="lblField" Text="Field" runat="server"></asp:Label>
                                                                                    </td>
                                                                                    <td>
                                                                                        <ig:WebDropDown ID="cboField" runat="server" DisplayMode="DropDown" Width="250px"
                                                                                            EnableDropDownAsChild="false" EnableCustomValues="false">
                                                                                            <ClientEvents />
                                                                                        </ig:WebDropDown>
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </Template>
                                                                    </igmisc:WebGroupBox>
                                                                </td>
                                                                <td valign="top">
                                                                    <igmisc:WebGroupBox ID="grpChangeToMadge" runat="server" Text="Change to Madge" Width="410px"
                                                                        BorderColor="ActiveBorder" BorderWidth="1" BackColor="Transparent">
                                                                        <Template>
                                                                            <table>
                                                                                <tr>
                                                                                    <td style="padding-left: 5px;">
                                                                                        <asp:Label ID="lblNewTimeSchedule" Text="New Time Schedule" runat="server"></asp:Label>
                                                                                    </td>
                                                                                    <td>
                                                                                        <ig:WebDropDown ID="cboNewTimeSchedule" runat="server" DisplayMode="DropDown" Width="250px"
                                                                                            EnablePaging="true" EnableDropDownAsChild="false" EnableCustomValues="false">
                                                                                        </ig:WebDropDown>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td colspan="2">
                                                                                        <igmisc:WebGroupBox ID="grEffectiveDateRange" runat="server" Text="Effective Date Range"
                                                                                            BorderColor="ActiveBorder" BorderWidth="1" BackColor="Transparent">
                                                                                            <Template>
                                                                                                <table>
                                                                                                    <tr>
                                                                                                        <td valign="top">
                                                                                                            <asp:Label ID="lblFrom" Text="From" runat="server" Width="50px"></asp:Label>
                                                                                                        </td>
                                                                                                        <td>
                                                                                                            <ig:WebDatePicker ID="deFrom" runat="server" Width="130px"
                                                                                                                DropDownCalendarID="FromDateCalendarView">
                                                                                                                <ClientSideEvents CalendarClosed="WebDatePicker_CalendarClosed" />
                                                                                                            </ig:WebDatePicker>
                                                                                                            <ig:WebMonthCalendar runat="server" ID="FromDateCalendarView" EnableWeekNumbers="true"
                                                                                                                ChangeMonthToDateClicked="true" EnableMonthDropDown="True" EnableYearDropDown="True">
                                                                                                            </ig:WebMonthCalendar>
                                                                                                            <asp:Label ID="lblStartDay" Text="Start of Day" runat="server" ForeColor="Green"></asp:Label>
                                                                                                        </td>
                                                                                                        <td valign="top">
                                                                                                            <asp:Label ID="lblTo" Text="To" runat="server"></asp:Label>
                                                                                                        </td>
                                                                                                        <td>
                                                                                                            <ig:WebDatePicker ID="deTo" runat="server" Width="130px"
                                                                                                                DropDownCalendarID="ToDateCalendarView">
                                                                                                                <ClientSideEvents CalendarClosed="WebDatePicker_CalendarClosed" />
                                                                                                            </ig:WebDatePicker>
                                                                                                            <asp:Label ID="lblEndDay" Text="End of Day" runat="server" ForeColor="Green"></asp:Label>
                                                                                                            <ig:WebMonthCalendar runat="server" ID="ToDateCalendarView" EnableWeekNumbers="true"
                                                                                                                ChangeMonthToDateClicked="true" EnableMonthDropDown="True" EnableYearDropDown="True">
                                                                                                            </ig:WebMonthCalendar>
                                                                                                        </td>
                                                                                                    </tr>
                                                                                                </table>
                                                                                            </Template>
                                                                                        </igmisc:WebGroupBox>
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </Template>
                                                                    </igmisc:WebGroupBox>
                                                                    <table>
                                                                        <tr>
                                                                            <td>
                                                                                <asp:Label ID="lblPartitionGroup" Text="Partition Group" runat="server" Width="100"></asp:Label>
                                                                            </td>
                                                                            <td>
                                                                                <ig:WebDropDown ID="cboPartitionGroup" runat="server" DisplayMode="DropDownList"
                                                                                    Width="250px" EnableDropDownAsChild="false" EnableMultipleSelection="True" MultiSelectValueDelimiter=" | ">
                                                                                    <ClientEvents />
                                                                                </ig:WebDropDown>
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Label ID="lblActivatedMsg" runat="server" Visible="false" ForeColor="Red" Font-Bold="true"
                                                            Text="WARNING: Scheduled change is currently in effect or queued to be sent to the panel's midnight occurs."></asp:Label>
                                                    </td>
                                                </tr>
                                            </table>
                                        </Template>
                                    </ig:ContentTabItem>
                                </Tabs>
                            </ig:WebTab>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </table>
    </div>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            setInterval(pulseScheduledChangesActivationStatus, 1000);

            function pulseScheduledChangesActivationStatus() {
                $('.scheduled-changes-activated-msg').fadeIn(300);
                $('.scheduled-changes-activated-msg').fadeOut(300);
            }
        });

    </script>
</asp:Content>
