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

<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 language="javascript" type="text/javascript">
        $(function () {
            $('#ctl00_BodyContentPH_txtlateNotification').datetimepicker({ format: 'HH:mm' });
            $('#ctl00_BodyContentPH_txtContinuousLateEntry').datetimepicker({ format: 'HH:mm' });
            $('#ctl00_BodyContentPH_txtlessHoursLimit').datetimepicker({ format: 'HH:mm' });
        });
        function numbers_dot(e, ctrl) {
            var keycode;
            if (window.event)
                keycode = window.event.keyCode;
            else if (e) keycode = e.which;
            else return true;
            if ((keycode == 8) || (keycode == 0)) {
                return true;
            }
            if (!(keycode >= 48 && keycode <= 57) && (keycode != 13) && (keycode = 36)) {
                return false;
            }
            else return true;
        }
        function openURL(URL) {
            $('#ctl00_BodyContentPH_lbl_ReportName').text($("#ctl00_BodyContentPH_txtTemplateName").val());
            document.getElementById('ctl00_BodyContentPH_iframeReport').src = URL;
            $(document).ready(function () {
                $("#myModalReport").modal('show');
            });
            return false;
        }
        //    function openURL(URL)
        //    {
        //        $('#ctl00_BodyContentPH_lbl_ReportName').text($("#ctl00_BodyContentPH_txtTemplateName").val());
        //        document.getElementById('ctl00_BodyContentPH_iframeReport').src=URL;
        //        $(document).ready(function()
        //        {
        //            $("#myModalReport").modal('show');
        //        });
        //        return false;
        //    }
        function navi(loc) {
            document.getElementById('ctl00_BodyContentPH_iframe1').src = loc;
            return false;
        }
    </script>

    <div class="content-header">
        <h1>
            <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 id="myModalReport" class="modal modal-default fade" role="dialog">
            <div class="modal-dialog" style="min-width: 85%;">
                <!-- Modal content-->
                <div class="modal-content" style="margin-top: 50px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                            &times;</button>
                        <h4 class="modal-title" style="padding-bottom: 10px">
                            <asp:Label ID="lbl_ReportName" runat="server"></asp:Label>
                        </h4>
                    </div>
                    <div class="modal-body" style="padding-top: 0px">
                        <iframe id="iframeReport" runat="server" scrolling="auto" width="100%" height="550px"
                            style="border-style: none"></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 id="divReceivers" class="modal modal-default fade" role="dialog">
            <div class="modal-dialog" style="min-width: 85%;">
                <!-- Modal content-->
                <div class="modal-content" style="margin-top: 50px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                            &times;</button>
                        <h4 class="modal-title" style="padding-bottom: 10px">
                            <asp:Label ID="lblreceivershdr" runat="server"></asp:Label>
                        </h4>
                    </div>
                    <div class="modal-body" style="padding-top: 0px">
                        <iframe id="iframe1" runat="server" scrolling="auto" width="100%" height="400px"
                            style="border-style: none"></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 class="inr-ftr">
            <div class="row">
                <div class="col-sm-12">
                    <div class="pull-right">
                        <h6>
                            <span style="color: Red">|</span><span style="padding-left: 10px; padding-right: 10px">
                                Mandatory (5 No.) </span>
                        </h6>
                    </div>
                </div>
            </div>
        </div>
        <div class="emp-filter">
            <div class="form-horizontal">
                <div class="row">
                    <div class="col-md-12">
                        <asp:HiddenField ID="hdnFilters" runat="server" />
                        <asp:HiddenField ID="hdnReportType" runat="server" />
                        <asp:HiddenField ID="hdnCompanyId" runat="server" />
                        <div class="row form-group">
                            <div class="col-md-3">
                                <asp:Label ID="lblTemplatename" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-6">
                                <asp:TextBox onpaste="return true" ID="txtTemplateName" runat="server" CssClass="form-control"
                                    ReadOnly="true"></asp:TextBox>
                            </div>
                            <div class="col-md-2 src-margintop src-padleft">
                                <span class="input-group-btn">
                                    <asp:LinkButton CssClass="btn save-btn fa-filter" runat="server" Enabled="true" ID="lnkbtnChooseFilter"
                                        OnClick="btnChooseFilters_Click" Style="width: 120px;" />
                                </span>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3">
                                <asp:Label ID="lblReceivers" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-6">
                                <asp:TextBox ID="txtReceivers" runat="server" CssClass="form-control man-dat" TextMode="MultiLine"
                                    Style="resize: none" Height="70px"></asp:TextBox>
                            </div>
                            <div class="col-md-2 src-margintop src-padleft">
                                <span class="input-group-btn">
                                    <asp:LinkButton ID="btn_AddReceivers" runat="server" CssClass="btn add-btn fa-plus"
                                        Style="width: 120px" Text="" data-toggle="modal" data-target="#divReceivers">
                                    </asp:LinkButton>
                                </span>
                            </div>
                        </div>
                        <div class="row form-group" id="lateEntry" runat="server">
                            <div class="col-md-3">
                                <asp:Label ID="lbllateNotifcation" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-2" style="width: 50;">
                                <asp:TextBox onpaste="return true" ID="txtlateNotification" runat="server" CssClass="form-control man-dat"
                                    MaxLength="5"></asp:TextBox>
                            </div>
                            <div class="col-md-3">
                                <asp:Label ID="lbllateNotification1" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="row form-group" style="display: none" id="ContinuousAbsent" runat="server">
                            <div class="col-md-3">
                                <asp:Label ID="lblContinuousabsent" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-2" style="width: 50;">
                                <asp:TextBox onpaste="return true" ID="txtContinuousabsent" runat="server" CssClass="form-control man-dat"
                                    MaxLength="2" onkeypress="return numbers_dot(event,this)"></asp:TextBox>
                            </div>
                            <div class="col-md-3">
                                <asp:Label ID="lblDays" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="row form-group" style="display: none" id="Continuous_lateEntry" runat="server">
                            <div class="col-md-3">
                                <asp:Label ID="lblContinuousLateEntry" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-2" style="width: 50;">
                                <asp:TextBox onpaste="return true" ID="txtContinuousLateEntry" runat="server" CssClass="form-control man-dat"
                                    MaxLength="5"></asp:TextBox>
                            </div>
                            <div class="col-md-4">
                                <asp:Label ID="lblContinuousLateEntry1" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="row form-group" style="display: none" id="LessHours" runat="server">
                            <div class="col-md-3">
                                <asp:Label ID="lbllessHoursLimit" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-2" style="width: 50;">
                                <asp:TextBox onpaste="return true" ID="txtlessHoursLimit" runat="server" CssClass="form-control man-dat"
                                    MaxLength="5"></asp:TextBox>
                            </div>
                        </div>
                        <div class="row form-group" id="EmployeeNotification" runat="server" style="display: none">
                            <div class="col-md-3">
                                <asp:Label ID="lblEmployeeNotification" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3" style="width: 50; overflow: auto;">
                                <asp:RadioButtonList ID="rbtnEmployeeNotification" runat="server" RepeatDirection="Horizontal"
                                    Style="margin-right: 1px;" CssClass="radio radio-primary">
                                    <asp:ListItem Value="1" Text="Yes">Yes</asp:ListItem>
                                    <asp:ListItem Value="0" Text="No">No</asp:ListItem>
                                </asp:RadioButtonList>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3">
                                <asp:Label ID="lblMessage" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-6" style="width: 50; overflow: auto;">
                                <asp:TextBox onpaste="return true" ID="txtMessage" runat="server" CssClass="form-control man-dat"
                                    MaxLength="250" Style="resize: none" Height="60px" TextMode="MultiLine"></asp:TextBox>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3">
                                <asp:Label ID="lblTags" runat="server" Text="Insertion Tags"></asp:Label>
                            </div>
                            <div class="col-md-6">
                                <div class="input-group input-group-sm">
                                    <asp:TextBox ID="txtTags" runat="server" onkeyup="return chkMaxLen(event,this,300,MaxLength);"
                                        MaxLength="300" CssClass="form-control man-dat"></asp:TextBox>
                                    <span class="input-group-btn">
                                        <asp:DropDownList ID="ddlTags" onchange="insertAtCursor('texttest');" runat="server"
                                            CssClass="btn save-btn" Width="120px" Style="text-align: left">
                                            <asp:ListItem Text="Insert Fields" Value="0"></asp:ListItem>
                                        </asp:DropDownList>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="row form-group" style="display: none">
                            <div class="col-md-3">
                                <asp:Label ID="lblSample" runat="server" Text="Sample :"></asp:Label>
                            </div>
                            <div class="col-md-6">
                                <asp:Label ID="lblSampleData" runat="server" Text="Sample"></asp:Label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-5">
                            </div>
                            <div class="col-md-4" align="right">
                                <asp:LinkButton ID="smsbtn_save" CssClass="btn save-btn fa-floppy-o" runat="server"
                                    ValidationGroup="vgLeaveType" OnClientClick="return ValidateControl();" OnClick="btn_save_Click" />
                                <asp:LinkButton runat="server" ID="smsbtnBack" CssClass="btn save-btn fa-angle-left"
                                    OnClick="btnBack_Click" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var ChooseSMSReceiver = "Choose SMS Receiver";
        var SelectNotificationtriggeraftervalue = "Select Notification trigger after value";
        var EntervalidNotificationtriggeraftervalue = "Enter valid Notification trigger after value";
        var EntervalidNotificationtriggereveryvalue = "Enter valid Notification trigger every value";
        var EntervalidLessHoursLimitation = "Enter valid Less Hours Limitation";
        var SelectLessHoursLimitation = "Select Less Hours Limitation";
        var EnterNumberofdaysfieldvalue = "Enter Number of days field value";
        var EntervalidNumberinNumberofdays = "Enter valid Number in Number of days";
        var EnterMessage = "Enter Message";
        var SelectTags = "Select Tags";
        var Areyousuretosaverecord = "Are you sure to save record";
        var SelectNotificationtriggereveryvalue = "Select Notification trigger every value";

        function SetAlertMessages(chooseSMSReceiver, selectNotificationtriggeraftervalue, entervalidNotificationtriggeraftervalue,
            entervalidNotificationtriggereveryvalue, entervalidLessHoursLimitation, selectLessHoursLimitation, enterNumberofdaysfieldvalue,
            entervalidNumberinNumberofdays, enterMessage, selectTags, areyousuretosaverecord, selectNotificationtriggereveryvalue
            ) {
            ChooseSMSReceiver = chooseSMSReceiver;
            SelectNotificationtriggeraftervalue = selectNotificationtriggeraftervalue;
            EntervalidNotificationtriggeraftervalue = entervalidNotificationtriggeraftervalue;
            EntervalidNotificationtriggereveryvalue = entervalidNotificationtriggereveryvalue;
            EntervalidLessHoursLimitation = entervalidLessHoursLimitation;
            SelectLessHoursLimitation = selectLessHoursLimitation;
            EnterNumberofdaysfieldvalue = enterNumberofdaysfieldvalue;
            EntervalidNumberinNumberofdays = entervalidNumberinNumberofdays;
            EnterMessage = enterMessage;
            SelectTags = selectTags;
            Areyousuretosaverecord = areyousuretosaverecord;
            SelectNotificationtriggereveryvalue = selectNotificationtriggereveryvalue;
        }

        function ValidateControl() {
            if (document.getElementById('ctl00_BodyContentPH_txtReceivers').value == "") {
                alert(ChooseSMSReceiver);
                return false;
            }
            if (document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Late Entry"
                || document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Early Exit"
                || document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Less Hours Worked"
                || document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Continuous Absent"
                || document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Absent - Single Day"
            ) {
                if (document.getElementById('ctl00_BodyContentPH_txtlateNotification').value == "") {
                    alert(SelectNotificationtriggeraftervalue);
                    document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.focus();
                    return false;
                }
                if (document.getElementById('ctl00_BodyContentPH_txtlateNotification').value != "") {
                    var splittedValue = document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.value.split(":");
                    if (splittedValue.length < 2) {
                        alert(EntervalidNotificationtriggeraftervalue);
                        document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.focus();
                        return false;
                    }
                    else if (splittedValue[0].length < 2) {
                        alert(EntervalidNotificationtriggeraftervalue);
                        document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.focus();
                        return false;
                    }
                    else if (splittedValue[1].length < 2) {
                        alert(EntervalidNotificationtriggeraftervalue);
                        document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.focus();
                        return false;
                    }
                    var HoursToMinutes = splittedValue[0] * 60;
                    HoursToMinutes = parseInt(HoursToMinutes) + parseInt(splittedValue[1]);
                    if (HoursToMinutes == 0) {
                        alert(EntervalidNotificationtriggeraftervalue);
                        document.aspnetForm.ctl00_BodyContentPH_txtlateNotification.focus();
                        return false;
                    }
                }
                if (document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Late Entry") {
                    if (document.getElementById('ctl00_BodyContentPH_txtContinuousLateEntry').value == "") {
                        alert(SelectNotificationtriggereveryvalue);
                        document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.focus();
                        return false;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_txtContinuousLateEntry').value != "") {
                        var splittedValue = document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.value.split(":");
                        if (splittedValue.length < 2) {
                            alert(EntervalidNotificationtriggereveryvalue);
                            document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.focus();
                            return false;
                        }
                        else if (splittedValue[0].length < 2) {
                            alert(EntervalidNotificationtriggereveryvalue);
                            document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.focus();
                            return false;
                        }
                        else if (splittedValue[1].length < 2) {
                            alert(EntervalidNotificationtriggereveryvalue);
                            document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.focus();
                            return false;
                        }
                        var HoursToMinutes = splittedValue[0] * 60;
                        HoursToMinutes = parseInt(HoursToMinutes) + parseInt(splittedValue[1]);
                        if (HoursToMinutes == 0) {
                            alert(EntervalidNotificationtriggereveryvalue);
                            document.aspnetForm.ctl00_BodyContentPH_txtContinuousLateEntry.focus();
                            return false;
                        }
                    }
                }
                if (document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Less Hours Worked") {
                    if (document.getElementById('ctl00_BodyContentPH_txtlessHoursLimit').value == "") {
                        alert(SelectLessHoursLimitation);
                        document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.focus();
                        return false;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_txtlessHoursLimit').value != "") {
                        var splittedValue = document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.value.split(":");
                        if (splittedValue.length < 2) {
                            alert(EntervalidLessHoursLimitation);
                            document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.focus();
                            return false;
                        }
                        else if (splittedValue[0].length < 2) {
                            alert(EntervalidLessHoursLimitation);
                            document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.focus();
                            return false;
                        }
                        else if (splittedValue[1].length < 2) {
                            alert(EntervalidLessHoursLimitation);
                            document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.focus();
                            return false;
                        }
                        var HoursToMinutes = splittedValue[0] * 60;
                        HoursToMinutes = parseInt(HoursToMinutes) + parseInt(splittedValue[1]);
                        if (HoursToMinutes == 0) {
                            alert(EntervalidLessHoursLimitation);
                            document.aspnetForm.ctl00_BodyContentPH_txtlessHoursLimit.focus();
                            return false;
                        }
                    }
                }
                if (document.getElementById('ctl00_BodyContentPH_txtTemplateName').value == "Continuous Absent") {
                    if (document.getElementById('ctl00_BodyContentPH_txtContinuousabsent').value == "") {
                        alert(EnterNumberofdaysfieldvalue);
                        return false;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_txtContinuousabsent').value == "0") {
                        alert(EntervalidNumberinNumberofdays);
                        return false;
                    }
                }
            }
            if (document.getElementById('ctl00_BodyContentPH_txtMessage').value == "") {
                alert(EnterMessage);
                return false;
            }
            if (document.getElementById('ctl00_BodyContentPH_txtTags').value == "") {
                alert(SelectTags);
                return false;
            }
            return confirm(Areyousuretosaverecord);
        }
        function insertAtCursor(myValue) {
            var EmployeeID = ["787", "788"];
            var EmployeeName = ["Sample1", "Sample2"];
            var LateHours = ["01:00", "00:30"];
            myField = document.getElementById('<%= txtTags.ClientID %>');
        var e = document.getElementById('<%= ddlTags.ClientID %>');
        myValue = e.options[e.selectedIndex].value;
        if (myValue != '0') {
            textAreaScrollPosition = myField.scrollTop;
            if (document.selection) {
                myField.focus();
                sel = document.selection.createRange();
                sel.text = myValue;
            }
            else if (myField.selectionStart || myField.selectionStart == '0') {
                myField.focus();
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                if (startPos == 0) {
                    myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
                }
                else {
                    myField.value = myField.value.substring(0, startPos) + "-" + myValue + myField.value.substring(endPos, myField.value.length);
                }
            }
            else {
                myField.value += myValue;
            }
            myField.scrollTop = textAreaScrollPosition;
            document.getElementById('<%= ddlTags.ClientID %>').value = '0';
            document.getElementById('<%= ddlTags.ClientID %>').focus();
        }
        //        var Sample = document.getElementById('<%= txtMessage.ClientID %>').value + ' ' +  document.getElementById('<%= txtTags.ClientID %>').value;
        //        document.getElementById('ctl00_BodyContentPH_lblSampleData').innerHTML  = Sample;        
    }
    </script>

</asp:Content>
