<%@ page language="C#" masterpagefile="~/MasterFile/TimeCheck.master" enableeventvalidation="false" autoeventwireup="true" inherits="Organization_Settings_Organization_TemporaryWeekday, App_Web_khau1nsh" %>

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

    <script src="../plugins/datepicker/jquery-1.11.1.min.js"></script>

    <script language="javascript" src="../js/jquery.autocomplete.js" type="text/javascript"></script>

    <script src="../plugins/datepicker/bootstrap-datepicker.js"></script>

    <script>

        $(function () {
            $('#ctl00_BodyContentPH_txtWeekFromDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });
        $(function () {
            $('#ctl00_BodyContentPH_txtWeekToDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });
        $(function () {
            $('#ctl00_BodyContentPH_txt_closingtime').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden2').value }
            );
        });
    </script>

    <div class="content-header">
        <h1 style="background-image: url(../dist/img/temporary-weekday.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">
        <%-- <div class="inr-ftr">--%>
        <div class="exda-table">
            <h6 style="border-bottom: none !important;">
                <span style="color: Red">|</span> <asp:Label ID="lblMandatory" runat="server" Text="Mandatory"></asp:Label> (3 No.)</h6>
        </div>
        <asp:HiddenField ID="Hidden1" runat="server" />
        <asp:HiddenField ID="Hidden2" runat="server" />
        <%-- </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; width: 450; overflow: auto; padding-left: 20px; border: 1px solid #c5dffc;">
                                    <asp:TreeView ID="tvLevel" runat="server" NodeStyle-Font-Size="12px" ShowCheckBoxes="All"
                                        ImageSet="Simple" NodeStyle-Font-Names="tahoma" ShowLines="true" NodeIndent="15"
                                        onclick="HandleCheckbox(event);">
                                    </asp:TreeView>
                                </div>
                            </div>
                        </div>
                        <div class="row form-group">
                            <%--  <div class="col-md-1">
                            </div>--%>
                            <div class="col-md-2">
                                <asp:Label ID="lbl_TempWeekFromDate" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-4">
                                <asp:TextBox onpaste="return true" ID="txtWeekFromDate" runat="server" CssClass="form-control man-dat"
                                    onCut="return false;" MaxLength="25"></asp:TextBox>
                            </div>
                        </div>
                        <div class="row form-group" style="display: none">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_TempWeekToDate" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-9">
                                <asp:TextBox onpaste="return true" ID="txtWeekToDate" runat="server" CssClass="form-control man-dat"
                                    onCut="return false;" MaxLength="25"></asp:TextBox>
                                <asp:CustomValidator ID="cus_ComDate" runat="server" Display="none" EnableClientScript="False"
                                    OnServerValidate="CompareDate"></asp:CustomValidator>
                            </div>
                        </div>
                        <div class="row form-group">
                            <%-- <div class="col-md-1">
                            </div>--%>
                            <div class="col-md-2">
                                <asp:Label ID="lbl_ClosingTime" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-4">
                                <asp:TextBox onpaste="return true" ID="txt_closingtime" runat="server" CssClass="form-control man-dat"
                                    MaxLength="8" onclick="EnableOrDisable();"></asp:TextBox>
                            </div>
                            <div class="col-md-2 src-margintop">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="btnLoadShift" runat="server" Text="&nbsp;&nbsp;Load Shift" OnClick="btnLoadShift_Click"
                                        CssClass="btn save-btn fa-refresh" OnClientClick="return CheckShiftTime()" />
                                </div>
                            </div>
                        </div>
                        <div class="row form-group" runat="server" style="display: none" id="trShiftLoad">
                            <%--<div class="col-md-1">
                            </div>--%>
                            <div class="col-md-2">
                                <asp:Label ID="lblShift" runat="server"></asp:Label>
                                <%--   <span  ></span>--%>
                            </div>
                            <div class="col-md-4">
                                <div style="width: 350; overflow: auto;">
                                    <asp:CheckBox ID="cbAll" runat="server" Text="Select All" onclick="CheckAll();" Font-Size="12px"
                                        Font-Bold="true" Font-Names="tahoma" Style="padding-left: 2px;" />
                                    <asp:CheckBoxList ID="cklstShift" runat="server" RepeatDirection="vertical" Font-Names="tahoma"
                                        Font-Size="12px" onclick="UnCheckAll();">
                                    </asp:CheckBoxList>
                                </div>
                                <asp:HiddenField ID="hdfLoadShift" runat="server" Value="0" />
                            </div>
                        </div>
                        <div class="row form-group">
                            <%-- <div class="col-md-1">
                            </div>--%>
                            <div class="col-md-2">
                                <asp:Label ID="lbl_Reason" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-4">
                                <asp:TextBox onpaste="return true" ID="txt_Reason" onkeypress="return chkMaxLen(event,this,250,MaxLength);"
                                    Style="resize: none" MaxLength="250" runat="server" CssClass="form-control man-dat"
                                    TextMode="MultiLine"></asp:TextBox>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <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"
                                            X="50" Y="50">
                                        </cc1:ModalPopupExtender>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:PostBackTrigger ControlID="btn_Save" />
                                    </Triggers>
                                </asp:UpdatePanel>
                            </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="if(WeekdayValidation()) $find('popupProgress').show();else return false;" />
                                    <asp:LinkButton ID="btn_Cancel" CssClass="btn save-btn fa-angle-left" runat="server"
                                        OnClick="btn_Cancel_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var FillWeekdayFromDate = "Fill Weekday From Date";
        var FillWeekdayToDate = " Fill Week day To Date";
        var FillClosingTime = "Fill Closing Time ";
        var FillReason = "Fill Reason";
        var AreyousuretoSave = "Are you sure to Save";
        //values for check date
        var Monthfourdigit = 'Please enter valid date as month, day, and four digit year : Format MM/dd/yyyy.';
        //Adding this line var Datefourdigit='Please enter valid date with correct format dd/MM/yyyy'; as newly
        var Datefourdigit = 'Please enter valid date with correct format dd/MM/yyyy';
        var Invalidyearentry = 'Invalid year entry';
        var Invalidmonthentry = 'Invalid month entry';
        var Invaliddateentry = 'Invalid date entry';
        var DateformatDDMONYYYY = 'Incorrect date format. Enter as DD-MON-YYYY';
        var Entertime = 'Enter time';
        var Valueforhours = 'Invalid value for hours:';
        var Invalidvalueforminutes = 'Invalid value for minutes:';
        var Invalidtimeformat = 'Invalid time format:';
        var EntervalidDateandTime = 'Please enter valid Date and Time';
        var ValiddatemonthMMDDYYHHMM = 'Please enter valid Date and Time MM/dd/yyyy HH:mm';
        var ValiddatemonthMMDDYYHHMMTT = 'Please enter valid Date and Time MM/dd/yyyy hh:mm tt';
        var EntervalidDateandTime = 'Please enter valid Date and Time';
        var Invalidvalueforhours = 'Invalid value for hours:';
        var Invalidvalueforminites = 'Invalid value for minutes:';
        var MaxLength = "Maximum length is ";
        var SelectShift = "Please select Shift";
        var NotValidShiftForLevels = "Shift is not available to this selected levels";
        var ClickLoadShift = "Click Load Shift";
        function MaxLengthh(maxLength) {
            MaxLength = maxLength;
        }
        function SetAlertCheckDate(monthfourdigit, datefourdigit, invalidyearentry, invalidmonthentry, invaliddateentry, dateformatDDMONYYYY, entertime, valueforhours, invalidvalueforminutes, invalidtimeformat, entervalidDateandTime, validdatemonthMMDDYYHHMM, validdatemonthMMDDYYHHMMTT, entervalidDateandTime, invalidvalueforhours, invalidvalueforminites) {
            Monthfourdigit = monthfourdigit;
            Datefourdigit = datefourdigit;
            Invalidyearentry = invalidyearentry;
            Invalidmonthentry = invalidmonthentry;
            Invaliddateentry = invaliddateentry;
            DateformatDDMONYYYY = dateformatDDMONYYYY;
            Entertime = Entertime;
            Valueforhours = valueforhours;
            Invalidvalueforminutes = invalidvalueforminutes;
            Invalidtimeformat = invalidtimeformat;
            EntervalidDateandTime = entervalidDateandTime;
            ValiddatemonthMMDDYYHHMM = validdatemonthMMDDYYHHMM;
            ValiddatemonthMMDDYYHHMMTT = validdatemonthMMDDYYHHMMTT;
            EntervalidDateandTime = entervalidDateandTime;
            Invalidvalueforhours = invalidvalueforhours;
            Invalidvalueforminites = invalidvalueforminites;
        }
        function SetAlertMessages(fillWeekdayFromDate, fillWeekdayToDate, fillClosingTime, fillReason, areyousuretoSave,
        selectShift, notValidShiftForLevels, clickLoadShift
        ) {
            FillWeekdayFromDate = fillWeekdayFromDate;
            FillWeekdayToDate = fillWeekdayToDate;
            FillClosingTime = fillClosingTime;
            FillReason = fillReason;
            AreyousuretoSave = areyousuretoSave;
            SelectShift = selectShift;
            NotValidShiftForLevels = notValidShiftForLevels;
            ClickLoadShift = clickLoadShift;
        }
        function WeekdayValidation() {
            var weekDay = document.aspnetForm.ctl00_BodyContentPH_txtWeekFromDate;
            var weekToDay = document.aspnetForm.ctl00_BodyContentPH_txtWeekFromDate;
            var DateFormat = document.getElementById('ctl00_BodyContentPH_Hidden1').value;
            var ClosingTime = document.aspnetForm.ctl00_BodyContentPH_txt_closingtime;
            var TimeFormat = document.getElementById('ctl00_BodyContentPH_Hidden2').value;
            var cklstShift = document.getElementById('ctl00_BodyContentPH_cklstShift');
            var intIndex = 0;
            var flag = 0;
            var rowCount = 0;
            if (document.getElementById('ctl00_BodyContentPH_cklstShift') != null)
                rowCount = document.getElementById('ctl00_BodyContentPH_cklstShift').getElementsByTagName("input").length;
            var hdfLoadShift = document.getElementById('ctl00_BodyContentPH_hdfLoadShift').value;
            var rangeDemoFormat = document.getElementById('ctl00_BodyContentPH_Hidden1').value;

            if (hdfLoadShift == "0") {
                alert(ClickLoadShift);
                //document.aspnetForm.ctl00_BodyContentPH_btnLoadShift.focus();
                return false;
            }
            if (document.aspnetForm.ctl00_BodyContentPH_txtWeekFromDate.value == "") {
                alert(FillWeekdayFromDate);
                document.aspnetForm.ctl00_BodyContentPH_txtWeekFromDate.focus();
                return false;
            }
            else if (document.aspnetForm.ctl00_BodyContentPH_txt_closingtime.value == "") {
                alert(FillClosingTime);
                document.aspnetForm.ctl00_BodyContentPH_txt_closingtime.focus();
                return false;
            }
            else if (document.aspnetForm.ctl00_BodyContentPH_txt_Reason.value == "") {
                alert(FillReason);
                document.aspnetForm.ctl00_BodyContentPH_txt_Reason.focus();
                return false;
            }
            else if (rowCount > 0) {
                for (i = 0; i < rowCount; i++) {
                    if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i)) {
                        if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).checked == true) {
                            flag = 1;
                            break;
                        }
                        else {
                            flag = 0;
                        }
                    }
                }
                if (flag == 0) {
                    alert(SelectShift);
                    return false;
                }
            }
            else if (rowCount == 0) {
                alert(NotValidShiftForLevels);
                return false;
            }
            if (checkDate(weekDay, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {
            }
            else {
                weekDay.focus();
                return false;
            }
            if (checkDate(weekToDay, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {
            }
            else {
                weekToDay.focus();
                return false;
            }

            if (checkTime(ClosingTime, TimeFormat)) {
            }
            else {
                return false;
            }
            return confirm(AreyousuretoSave);

        }
        function checkTime(field, TimeFormat) {
            var errorMsg = "";
            if (TimeFormat == "HH:mm") {
                re = /^(\d{1,2}):(\d{2})(:00)?([AP]M)?$/;
            }
            if (TimeFormat == "LT") {
                re = /^(\d{1,2}):(\d{2})(:00)? ((AM|am|PM|pm))?$/;
            }
            //re = /^(\d{1,2}):(\d{2})(:00)? ((AM|am|PM|pm))?$/;  
            if (field.value != '') {
                if (regs = field.value.match(re)) {
                    if (TimeFormat == "LT") {
                        // 12-hour time format with am/pm 
                        if (regs[1] < 1 || regs[1] > 12) {
                            errorMsg = "Invalid value for hours: " + regs[1];
                        }
                    }
                    else if (TimeFormat == "HH:mm") {
                        // 24-hour time format 
                        if (regs[1] > 23) {
                            errorMsg = "Invalid value for hours: " + regs[1];
                        }
                    }
                    if (!errorMsg && regs[2] > 59) {
                        errorMsg = "Invalid value for minutes: " + regs[2];
                    }
                }
                else {
                    errorMsg = "Invalid time format: " + field.value;
                }
            }
            if (errorMsg != "") {
                alert(errorMsg);
                field.focus();
                return false;
            }
            return true;
        }
        function EnableOrDisable() {
            document.getElementById('ctl00_BodyContentPH_hdfLoadShift').value = "0";
            document.getElementById('ctl00_BodyContentPH_cbAll').checked = false;
            var intIndex = 0;
            var rowCount = 0;
            document.getElementById('ctl00_BodyContentPH_cbAll').checked = false;
            if (document.getElementById('ctl00_BodyContentPH_cklstShift') != null)
                rowCount = document.getElementById('ctl00_BodyContentPH_cklstShift').getElementsByTagName("input").length;
            if (rowCount > 0) {
                for (i = 0; i < rowCount; i++) {
                    document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).checked = 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);
                }
            }
            EnableOrDisable();
        }
        function postBackByObject() {
            var o = window.event.srcElement;
            if (o.tagName == "INPUT" && o.type == "checkbox") {
                __doPostBack("", "");
            }
        }
        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 CheckAll() {
            var intIndex = 0;
            var rowCount = document.getElementById('ctl00_BodyContentPH_cklstShift').getElementsByTagName("input").length;
            for (i = 0; i < rowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_cbAll').checked == true) {
                    if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i)) {
                        if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).disabled != true)
                            document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).checked = true;
                    }
                }
                else {
                    if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i)) {

                        if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).disabled != true)
                            document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).checked = false;
                    }
                }
            }
        }
        function UnCheckAll() {
            var intIndex = 0;
            var flag = 0;
            var rowCount = document.getElementById('ctl00_BodyContentPH_cklstShift').getElementsByTagName("input").length;
            for (i = 0; i < rowCount; i++) {
                if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i)) {
                    if (document.getElementById("ctl00_BodyContentPH_cklstShift" + "_" + i).checked == true) {
                        flag = 1;
                    }
                    else {
                        flag = 0;
                        break;
                    }
                }
            }
            if (flag == 0)
                document.getElementById('ctl00_BodyContentPH_cbAll').checked = false;
            else

                document.getElementById('ctl00_BodyContentPH_cbAll').checked = true;
        }
        //Added by Manjula.P on 07-Feb-2014
        function CheckShiftTime() {
            var ClosingTime = document.aspnetForm.ctl00_BodyContentPH_txt_closingtime;
            var TimeFormat = document.getElementById('ctl00_BodyContentPH_Hidden2').value;
            if (checkTime(ClosingTime, TimeFormat)) {
            }
            else {
                return false;
            }
        }
    </script>

</asp:Content>
