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

<asp:Content ID="ConOrganizationYearSetting" ContentPlaceHolderID="BodyContentPH"
    runat="Server">

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

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

        window.onload = function () { Loaddropdown(); };
        var SelectStartMonth = "Select Start Month";
        var SelectStartYear = "Select Start Year";
        var SelectEndMonth = "Select End Month";
        var SelectEndYear = "Select End Year";
        var StartYearshouldnotbegreaterthanEndYear = "Start Year should not be greater than End Year";
        var StartMonthshouldnotbegreaterthanEndMonth = "Start Month should not be greater than End Month";
        var InvalidYearSetting = "Invalid Year Setting";
        var SelectaYeartoDelete = "Select a Year to Delete";
        var SelectedYearAlreadySetAsCurrentYear = "Selected year already set as current year";
        var AreYouSureToSaveYearSetting = "Are you sure to save Year Setting";
        var AreYouSureToDeleteTheSelectedYearSetting = "Are you sure to delete the selected Year Setting";
        var AreYouSureToSetTheSelectedYearAsCurrentYear = "Are you sure, to set the selected year as current year";
        var Theyearcreationexceedsthelimitof12months = "The year creation exceeds the limit of 12 months";
        function SetAlertMessages(selectStartMonth, selectStartYear, selectEndMonth, selectEndYear, startYearshouldnotbegreaterthanEndYear, startMonthshouldnotbegreaterthanEndMonth, invalidYearSetting, selectaYeartoDelete, selectedYearAlreadySetAsCurrentYear, areYouSureToSaveYearSetting, areYouSureToDeleteTheSelectedYearSetting, areYouSureToSetTheSelectedYearAsCurrentYear, theyearcreationexceedsthelimitof12months) {
            SelectStartMonth = selectStartMonth;
            SelectStartYear = selectStartYear;
            SelectEndMonth = selectEndMonth;
            SelectEndYear = selectEndYear;
            StartYearshouldnotbegreaterthanEndYear = startYearshouldnotbegreaterthanEndYear;
            StartMonthshouldnotbegreaterthanEndMonth = startMonthshouldnotbegreaterthanEndMonth;
            InvalidYearSetting = invalidYearSetting;
            SelectaYeartoDelete = selectaYeartoDelete;
            SelectedYearAlreadySetAsCurrentYear = selectedYearAlreadySetAsCurrentYear;
            AreYouSureToSaveYearSetting = areYouSureToSaveYearSetting;
            AreYouSureToDeleteTheSelectedYearSetting = areYouSureToDeleteTheSelectedYearSetting;
            AreYouSureToSetTheSelectedYearAsCurrentYear = areYouSureToSetTheSelectedYearAsCurrentYear;
            Theyearcreationexceedsthelimitof12months = theyearcreationexceedsthelimitof12months;
        }

        function yearSettingValidation() {
            var StartMonthIndex = document.getElementById('ctl00_BodyContentPH_ddlStartMonth').selectedIndex;
            var StartYearIndex = document.getElementById('ctl00_BodyContentPH_ddlStartYear').selectedIndex;
            var EndMonthIndex = document.getElementById('ctl00_BodyContentPH_ddlEndMonth').selectedIndex;
            var EndYearIndex = document.getElementById('ctl00_BodyContentPH_ddlEndYear').selectedIndex;
            if (document.getElementById('ctl00_BodyContentPH_ddlStartMonth').selectedIndex == 0) {
                alert(SelectStartMonth);
                return false;
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlStartYear').selectedIndex == 0) {
                alert(SelectStartYear);
                return false;
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlEndMonth').selectedIndex == 0) {
                alert(SelectEndMonth);
                return false;
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlEndYear').selectedIndex == 0) {
                alert(SelectEndYear);
                return false;
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlStartYear').options[StartYearIndex].value > document.getElementById('ctl00_BodyContentPH_ddlEndYear').options[EndYearIndex].value) {
                alert(StartYearshouldnotbegreaterthanEndYear);
                return false;
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlStartYear').options[StartYearIndex].value == document.getElementById('ctl00_BodyContentPH_ddlEndYear').options[EndYearIndex].value) {
                if (parseFloat(document.getElementById('ctl00_BodyContentPH_ddlStartMonth').options[StartMonthIndex].value) > parseFloat(document.getElementById('ctl00_BodyContentPH_ddlEndMonth').options[EndMonthIndex].value)) {
                    alert(StartMonthshouldnotbegreaterthanEndMonth);
                    return false;
                }
                else if (document.getElementById('ctl00_BodyContentPH_ddlStartMonth').options[StartMonthIndex].value == document.getElementById('ctl00_BodyContentPH_ddlEndMonth').options[EndMonthIndex].value) {
                    alert(InvalidYearSetting);
                    return false;
                }
            }
            else if (document.getElementById('ctl00_BodyContentPH_ddlStartYear').options[StartYearIndex].value != document.getElementById('ctl00_BodyContentPH_ddlEndYear').options[EndYearIndex].value) {
                if (document.getElementById('ctl00_BodyContentPH_ddlStartMonth').options[StartMonthIndex].value != 0) {
                    var intStartMonth;
                    var intStartMonthCount;
                    var intEndMonth;
                    var intEndMonthCount;
                    var intSumStartMonthCount = 1
                    var intSumEndMonthCount = 1
                    intStartMonth = parseInt(document.getElementById('ctl00_BodyContentPH_ddlStartMonth').options[StartMonthIndex].value);

                    for (var i = intStartMonth; i < 12; i++) {
                        intSumStartMonthCount = intSumStartMonthCount + 1;
                    }
                    if (document.getElementById('ctl00_BodyContentPH_ddlEndMonth').options[EndMonthIndex].value != 0) {
                        intEndMonth = parseInt(document.getElementById('ctl00_BodyContentPH_ddlEndMonth').options[EndMonthIndex].value);

                        for (var j = 1; j < intEndMonth; j++) {
                            intSumEndMonthCount = intSumEndMonthCount + 1;
                        }
                    }
                    else {
                        alert(SelectEndMonth);
                        return false;
                    }
                    var TotalMonthCount;
                    TotalMonthCount = parseInt(intSumStartMonthCount) + parseInt(intSumEndMonthCount);

                    if (TotalMonthCount > 12) {
                        alert(Theyearcreationexceedsthelimitof12months);
                        return false;
                    }
                }
                else {
                    alert(SelectStartMonth);
                    return false;
                }
            }
            if (confirm(AreYouSureToSaveYearSetting)) {
            }
            else {
                return false;
            }
        }
        function ShowWindow() {
            document.getElementById('div_CreateYear').style.display = 'block';
            document.getElementById('div_Mainwin').style.display = 'none';
            return false;
        }
        function Hidewindow() {
            document.getElementById('div_CreateYear').style.display = 'none';
            document.getElementById('div_Mainwin').style.display = 'block';
            return false;
        }
        function checklistSelected() {
            var listIndex = document.getElementById('ctl00_BodyContentPH_lst_Currentyear').selectedIndex;
            if (listIndex == -1) {
                alert(SelectaYeartoDelete);
                return false;
            }
            if (confirm(AreYouSureToDeleteTheSelectedYearSetting)) {
            }
            else {
                return false;
            }
        }
        function checkYearChanged() {
            if (document.getElementById('ctl00_BodyContentPH_lst_Currentyear').value == document.getElementById('ctl00_BodyContentPH_hdnActiveYear').value) {
                alert(SelectedYearAlreadySetAsCurrentYear);
                return false;
            }
            if (confirm(AreYouSureToSetTheSelectedYearAsCurrentYear)) {
            }
            else {
                return false;
            }
        }

        function CheckWeekOff() {
            if (document.getElementById('ctl00_BodyContentPH_chkShift').checked == true)
            { document.getElementById('ctl00_BodyContentPH_pnlWeekOff').style.display = 'block'; }
            else
            { document.getElementById('ctl00_BodyContentPH_pnlWeekOff').style.display = 'none'; }
            return false;
        }
    </script>

    <div class="content-header">
        <h1 style="background-image: url('../dist/img/YearSettings.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 pull-left">
                    <asp:Label ID="lbl_ActiveYear" runat="server" Font-Bold="true" Height="36px" Style="font-family: Arial Rounded MT Bold,Arial,Helvetica,sans-serif; color: #5d5d5d; padding-top: 10px; padding-left: 20px; padding-right: 20px;"></asp:Label>
                </div>
            </div>
        </div>
        <div class="emp-filter">
            <div class="form-horizontal">
                <div id="div_Mainwin">
                    <div class="panel-body">
                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_currentyear" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-6">
                                <asp:ListBox Style="height: 150px" ID="lst_Currentyear" runat="server" CssClass="form-control"></asp:ListBox>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-8">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="btn_Createyear" CssClass="btn add-btn fa-plus" OnClientClick="return ShowWindow()"
                                        runat="server" />
                                    <asp:LinkButton ID="btn_SetCurrentyear" CssClass="btn save-btn fa-check-circle" runat="server"
                                        OnClick="btn_SetCurrentyear_Click1" OnClientClick="javascript:return checkYearChanged();" />
                                    <asp:LinkButton ID="btn_DeleteYear" CssClass="btn  save-btn fa-trash-o" runat="server"
                                        OnClick="btn_DeleteYear_Click" OnClientClick="javascript:return checklistSelected();" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="div_CreateYear" style="display: none;">
                    <div class="row form-group">
                        <div class="col-md-2">
                            <asp:Label ID="lbl_startmonth" runat="server"></asp:Label>
                        </div>
                        <div class="col-md-3">
                            <asp:DropDownList ID="ddlStartMonth" runat="server" CssClass="form-control select2">
                            </asp:DropDownList>
                        </div>
                        <div class="col-md-3">
                            <asp:DropDownList ID="ddlStartYear" runat="server" CssClass="form-control select2">
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-2">
                            <asp:Label ID="lbl_EndMonth" runat="server"></asp:Label>
                        </div>
                        <div class="col-md-3">
                            <asp:DropDownList ID="ddlEndMonth" runat="server" CssClass="form-control select2">
                            </asp:DropDownList>
                        </div>
                        <div class="col-md-3">
                            <asp:DropDownList ID="ddlEndYear" runat="server" CssClass="form-control select2">
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <asp:CheckBox runat="server" ID="chkHoliday" CssClass="checkbox checkbox-primary" />
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <asp:CheckBox runat="server" ID="chkShift" CssClass="checkbox checkbox-primary" onchange="return CheckWeekOff()" />
                        </div>
                    </div>
                    <div class="col-md-12" runat="server" id="pnlWeekOff" style="display: none;">
                        <div class="form-group src-padbottomMargin">
                            <div class="col-md-2">
                                <asp:Label ID="lblWeeklyOffDays" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-10 pad-left-10px">
                                <div class="col-md-2">
                                    <asp:CheckBoxList ID="lstWeeklyOffDays" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal"
                                        CssClass="checkbox checkbox-primary" Visible="false">
                                    </asp:CheckBoxList>
                                    <asp:CheckBox ID="ChbMonday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbTuesday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbWednesday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbThuday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                            </div>
                        </div>
                        <div class="form-group src-padTopMargin">
                            <div class="col-md-2">
                            </div>
                            <div class="col-md-10 pad-left-10px">
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbFriday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbSaturday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                                <div class="col-md-2">
                                    <asp:CheckBox ID="ChbSunday" runat="server" CssClass="checkboxShift checkboxShift-primary" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2">
                        </div>
                        <div class="col-md-6">
                            <div class="pull-right-button">
                                <asp:LinkButton ID="btn_Add" CssClass="btn save-btn fa-floppy-o" runat="server" OnClick="btn_Add_Click"
                                    OnClientClick="javascript:return yearSettingValidation();" />
                                <asp:LinkButton ID="btn_Cancel" CssClass="btn save-btn  fa-times" runat="server"
                                    OnClick="btn_Cancel_Click" />
                                <asp:HiddenField ID="hdnSelectedYear" runat="server" />
                                <asp:HiddenField ID="hdnActiveYear" runat="server" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
