<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Organization_AddlWeekoff_Add.aspx.cs"
    EnableEventValidation="false" MasterPageFile="~/MasterFile/TimeCheck.master"
    Inherits="Organization_Settings_Organization_AddlWeekoff_Add" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ContentPlaceHolderID="BodyContentPH" ID="conAddlWeekoffAdd" runat="server">

    <script language="javascript" type="text/javascript">
        var SelectWeeklyoffDay = "Select Weekly off Day";
        var SelectWeek = "Select Week";
        function SetAlertMessages(selectWeeklyoffDay, selectWeek) {
            SelectWeeklyoffDay = selectWeeklyoffDay;
            SelectWeek = selectWeek;
        }
        function rbtn_click() {
            if (document.getElementById("ctl00_BodyContentPH_rbtn_Company").checked == true) {
                document.getElementById("ctl00_BodyContentPH_ddl_Company").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Region").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Branch").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Dept").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Section").disabled = true;
            }
            else if (document.getElementById("ctl00_BodyContentPH_rbtn_Region").checked == true) {
                document.getElementById("ctl00_BodyContentPH_ddl_Company").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Region").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Branch").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Dept").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Section").disabled = true;
            }
            else if (document.getElementById("ctl00_BodyContentPH_rbtn_Branch").checked == true) {
                document.getElementById("ctl00_BodyContentPH_ddl_Company").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Region").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Branch").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Dept").disabled = true;
                document.getElementById("ctl00_BodyContentPH_ddl_Section").disabled = true;
            }
            else if (document.getElementById("ctl00_BodyContentPH_rbtn_Dept").checked == true) {
                document.getElementById("ctl00_BodyContentPH_ddl_Company").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Region").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Branch").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Dept").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Section").disabled = true;
            }
            else if (document.getElementById("ctl00_BodyContentPH_rbtn_Section").checked == true) {
                document.getElementById("ctl00_BodyContentPH_ddl_Company").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Region").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Branch").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Dept").disabled = false;
                document.getElementById("ctl00_BodyContentPH_ddl_Section").disabled = false;
            }
        }
        // Handle tree view click
        function HandleCheckbox(event) {
            var element = event.srcElement || event.target;
            if (element.tagName == "INPUT" && element.type == "checkbox") {
                var checkedState = element.checked;
                while (element.tagName != "TABLE") // Get wrapping table
                {
                    //element = element.parentElement;
                    element = element.parentNode;
                }
                UnCheckParents(element); // Uncheck all parents        
                element = element.nextSibling;
                if (element == null) // If no childrens than exit
                    return;
                var childTables = element.getElementsByTagName("TABLE");
                for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++) {
                    CheckTable(childTables[tableIndex], checkedState);
                }
            }
        }
        function UnCheckParents(table) {

            if (table == null || table.rows[0].cells.length == 2) // This is the root
            {
                return;
            }
            var parentTable = table.parentNode.previousSibling;
            UnCheckParents(parentTable);
        }
        function CheckTable(table, checked) {
            var checkboxIndex = table.rows[0].cells.length - 1;
            var cell = table.rows[0].cells[checkboxIndex];
            var checkboxes = cell.getElementsByTagName("INPUT");
            if (checkboxes.length == 1) {
                checkboxes[0].checked = checked;
            }
        }
        function CheckValidation() {
            var Week = document.getElementById('ctl00_BodyContentPH_ddl_Day');
            var Day = document.getElementById('ctl00_BodyContentPH_ddl_Week');
            var Errormessage = "";
            if (Week.options[Week.selectedIndex].value == "-Select-") {
                Errormessage = '1';
                alert(SelectWeeklyoffDay);
                return false;
            }
            else if (Day.options[Day.selectedIndex].value == "-Select-") {
                Errormessage = '2';
                alert(SelectWeek);
                return false;
            }
            if (Errormessage == "") {
                return true;
            }
            else {
                return false;
            }
        }
    </script>

    <div class="content-header">
        <h1 style="background-image: url(../dist/img/add-weekoff.png); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_Header" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <asp:UpdatePanel ID="upLeave" runat="server" UpdateMode="conditional">
            <ContentTemplate>
                <asp:Panel ID="pnlProgress" runat="server" Style="display: none;">
                    <asp:Panel ID="pnlLoading" runat="server" HorizontalAlign="center">
                        <div class="InsideProgressBar">
                            <div class="row" style="margin-top: 10px">
                                <img src="../dist/img/logo-Progress.png" />
                            </div>
                            <div class="row" style="min-width: 280px">
                                <img src="../dist/img/default.gif" style="width: 100px" />
                            </div>
                            <div class="row" style="margin-bottom: 10px">
                                <asp:Label ID="lblLoading" runat="server" ForeColor="black" Style="text-align: center"
                                    Text="Please Wait..." Font-Bold="true" Font-Size="12px" Font-Italic="true" Font-Family="Arial"></asp:Label>
                            </div>
                            <div class="clear clearfix">
                            </div>
                        </div>
                    </asp:Panel>
                </asp:Panel>
                <asp:HiddenField ID="hdnProgress" runat="server" />
                <cc1:ModalPopupExtender ID="popupProgress" runat="server" TargetControlID="hdnProgress"
                    BackgroundCssClass="ModalPopup" PopupControlID="pnlProgress" BehaviorID="popupProgress">
                </cc1:ModalPopupExtender>
            </ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="btn_Save" />
            </Triggers>
        </asp:UpdatePanel>
        <div class="exda-table">
            <h6 style="border-bottom: none !important;">
                <span style="color: Red">|</span>Mandatory (2 No.)</h6>
        </div>
        <div class="emp-filter">
            <div class="form-horizontal">
                <div class="row  form-group">
                    <div class="col-md-12">
                        <div class="row form-group">
                            <div class="col-md-12">
                                <div style="height: 280px; overflow: auto; padding-left: 20px; border: 1px solid #c5dffc;">
                                    <asp:TreeView ID="tvAdditionalWeeklyOff" runat="server" ShowCheckBoxes="All" ShowLines="true"
                                        ImageSet="simple" NodeIndent="15" NodeStyle-Font-Size="10" NodeStyle-Font-Names="tahoma"
                                        onclick="HandleCheckbox(event);">
                                    </asp:TreeView>
                                </div>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_Weekof" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-4">
                                <asp:DropDownList ID="ddl_Day" CssClass="form-control select2 Man-dat" runat="server">
                                    <asp:ListItem Value="-Select-" Text="-Select-"></asp:ListItem>
                                    <asp:ListItem Value="Sunday" Text="Sunday"></asp:ListItem>
                                    <asp:ListItem Value="Monday" Text="Monday"></asp:ListItem>
                                    <asp:ListItem Value="Tuesday" Text="Tuesday"></asp:ListItem>
                                    <asp:ListItem Value="Wednesday" Text="Wednesday"></asp:ListItem>
                                    <asp:ListItem Value="Thursday" Text="Thursday"></asp:ListItem>
                                    <asp:ListItem Value="Friday" Text="Friday"></asp:ListItem>
                                    <asp:ListItem Value="Saturday" Text="Saturday"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_selectedweek" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-4">
                                <asp:DropDownList ID="ddl_Week" CssClass="form-control select2 Man-dat" runat="server">
                                    <asp:ListItem Value="-Select-" Text="-Select-"></asp:ListItem>
                                    <asp:ListItem Value="First Week" Text="First Week"></asp:ListItem>
                                    <asp:ListItem Value="Second Week" Text="Second Week"></asp:ListItem>
                                    <asp:ListItem Value="Third Week" Text="Third Week"></asp:ListItem>
                                    <asp:ListItem Value="Fourth Week" Text="Fourth Week"></asp:ListItem>
                                    <asp:ListItem Value="Fifth Week" Text="Fifth Week"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="btn_Save" CssClass="btn save-btn fa-floppy-o" runat="server"
                                        OnClick="btn_Save_Click" OnClientClick="javascript:if(CheckValidation())$find('popupProgress').show();else return false;" />
                                    <asp:LinkButton ID="btn_Cancel" CssClass="btn save-btn fa-angle-left" runat="server"
                                        CausesValidation="False" OnClick="btn_Cancel_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
