<%@ page language="C#" autoeventwireup="true" masterpagefile="~/MasterFile/TimeCheck.master" inherits="Transactions_TA_UI_Transactions_CompressedWorkHoursApproval, App_Web_tn30ieod" %>

<%@ Register Src="../UserControls/TA_uc_OrgLevelFilter_Updated.ascx" TagName="TA_uc_OrgLevel_Filter"
    TagPrefix="uc4" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="ConCWHSanction" ContentPlaceHolderID="BodyContentPH" runat="Server">
    <!--[if gt IE 5.5]>
	<link rel="stylesheet" type="text/css" href="../css/anytimeIE.css" />
			<link rel="stylesheet" type="text/css" href="../css/ProgressforIE.css" />
 <![endif]-->

    <script language="javascript" type="text/javascript">

        //values for check date
        var Monthfourdigit = 'Please enter valid date as month, day, and four digit year : Format MM/dd/yyyy.';
        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 SelStatus = "Select Status";
        var EnterFrmDate = "Enter From Date";
        var EnterToDate = "Enter To Date";
        var GreaterThanFromdt = "To Date should be greater than From Date"

        var MaxLength = "Maximum length is ";


        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(Status, FrmDate, Todate, GreaterThan) {
            SelStatus = Status;
            EnterFrmDate = FrmDate;
            EnterToDate = Todate;
            GreaterThanFromdt = GreaterThan;
        }


        function CWHSanctionWindow() {
            if (document.aspnetForm.ctl00_BodyContentPH_txtFromDate.value == '' && document.aspnetForm.ctl00_BodyContentPH_txtToDate.value != '') {
                alert(EnterFrmDate);
                return false;
            }
            if (document.aspnetForm.ctl00_BodyContentPH_txtFromDate.value != '') {

                var weekDay = document.aspnetForm.ctl00_BodyContentPH_txtFromDate;
                var DateFormat = document.getElementById('ctl00_BodyContentPH_Hidden1').value;

                if (checkDate(weekDay, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {
                }
                else {
                    return false;
                }
            }

            if (document.aspnetForm.ctl00_BodyContentPH_txtFromDate.value != '' && document.aspnetForm.ctl00_BodyContentPH_txtToDate.value == '') {
                alert(EnterToDate);
                return false;
            }

            if (document.aspnetForm.ctl00_BodyContentPH_txtToDate.value != '') {

                var weekDay = document.aspnetForm.ctl00_BodyContentPH_txtToDate;
                var DateFormat = document.getElementById('ctl00_BodyContentPH_Hidden1').value;

                if (checkDate(weekDay, DateFormat, Monthfourdigit, Datefourdigit, Invalidyearentry, Invalidmonthentry, Invaliddateentry, DateformatDDMONYYYY, Entertime, Valueforhours, Invalidvalueforminutes, Invalidtimeformat, EntervalidDateandTime, ValiddatemonthMMDDYYHHMM, ValiddatemonthMMDDYYHHMMTT, EntervalidDateandTime, Invalidvalueforhours, Invalidvalueforminites)) {
                }
                else {
                    return false;
                }
            }

            if (document.aspnetForm.ctl00_BodyContentPH_txtFromDate.value != '' && document.aspnetForm.ctl00_BodyContentPH_txtToDate.value != '') {

                //dd/MM/yyyy validation
                if (document.getElementById('ctl00_BodyContentPH_Hidden1').value == 'DD/MM/YYYY') {
                    var date1 = document.getElementById("<%= txtFromDate.ClientID%>").value;
                    var date1Date = date1.substring(0, 2);
                    var date1Month = date1.substring(3, 5);
                    var date1Year = date1.substring(6, date1.length);

                    var date2 = document.getElementById("<%= txtToDate.ClientID%>").value;
                    var date2Date = date2.substring(0, 2);
                    var date2Month = date2.substring(3, 5);
                    var date2Year = date2.substring(6, date2.length);
                }
                if (date1Year >= date2Year) {
                    if (date1Year > date2Year) {
                        alert(GreaterThanFromdt);
                        document.getElementById("<%= txtToDate.ClientID%>").focus();
                        return false;
                    }
                    if (date1Year == date2Year) {
                        if (date1Month >= date2Month) {
                            if (date1Month > date2Month) {
                                alert(GreaterThanFromdt);
                                document.getElementById("<%= txtToDate.ClientID%>").focus();
                                return false;
                            }
                            if (date1Month == date2Month) {
                                if (date1Date > date2Date) {
                                    alert(GreaterThanFromdt);
                                    document.getElementById("<%= txtToDate.ClientID%>").focus();
                                    return false;
                                }
                                else {
                                }
                            }
                        }
                        else {
                        }
                    }
                }
                else {

                }

                //dd-MMM-yyyy validation
                if (document.getElementById('ctl00_BodyContentPH_Hidden1').value == 'DD-MMM-YYYY') {
                    var date1 = document.getElementById("<%= txtFromDate.ClientID%>").value;
                    var date1Date = date1.substring(0, 2);
                    var date1Month = date1.substring(3, 6);
                    date1Month = Month(date1Month);
                    var date1Year = date1.substring(7, date1.length);

                    var date2 = document.getElementById("<%= txtToDate.ClientID%>").value;
                    var date2Date = date2.substring(0, 2);
                    var date2Month = date2.substring(3, 6);
                    date2Month = Month(date2Month);
                    var date2Year = date2.substring(7, date2.length);
                }
                if (date1Year >= date2Year) {
                    if (date1Year > date2Year) {
                        alert(GreaterThanFromdt);
                        document.getElementById("<%= txtToDate.ClientID%>").focus();
                        return false;
                    }
                    if (date1Year == date2Year) {
                        if (date1Month >= date2Month) {
                            if (date1Month > date2Month) {
                                alert(GreaterThanFromdt);
                                document.getElementById("<%= txtToDate.ClientID%>").focus();
                                return false;
                            }
                            if (date1Month == date2Month) {
                                if (date1Date > date2Date) {
                                    alert(GreaterThanFromdt);
                                    document.getElementById("<%= txtToDate.ClientID%>").focus();
                                    return false;
                                }
                                else {
                                }
                            }
                        }
                        else {
                        }
                    }
                }
                else {

                }

                //mm/dd/yyyy validation
                if (document.getElementById('ctl00_BodyContentPH_Hidden1').value == 'MM/DD/YYYY') {
                    var date1 = document.getElementById("<%= txtFromDate.ClientID%>").value;
                    var date1Month = date1.substring(0, 2);
                    var date1Date = date1.substring(3, 5);
                    var date1Year = date1.substring(6, date1.length);

                    var date2 = document.getElementById("<%= txtToDate.ClientID%>").value;
                    var date2Month = date2.substring(0, 2);
                    var date2Date = date2.substring(3, 5);
                    var date2Year = date2.substring(6, date2.length);
                }
                if (date1Year >= date2Year) {
                    if (date1Year > date2Year) {
                        alert(GreaterThanFromdt);
                        document.getElementById("<%= txtToDate.ClientID%>").focus();
                        return false;
                    }
                    if (date1Year == date2Year) {
                        if (date1Month >= date2Month) {
                            if (date1Month > date2Month) {
                                alert(GreaterThanFromdt);
                                document.getElementById("<%= txtToDate.ClientID%>").focus();
                                return false;
                            }
                            if (date1Month == date2Month) {
                                if (date1Date > date2Date) {
                                    alert(GreaterThanFromdt);
                                    document.getElementById("<%= txtToDate.ClientID%>").focus();
                                    return false;
                                }
                                else {
                                }
                            }
                        }
                        else {
                        }
                    }
                }
                else {

                }
            }
        }

        //Added for DD-MMM-YYYY date format month conversion
        function Month(Mon) {
            var Month;
            switch (Mon) {
                case "Jan":
                    Month = 1;
                    break;
                case "Feb":
                    Month = 2;
                    break;
                case "Mar":
                    Month = 3;
                    break;
                case "Apr": Month = 4;
                    break;
                case "May": Month = 5;
                    break;
                case "Jun": Month = 6;
                    break;
                case "Jul": Month = 7;
                    break;
                case "Aug": Month = 8;
                    break;
                case "Sep": Month = 9;
                    break;
                case "Oct": Month = 10;
                    break;
                case "Nov": Month = 11;
                    break;
                case "Dec": Month = 12;
                    break;
            }
            return (Month);
        }

        //On Center Screen
        function popupwindow(url, title, w, h) {
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);
            return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        }

        var objCWHSanction = null;
        function getApprovalStatus() {
            try {
                objCWHSanction = new XMLHttpRequest();
            }
            catch (ex) {
                try {
                    objCWHSanction = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                    try {
                        objCWHSanction = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch (e1) {
                        objCWHSanction = null;
                    }
                }
            }

            if (objCWHSanction != null) {

                var enK = Math.floor(Math.random() * 111);
                objCWHSanction.onreadystatechange = Process_Response_CWHSanction;
                var Module = "CompressedWorkHours";
                objCWHSanction.open("GET", "AjaxGetApprovalStatus.aspx?Module=" + Module + "&k=" + enK, true);
                objCWHSanction.send(null);
            }

            return false;
        }

        function Process_Response_CWHSanction() {
            if (objCWHSanction.readyState == 4) {
                if (objCWHSanction.status == 200) {
                    document.getElementById('ctl00_BodyContentPH_hdnCWHApprovalStatus').value = objCWHSanction.responseText;
                    return false;
                }
                else {
                    document.getElementById('ctl00_BodyContentPH_hdnCWHApprovalStatus').value = 'Error';
                    return false;
                }
            }
        }

        // SRS Rule: Approve / Reject allowed only on Monday (1) and Tuesday (2)
        // JS getDay(): 0=Sun, 1=Mon, 2=Tue
        function ConfirmApprove() {
            var day = new Date().getDay();
            if (day !== 1 && day !== 2) {
                alert('Approval is allowed only on Monday and Tuesday as per company policy.');
                return false;
            }
            return confirm('Are you sure you want to Approve this application?');
        }
        function ConfirmReject() {
            var day = new Date().getDay();
            if (day !== 1 && day !== 2) {
                alert('Rejection is allowed only on Monday and Tuesday as per company policy.');
                return false;
            }
            return confirm('Are you sure you want to Reject this application?');
        }
    </script>

    <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>

    <link href="../css/ProgressBar.css" rel="stylesheet" type="text/css" />

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

    <script>

        $(function () {
            $('#ctl00_BodyContentPH_txtFromDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });
        $(function () {
            $('#ctl00_BodyContentPH_txtToDate').datetimepicker({ format: document.getElementById('ctl00_BodyContentPH_Hidden1').value }
            );
        });

    </script>

    <div class="content-header">
        <h1 style="background-image: url('../dist/img/lve-san.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="row">
                <div class="col-sm-12">
                    <div class="inr-fil-text pull-left">
                        <asp:Label ID="lblFilter" runat="server" Text="Filter"></asp:Label>
                        <asp:HiddenField ID="Hidden2" runat="server" />
                        <%--<input id="Hidden2" type="hidden" value='<% Response.Write(Convert.ToString(Session["IDateFormat"])); %>' />--%>
                    </div>
                    <div class="pull-right">
                        <h6>
                            <span style="color: Red">|</span><span style="padding-left: 10px; padding-right: 10px"><asp:Label
                                ID="lbl_IndicatesMandatoryFields" runat="server"></asp:Label>
                                (2 No.)</span>
                        </h6>
                    </div>
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
        <div id="collapseOne">
            <div class="emp-filter">
                <div class="form-horizontal">
                    <div class="row">
                        <div class="col-md-12">
                            <div id="divEmployeeDetails" runat="server" style="width: 100%">
                                <div class="form-group" style="display: none">
                                    <div class="col-md-12">
                                        <asp:Label ID="lblEmpSwipe" runat="server"></asp:Label>
                                        <asp:TextBox onpaste="return true" ID="txtSwipeCard" MaxLength="20" runat="server"
                                            CssClass="form-control" onkeypress="return acceptCharsNum_MaxLength(event,this,20,MaxLength);"></asp:TextBox>
                                        <cc1:AutoCompleteExtender ID="acSwipeCardNo" runat="server" CompletionSetCount="10"
                                            CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                            CompletionInterval="10" Enabled="true" MinimumPrefixLength="1" TargetControlID="txtSwipeCard"
                                            ServicePath="../WebServices/AutoCompleteExtender.asmx" ServiceMethod="GetCardNo"
                                            CompletionListCssClass="autocomplete_completionListElement" FirstRowSelected="true">
                                        </cc1:AutoCompleteExtender>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-2">
                                        <asp:Label ID="lblEmployeeName" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:TextBox onpaste="return true" ID="txtEmployeeName" runat="server" CssClass="form-control"
                                            MaxLength="50" onkeypress="return employeename_singlequotes_maxlength(event,this,50,MaxLength);"></asp:TextBox>
                                        <cc1:AutoCompleteExtender ID="acEmpName" runat="server" CompletionInterval="10" CompletionSetCount="10"
                                            CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                            Enabled="true" FirstRowSelected="true" MinimumPrefixLength="1" ServicePath="../WebServices/AutoCompleteExtender.asmx"
                                            ServiceMethod="GetEmployeeName" CompletionListCssClass="autocomplete_completionListElement"
                                            TargetControlID="txtEmployeeName">
                                        </cc1:AutoCompleteExtender>
                                    </div>
                                    <div class="col-md-1">
                                    </div>
                                    <div class="col-md-2">
                                        <asp:Label ID="lblEmployeeId" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:TextBox onpaste="return true" ID="txtEmployeeId" runat="server" CssClass="form-control"
                                            MaxLength="15" onkeypress="return acceptCharsNum_MaxLength(event,this,15,MaxLength);"></asp:TextBox>
                                        <cc1:AutoCompleteExtender ID="acEmployeeId" runat="server" CompletionSetCount="10"
                                            CompletionListItemCssClass="item" CompletionListHighlightedItemCssClass="AutocompleteCSS"
                                            CompletionInterval="10" Enabled="true" MinimumPrefixLength="1" TargetControlID="txtEmployeeId"
                                            ServicePath="../WebServices/AutoCompleteExtender.asmx" ServiceMethod="GetEmployeeId"
                                            CompletionListCssClass="autocomplete_completionListElement" FirstRowSelected="true">
                                        </cc1:AutoCompleteExtender>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-2">
                                        <asp:Label ID="lblEmpCategory" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:DropDownList ID="ddlEmpCatagory" runat="server" CssClass="form-control select2" AppendDataBoundItems="true">
                                            <asp:ListItem Value="0" Selected="True" Text="-Select-"></asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                    <div class="col-md-1">
                                    </div>
                                    <div class="col-md-2">
                                        <asp:Label ID="lblEmpType" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:DropDownList ID="ddlEmpType" runat="server" CssClass="form-control select2" AppendDataBoundItems="true">
                                            <asp:ListItem Value="0" Selected="True" Text="-Select-"></asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-2">
                                        <asp:Label ID="lbl_From" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:TextBox onpaste="return true" ID="txtFromDate" runat="server" CssClass="form-control"
                                            EnableViewState="False" MaxLength="25" onCut="return false" onDrop="return false"></asp:TextBox>
                                        <asp:CustomValidator ID="cus_FromDate" runat="server" EnableClientScript="False"
                                            OnServerValidate="ValidateFromDate" ErrorMessage="Select valid From Date" Display="Dynamic"></asp:CustomValidator>
                                    </div>
                                    <div class="col-md-1">
                                    </div>
                                    <div class="col-md-2">
                                        <asp:Label ID="lbl_To" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:TextBox onpaste="return true" ID="txtToDate" runat="server" CssClass="form-control"
                                            EnableViewState="False" MaxLength="25" onCut="return false" onDrop="return false"></asp:TextBox>
                                        <asp:CustomValidator ID="cus_ToDate" OnServerValidate="ValidateToDate" runat="server"
                                            EnableClientScript="False" ErrorMessage="Select valid To Date" Display="Dynamic"></asp:CustomValidator>
                                        <asp:CustomValidator ID="cus_ComDate" runat="server" Display="Dynamic" EnableClientScript="False"
                                            ErrorMessage="Todate should be greater then from date" OnServerValidate="CompareDate"></asp:CustomValidator>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-2">
                                        <asp:Label ID="lbl_Status" runat="server"></asp:Label>
                                    </div>
                                    <div class="col-md-3">
                                        <asp:DropDownList ID="ddlStatus" runat="server" CssClass="form-control select2 Man-dat">
                                            <asp:ListItem Text="All" Value="All"></asp:ListItem>
                                            <asp:ListItem Text="Approved" Value="Approved"></asp:ListItem>
                                            <asp:ListItem Text="Forwarded" Value="Forwarded"></asp:ListItem>
                                            <asp:ListItem Text="Pending" Value="Pending"></asp:ListItem>
                                            <asp:ListItem Text="Rejected" Value="Rejected"></asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix">
                        </div>
                        <div class="row">
                            <div class="line16">
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="row">
                                <div class="col-md-12">
                                    <uc4:TA_uc_OrgLevel_Filter ID="TA_UC_Organisation" runat="server" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-5">
                        </div>
                        <div class="col-md-6">
                            <div class="pull-right-button">
                                <asp:HiddenField ID="Hidden1" runat="server" />
                                <asp:LinkButton ID="btn_View" CssClass="btn view-btn fa-eye" runat="server" OnClick="btn_View_Click"
                                    OnClientClick="return CWHSanctionWindow();" />
                                <input id="hdnCWHApprovalStatus" type="hidden" runat="server" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- SRS INFO: Day restriction notice -->
            <div class="row" style="margin: 0 15px 5px 15px;">
                <div class="col-md-12">
                    <asp:Label ID="lblDayRestrictionNote" runat="server" ForeColor="#E07B00"
                        Text="&#9432; Approve / Reject is allowed only on Monday and Tuesday as per company policy."
                        Style="font-size:12px;"></asp:Label>
                </div>
            </div>

            <div id="myModal" class="modal modal-default fade" role="dialog">
                <div class="modal-dialog" style="min-width: 75%;">
                    <!-- Modal content-->
                    <div class="modal-content" style="margin-top: 100px">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                                &times;</button>
                            <h4 class="modal-title">Compressed Work Hours Sanction</h4>
                        </div>
                        <div class="modal-body" style="padding-top: 0px">
                            <iframe id="iframePopup" runat="server" scrolling="auto" width="100%" style="border-style: none; height: 400px"></iframe>
                        </div>
                        <div class="modal-footer" style="display: none">
                            <button type="button" class="btn btn-primary pull-right" data-dismiss="modal">
                                Close</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
