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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="Server">
    <!--[if gt IE 5.5]>
	<link rel="stylesheet" type="text/css" href="../css/ProgressforIE.css" />
 <![endif]-->

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

    <script src="../js/maxLength.js" type="text/javascript"></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>

    <script>
        $(function () {
            $('#ctl00_BodyContentPH_txtHalfDayComoff').datetimepicker({ format: 'HH:mm' }
          );
        });
        $(function () {
            $('#ctl00_BodyContentPH_txtFullDayComoff').datetimepicker({ format: 'HH:mm' }
          );
        });
    </script>

    <script language="javascript" type="text/javascript">
        var SelectOvertimetype = "Select Overtime type Day wise or Hour wise";
        var EnterMinimumOTHours = "Enter Minimum OT Hours";
        var EnterPolicyName = "Enter Policy Name";
        var ConfirmSave = "Are you sure, to save?";
        var SpellYearNotEmpty = "Spell/Year should not be empty";
        var ApplyLeaveForLeavePolicy = "Please Apply any one of Leave Type for Leave Policy";
        var AppDaysNotEmpty = "Applicable Days/Year should not be empty";
        var MaxDaysPerSpellNotEmpty = "Max Days/Spell should not be empty";
        var EntervalidMaximumHours = "Enter valid Maximum Hours per Month";
        var CalcFactor = "Calc Factor Should be lesser than Min Work Days";
        var EnterPermissionHours = "Enter permission hours";
        var EnterMaximunPermissionHrsPerMonth = "Enter the Maximun Permission Hrs per month";
        var EnterMaximunNoOfInstance = "Enter the Maximun no of Instance per month";
        var EnterMaximunPermissionHrsPerInstance = "Enter the Maximun Permission Hrs per instance";
        var EntervalidTime = "Enter valid Time";
        var AppDaysNotZero = "App Days should not be zero";
        var InvalidAppDays = "Invalid App Days";
        var MaxValue_AppDays_365 = "Maximum Value of App Days is 365";
        var MaxDaysPerSpellNotZero = "Max Days/Spell should not be zero";
        var InvalidMaxDaysPerSpell = "Invalid Max Days/Spell";
        var MaxValue_MaxDaysPerSpell_365 = "Maximum Value of Max Days/Spell is 365";
        var MinDaysPerSpellNotZero = "Min Days/Spell should not be zero";
        var InvalidMinDaysPerSpell = "Invalid Min Days/Spell";
        var MaxValue_MinDaysPerSpell_365 = "Maximum Value of Min Days/Spell is 365";
        var MinDaysPerSpellNotEmpty = "Min Days/Spell should not be empty";
        var MaxDaysLesserThanAppDays = "Max Days/Spell Should be lesser than App Days";
        var MinDaysLesserThanAppDays = "Min Days/Spell Should be lesser than App Days";
        var SpellsPerYearLesserThanAppDays = "Spells per year Should be lesser than App Days";
        var MinDaysLesserThanMaxDays = "Min Days/Spell Should be lesser than Max Days/Spell";
        var MaxLOPNotZero = "Max LOP should not be zero";
        var InvalidMaxLOP = "Invalid Max LOP";
        var MaxValue_MaxLOP_365 = "Maximum Value of Max LOP is 365";
        var MaxLOPNotEmpty = "Max LOP should not be empty";
        var MaxAccDaysNotZero = "Max Acc Days should not be zero";
        var InvalidMaxAccDays = "Invalid Max Acc Days";
        var MaxValue_MaxAccDays_365 = "Maximum Value of Max Acc Days is 365";
        var AppAfterDaysNotZero = "App After Days should not be zero";
        var InvalidAppAfterDays = "Invalid App After Days";
        var MaxValue_AppAfterDays_365 = "Maximum Value of App After Days is 365";
        var CalcFactorNotZero = "Calc Factor should not be zero";
        var InvalidCalcFactor = "Invalid Calc Factor";
        var MaxValue_CalcFactor_365 = "Maximum Value of Calc Factor is 365";
        var CalcFactorNotEmpty = "Calc Factor should not be empty";
        var MinWorkDaysNotZero = "Min Work Days should not be zero";
        var InvalidMinWorkDays = "Invalid Min Work Days";
        var MaxValue_WorkDay_365 = "Maximum Value of Min Work Days is 365";
        var MinWorkDaysNotEmpty = "Min Work Days should not be empty";
        var MaxLength = "Maximum length is ";
        var Permission = "Enter in hh:mm format";
        var EnterHalfDayComoff = "Enter Min Extra Hrs for Half Day Comp Off";
        var EnterFullDayComoff = "Enter Min Extra Hrs for Full Day Comp Off";
        var EnterValidsDays = "Enter Comp Off Validity Days";
        var FullDayCompOffLessThenHalfDay = 'Full Day Comp Off Not Less Then Half Day Comp Off'
        var ClickviewButtonandproceed = 'Click view Button and proceed';
        var SelectValidOptionClickSave = 'Select Valid Option in above and Then Click Save';
        var EnterValidPermissionHours = "Enter Valid Permission Hours";
        function chkPermission(permission) {
            Permission = permission;
        }
        function MaxLengthh(maxLength) {
            MaxLength = maxLength;
        }
        function SetAlertMessages
        (
            selectOvertimetype,
            enterMinimumOTHours,
            enterPolicyName,
            confirmSave,
            spellYearNotEmpty,
            applyLeaveForLeavePolicy,
            appDaysNotEmpty,
            maxDaysPerSpellNotEmpty,
            entervalidMaximumHours,
            calcFactor,
            enterPermissionHours,
            enterMaximunPermissionHrsPerMonth,
            enterMaximunNoOfInstance,
            enterMaximunPermissionHrsPerInstance,
            entervalidTime,
            appDaysNotZero,
            invalidAppDays,
            maxValue_AppDays_365,
            maxDaysPerSpellNotZero,
            invalidMaxDaysPerSpell,
            maxValue_MaxDaysPerSpell_365,
            minDaysPerSpellNotZero,
            invalidMinDaysPerSpell,
            maxValue_MinDaysPerSpell_365,
            minDaysPerSpellNotEmpty,
            maxDaysLesserThanAppDays,
            minDaysLesserThanAppDays,
            spellsPerYearLesserThanAppDays,
            minDaysLesserThanMaxDays,
            maxLOPNotZero,
            invalidMaxLOP,
            maxValue_MaxLOP_365,
            maxLOPNotEmpty,
            maxAccDaysNotZero,
            invalidMaxAccDays,
            maxValue_MaxAccDays_365,
            appAfterDaysNotZero,
            invalidAppAfterDays,
            maxValue_AppAfterDays_365,
            calcFactorNotZero,
            invalidCalcFactor,
            maxValue_CalcFactor_365,
            calcFactorNotEmpty,
            minWorkDaysNotZero,
            invalidMinWorkDays,
            maxValue_WorkDay_365,
            minWorkDaysNotEmpty,
            strHalfDayComoff,
            strFullDayComoff,
            strValidsDays,
            VaildHalfDayCompOff,
            clickviewButtonandproceed,
            selectValidOptionClickSave,
            enterValidPermissionHours
        ) {
            SelectOvertimetype = selectOvertimetype;
            EnterMinimumOTHours = enterMinimumOTHours;
            EnterPolicyName = enterPolicyName;
            ConfirmSave = confirmSave;
            SpellYearNotEmpty = spellYearNotEmpty;
            ApplyLeaveForLeavePolicy = applyLeaveForLeavePolicy;
            AppDaysNotEmpty = appDaysNotEmpty;
            MaxDaysPerSpellNotEmpty = maxDaysPerSpellNotEmpty;
            EntervalidMaximumHours = entervalidMaximumHours;
            CalcFactor = calcFactor;
            EnterPermissionHours = enterPermissionHours;
            EnterMaximunPermissionHrsPerMonth = enterMaximunPermissionHrsPerMonth;
            EnterMaximunNoOfInstance = enterMaximunNoOfInstance;
            EnterMaximunPermissionHrsPerInstance = enterMaximunPermissionHrsPerInstance;
            EntervalidTime = entervalidTime;
            AppDaysNotZero = appDaysNotZero;
            InvalidAppDays = invalidAppDays;
            MaxValue_AppDays_365 = maxValue_AppDays_365;
            MaxDaysPerSpellNotZero = maxDaysPerSpellNotZero;
            InvalidMaxDaysPerSpell = invalidMaxDaysPerSpell;
            MaxValue_MaxDaysPerSpell_365 = maxValue_MaxDaysPerSpell_365;
            MinDaysPerSpellNotZero = minDaysPerSpellNotZero;
            InvalidMinDaysPerSpell = invalidMinDaysPerSpell;
            MaxValue_MinDaysPerSpell_365 = maxValue_MinDaysPerSpell_365;
            MinDaysPerSpellNotEmpty = minDaysPerSpellNotEmpty;
            MaxDaysLesserThanAppDays = maxDaysLesserThanAppDays;
            MinDaysLesserThanAppDays = minDaysLesserThanAppDays;
            SpellsPerYearLesserThanAppDays = spellsPerYearLesserThanAppDays;
            MinDaysLesserThanMaxDays = minDaysLesserThanMaxDays;
            MaxLOPNotZero = maxLOPNotZero;
            InvalidMaxLOP = invalidMaxLOP;
            MaxValue_MaxLOP_365 = maxValue_MaxLOP_365;
            MaxLOPNotEmpty = maxLOPNotEmpty;
            MaxAccDaysNotZero = maxAccDaysNotZero;
            InvalidMaxAccDays = invalidMaxAccDays;
            MaxValue_MaxAccDays_365 = maxValue_MaxAccDays_365;
            AppAfterDaysNotZero = appAfterDaysNotZero;
            InvalidAppAfterDays = invalidAppAfterDays;
            MaxValue_AppAfterDays_365 = maxValue_AppAfterDays_365;
            CalcFactorNotZero = calcFactorNotZero;
            InvalidCalcFactor = invalidCalcFactor;
            MaxValue_CalcFactor_365 = maxValue_CalcFactor_365;
            CalcFactorNotEmpty = calcFactorNotEmpty;
            MinWorkDaysNotZero = minWorkDaysNotZero;
            InvalidMinWorkDays = invalidMinWorkDays;
            MaxValue_WorkDay_365 = maxValue_WorkDay_365;
            MinWorkDaysNotEmpty = minWorkDaysNotEmpty;
            EnterHalfDayComoff = strHalfDayComoff;
            EnterFullDayComoff = strFullDayComoff;
            EnterValidsDays = strValidsDays;
            FullDayCompOffLessThenHalfDay = VaildHalfDayCompOff;
            ClickviewButtonandproceed = clickviewButtonandproceed;
            SelectValidOptionClickSave = selectValidOptionClickSave;
            EnterValidPermissionHours = enterValidPermissionHours;
        }
        function CheckOverTimeType() {
            if (document.getElementById("ctl00_BodyContentPH_chkOverTimeType").checked == true) {
                document.getElementById("ctl00_BodyContentPH_rbt_HourWise").disabled = false;
                document.getElementById("ctl00_BodyContentPH_rbt_DayWise").disabled = false;
                document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").disabled = false;
                document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").disabled = false;
                document.getElementById("ctl00_BodyContentPH_txtValidsDays").disabled = false;
            }
            else {
                document.getElementById("ctl00_BodyContentPH_rbt_HourWise").disabled = true;
                document.getElementById("ctl00_BodyContentPH_rbt_DayWise").disabled = true;
                document.getElementById("ctl00_BodyContentPH_rbt_DayWise").checked = false;
                document.getElementById("ctl00_BodyContentPH_rbt_HourWise").checked = false;
                document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").value = '';
                document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").value = '';
                document.getElementById("ctl00_BodyContentPH_txtValidsDays").value = '';
                document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").disabled = true;
                document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").disabled = true;
                document.getElementById("ctl00_BodyContentPH_txtValidsDays").disabled = true;
                document.getElementById("ctl00_BodyContentPH_hdfOTHourType").value = "0";
                document.getElementById("ctl00_BodyContentPH_hdfOTDayType").value = "0";
            }
        }
        function CheckPermission() {
            if (document.getElementById("ctl00_BodyContentPH_chkPermission").checked == true) {
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").disabled = false;
                document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").disabled = false;
                document.getElementById("ctl00_BodyContentPH_butBeforeShiftMax").disabled = false;
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstanceHdn").value = "";
                document.getElementById("ctl00_BodyContentPH_chkBeforeLeave").disabled = false;
                document.getElementById("ctl00_BodyContentPH_chkAfterLeave").disabled = false;
                document.getElementById("ctl00_BodyContentPH_chkBeforeLeave").checked = false;
                document.getElementById("ctl00_BodyContentPH_chkAfterLeave").checked = false;
            }
            else {
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").disabled = true;
                document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").disabled = true;
                document.getElementById("ctl00_BodyContentPH_butBeforeShiftMax").disabled = true;
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").value = "";
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstanceHdn").value = "";
                document.getElementById("ctl00_BodyContentPH_chkBeforeLeave").checked = false;
                document.getElementById("ctl00_BodyContentPH_chkAfterLeave").checked = false;
                document.getElementById("ctl00_BodyContentPH_chkBeforeLeave").disabled = true;
                document.getElementById("ctl00_BodyContentPH_chkAfterLeave").disabled = true;
            }
        }
        function ValidatePermissionHrs() {
            if (document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsMonth.value != "") {
                var hrsvalue = document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsMonth.value;
                var hrs = hrsvalue.substring(0, 2);
                var mins = hrsvalue.substring(3, 5);
                var minsvalue = parseFloat(hrs) * 60;
                minsvalue = parseFloat(minsvalue) + parseFloat(mins);
                var ins = document.aspnetForm.ctl00_BodyContentPH_txt_MaxInstances.value;
                var resHr = parseFloat(minsvalue) / parseFloat(ins);
                var resMin = parseFloat(minsvalue) % parseFloat(ins);
                var h = Math.floor(parseInt(resHr) / 60);
                var m = Math.ceil(parseFloat(resHr) % 60);
                if (m >= 60) {
                    h = h + 1;
                    m = 0;
                }
                if (h < 10) {
                    h = '0' + h;
                }
                if (m < 10) {
                    m = '0' + m;
                }
                if (hrsvalue.length == 5 && ins.length == 1) {
                    document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").value = h + ":" + m;
                    document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstanceHdn").value = h + ":" + m;
                }
            }
            return true;
        }
        function Validate() {
            if (document.getElementById("ctl00_BodyContentPH_chkOverTimeType").checked == true) {
                if (document.getElementById("ctl00_BodyContentPH_rbt_DayWise").checked == false && document.getElementById("ctl00_BodyContentPH_rbt_HourWise").checked == false) {
                    alert(SelectOvertimetype);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").value == "") {
                    alert(EnterFullDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").value == "") {
                    alert(EnterHalfDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtValidsDays").value == "") {
                    alert(EnterValidsDays);
                    return false;
                }
            }
            var permHrsMonth = document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsMonth.value;
            var ins = document.aspnetForm.ctl00_BodyContentPH_txt_MaxInstances.value;
            var permHrsIns = document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsInstance.value;
            if ((/^(\s*)$/.test(document.aspnetForm.ctl00_BodyContentPH_txt_PolicyName.value))) {
                alert(EnterPolicyName);
                document.getElementById("ctl00_BodyContentPH_txt_PolicyName").focus();
                return false;
            }
            if (document.aspnetForm.ctl00_BodyContentPH_txt_PolicyName.value == "") {
                alert(EnterPolicyName);
                document.getElementById("ctl00_BodyContentPH_txt_PolicyName").focus();
                return false;
            }
            if (document.getElementById("ctl00_BodyContentPH_rbt_HourWise").checked == true || document.getElementById("ctl00_BodyContentPH_rbt_DayWise").checked == true) {
                if (document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").value == "") {
                    alert(EnterFullDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").value == "") {
                    alert(EnterHalfDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtValidsDays").value == "") {
                    alert(EnterValidsDays);
                    return false;
                }
            }
            if (permHrsMonth == "" && ins == "" && permHrsIns == "") {
                return confirm(ConfirmSave);
            }
            else {
                if (permHrsMonth == "") {
                    alert(EnterMaximunPermissionHrsPerMonth);
                    document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").focus();
                    return false;
                }
                if (ins == "") {
                    alert(EnterMaximunNoOfInstance);
                    document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").focus();
                    return false;
                }
                if (permHrsIns == "") {
                    alert(EnterMaximunPermissionHrsPerInstance);
                    document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").focus();
                    return false;
                }
            }
            return confirm(ConfirmSave);
        }
        function validatePermissionMonth() {
            //Modified By Thilak
            var reExHoursMinitues = /^([0-9][0-9]|[2][0-3]):([0-5][0-9])$/;
            var HrsMonth;
            HrsMonth = document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").value;
            if (HrsMonth != '' && HrsMonth != '__:__') {
                if (document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").value.search(reExHoursMinitues) == -1) {
                    alert(EntervalidMaximumHours);
                    document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").focus();
                    return false;
                }
            }
            else {
                document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").value = '';
                document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").value = '';
            }
        }
        function ValidateAll() {
            var rangeDemoFormat = "HH:mm";
            if (document.getElementById("ctl00_BodyContentPH_hdfFilter").value == '0') {
                alert(ClickviewButtonandproceed);
                return false;
            }
            if (document.getElementById("ctl00_BodyContentPH_hdfFilter").value == '-1') {
                alert(SelectValidOptionClickSave);
                return false;
            }
            if ((/^(\s*)$/.test(document.aspnetForm.ctl00_BodyContentPH_txt_PolicyName.value))) {
                alert(EnterPolicyName);
                document.getElementById("ctl00_BodyContentPH_txt_PolicyName").focus();
                return false;
            }// end policy name empty
            var rowIndex = document.getElementById("ctl00_BodyContentPH_hdnLeaveCount").value;
            var isAnyOneChecked = false;
            var isValidMinWorkedDays = false;
            var isValidCalcFactorMinWorkDay = false;
            for (var rowid = 1; rowid <= rowIndex; rowid++) {
                if (document.getElementById("ctl00_BodyContentPH_Applicable" + rowid).checked == true) {
                    isAnyOneChecked = true;
                }
            }
            if (isAnyOneChecked == true) {
                for (var rowid = 1; rowid <= rowIndex; rowid++) {
                    if (document.getElementById("ctl00_BodyContentPH_Applicable" + rowid).checked == true) {
                        var appDay = document.getElementById("ctl00_BodyContentPH_total" + rowid).value;
                        var maxDay = document.getElementById("ctl00_BodyContentPH_Max" + rowid).value;
                        var minDay = document.getElementById("ctl00_BodyContentPH_Min" + rowid).value;
                        var spellYear = document.getElementById("ctl00_BodyContentPH_Spell" + rowid).value;
                        if (document.getElementById("ctl00_BodyContentPH_total" + rowid).disabled == true) {
                        }
                        else {
                            if (appDay == "") {
                                alert(AppDaysNotEmpty);
                                document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                                return false;
                            }
                        }
                        if (maxDay == "") {
                            alert(MaxDaysPerSpellNotEmpty);
                            document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                            return false;
                        }
                        if (minDay == "") {
                            alert(MinDaysPerSpellNotEmpty);
                            document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                            return false;
                        }
                        if (spellYear == "") {
                            alert(SpellYearNotEmpty);
                            document.getElementById("ctl00_BodyContentPH_Spell" + rowid).focus();
                            return false;
                        }
                        var isValidAppDay = false, isValidMaxDay = false, isValidMinDay = false;
                        // validate one by one all given value          
                        // validate App Days           
                        if (document.getElementById("ctl00_BodyContentPH_total" + rowid).disabled == true) {
                            isValidAppDay = true;
                        }
                        else {
                            isValidAppDay = ValidateAppDays(rowid);
                        }
                        // validate Max Days/Spell                              
                        isValidMaxDay = ValidateMaxDays(rowid);
                        // validate Min Days/Spell                              
                        isValidMinDay = ValidateMinDays(rowid);
                        //validate Max days/spell < App Days 
                        var isValidAppDayMaxDay = false;
                        if (document.getElementById("ctl00_BodyContentPH_total" + rowid).disabled == true) {
                            isValidAppDayMaxDay = true;
                        }
                        else {
                            if (isValidAppDay == true && isValidMaxDay == true) {
                                isValidAppDayMaxDay = ValidateAppDaysMaxDays(rowid);
                            }
                            else {
                                return false;
                            }
                        }
                        //validate Min days/spell < Max value/spell           
                        var isValidMaxDayMinDay = false;
                        if (isValidAppDay == true && isValidMaxDay == true && isValidMinDay == true) {
                            isValidMaxDayMinDay = ValidateMaxDaysMinDays(rowid);
                        }
                        else {
                            return false;
                        }
                        //validate Min days/spell < App Days 
                        var isValidAppDayMinDay = false;
                        if (document.getElementById("ctl00_BodyContentPH_total" + rowid).disabled == true) {
                            isValidAppDayMinDay = true;
                        }
                        else {
                            if (isValidAppDayMaxDay == true && isValidMaxDayMinDay == true) {
                                isValidAppDayMinDay = ValidateAppDaysMinDays(rowid);
                            }
                            else {
                                return false;
                            }
                        }
                        // validate Spell/Year
                        var isValidSpellYear = false;
                        if (document.getElementById("ctl00_BodyContentPH_total" + rowid).disabled == true) {
                            isValidSpellYear = true;
                        }
                        else {
                            if (isValidAppDayMinDay == true) {
                                isValidSpellYear = ValidateSpellYear(rowid);
                            }
                            else {
                                return false;
                            }
                        }
                        // validate Max LOP                              
                        if (document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).disabled == false) {
                            // based on MaxLOP true or false
                            var isValidMaxLOP = false;
                            if (isValidSpellYear == true) {
                                isValidMaxLOP = ValidateMaxLOP(rowid);
                            }
                            else {
                                return false;
                            }
                            //validate MACC Days 
                            var isValidMACCDays = false;
                            if (isValidMaxLOP == true) {
                                isValidMACCDays = ValidateMACCDays(rowid);
                            }
                            else {
                                return false;
                            }
                            // validate App After Days
                            var isValidAppAfterDays = false;
                            if (isValidMACCDays == true) {
                                isValidAppAfterDays = ValidateAppAfterDays(rowid);
                            }
                            else {
                                return false;
                            }
                            if (isValidAppAfterDays == true) {
                                if (document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).disabled == true && document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).disabled == true) {
                                    isValidCalcFactorMinWorkDay = true;
                                }
                                else {
                                    // validate Calc Factor
                                    var isValidCalcFactor = false;
                                    if (isValidAppAfterDays == true) {
                                        isValidCalcFactor = ValidateCalcFactor(rowid);
                                    }
                                    else {
                                        return false;
                                    }
                                    // validate Min Worked days                  
                                    if (isValidCalcFactor == true) {
                                        isValidMinWorkedDays = ValidateMinWorkedDays(rowid);
                                    }
                                    else {
                                        return false;
                                    }
                                    if (isValidMinWorkedDays == true) {
                                        if (isValidCalcFactor == true && isValidMinWorkedDays == true) {
                                            isValidCalcFactorMinWorkDay = ValidateCalcFactorMinWorkDay(rowid);
                                        }
                                        else {
                                            return false;
                                        }
                                    }
                                    else {
                                        return false;
                                    }
                                    if (isValidCalcFactorMinWorkDay == true) {
                                        // continue for loop
                                    }
                                    else {
                                        return false;
                                    }
                                }
                            }// end isValidAppAfterDays true check 
                            else {
                                return false;
                            }
                        }// end Max LOP disabled checking
                        else {
                            // not based on MaxLOP true or false
                            //validate MACC Days 
                            var isValidMACCDays = false;
                            if (isValidSpellYear == true) {
                                isValidMACCDays = ValidateMACCDays(rowid);
                            }
                            else {
                                return false;
                            }
                            // validate App After Days
                            var isValidAppAfterDays = false;
                            if (isValidMACCDays == true) {
                                isValidAppAfterDays = ValidateAppAfterDays(rowid);
                            }
                            else {
                                return false;
                            }
                            if (isValidAppAfterDays == true) {
                                if (document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).disabled == true && document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).disabled == true) {
                                    isValidCalcFactorMinWorkDay = true;
                                }
                                else {
                                    // validate Calc Factor
                                    var isValidCalcFactor = false;
                                    if (isValidAppAfterDays == true) {
                                        isValidCalcFactor = ValidateCalcFactor(rowid);
                                    }
                                    else {
                                        return false;
                                    }
                                    // validate Min Worked days                  
                                    if (isValidCalcFactor == true) {
                                        isValidMinWorkedDays = ValidateMinWorkedDays(rowid);
                                    }
                                    else {
                                        return false;
                                    }
                                    if (isValidMinWorkedDays == true) {
                                        if (isValidCalcFactor == true && isValidMinWorkedDays == true) {
                                            isValidCalcFactorMinWorkDay = ValidateCalcFactorMinWorkDay(rowid);
                                        }
                                        else {
                                            return false;
                                        }
                                    }
                                    else {
                                        return false;
                                    }
                                    if (isValidCalcFactorMinWorkDay == true) {
                                        // continue for loop
                                    }
                                    else {
                                        return false;
                                    }
                                }
                            }// end isValidAppAfterDays true check 
                            else {
                                return false;
                            }
                        }
                    }
                    else {
                        // nothing checked                
                    }
                }// end for loop             
            }// end any one checked true
            else {
                alert(ApplyLeaveForLeavePolicy);
                return false;
            }
            if (isValidCalcFactorMinWorkDay == true) {
                // validate permission setting
                var isValidPermission = ValiatePermissionSetting();
                // validate OT setting
                if (isValidPermission == true) {
                    var isValidOTSetting = ValidateOTSetting();
                    if (isValidOTSetting == true) {
                        return confirm(ConfirmSave);
                    }
                    else {
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }// end function
        // validate Calc Factor < Min Work Days
        function ValidateCalcFactorMinWorkDay(rowid) {
            var ctrl = "";
            ctrl += "ctl00_BodyContentPH_calcFactor" + rowid;
            var ctrl1 = "";
            ctrl1 += "ctl00_BodyContentPH_MinWorkedDays" + rowid;
            var val = parseFloat(document.getElementById(ctrl1).value)
            var val1 = parseFloat(document.getElementById(ctrl).value)
            if (val > 0 && val1 > 0) {
                if (val < val1) {
                    alert(CalcFactor);
                    document.getElementById(ctrl).focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        // validate permission setting
        function ValiatePermissionSetting() {
            var permHrsMonth = document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsMonth.value;
            var ins = document.aspnetForm.ctl00_BodyContentPH_txt_MaxInstances.value;
            var permHrsIns = document.aspnetForm.ctl00_BodyContentPH_txt_MaxHrsInstance.value;
            if (document.getElementById("ctl00_BodyContentPH_chkPermission").checked == true) {
                if (permHrsMonth == "" && ins == "" && permHrsIns == "") {
                    alert(EnterPermissionHours);
                    return false;
                }
                else {
                    if (permHrsMonth == "") {
                        alert(EnterPermissionHours);
                        document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").focus();
                        return false;
                    }
                    if (permHrsMonth == "00:00") {
                        alert(EnterValidPermissionHours);
                        document.getElementById("ctl00_BodyContentPH_txt_MaxHrsMonth").focus();
                        return false;
                    }
                    if (ins == "") {
                        alert(EnterMaximunNoOfInstance);
                        document.getElementById("ctl00_BodyContentPH_txt_MaxInstances").focus();
                        return false;
                    }
                    if (permHrsIns == "") {
                        alert(EnterMaximunPermissionHrsPerInstance);
                        document.getElementById("ctl00_BodyContentPH_txt_MaxHrsInstance").focus();
                        return false;
                    }
                }
                return true;
            }
            else {
                return true;
            }
        }
        // validate OT setting
        function ValidateOTSetting() {
            if (document.getElementById("ctl00_BodyContentPH_chkOverTimeType").checked == true) {
                if (document.getElementById("ctl00_BodyContentPH_rbt_DayWise").checked == false && document.getElementById("ctl00_BodyContentPH_rbt_HourWise").checked == false) {
                    alert(SelectOvertimetype);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").value == "") {
                    alert(EnterFullDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").value == "") {
                    alert(EnterHalfDayComoff);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_txtValidsDays").value == "") {
                    alert(EnterValidsDays);
                    return false;
                }
                if (document.getElementById("ctl00_BodyContentPH_rbt_HourWise").checked == true) {
                    document.getElementById("ctl00_BodyContentPH_hdfOTHourType").value = "1";
                }
                else {
                    document.getElementById("ctl00_BodyContentPH_hdfOTHourType").value = "0";
                }
                if (document.getElementById("ctl00_BodyContentPH_rbt_DayWise").checked == true) {
                    document.getElementById("ctl00_BodyContentPH_hdfOTDayType").value = "1";
                }
                else {
                    document.getElementById("ctl00_BodyContentPH_hdfOTDayType").value = "0";
                }
                var FullDay = document.getElementById("ctl00_BodyContentPH_txtFullDayComoff").value;
                var HalfDay = document.getElementById("ctl00_BodyContentPH_txtHalfDayComoff").value;
                if ((!(FullDay.match(/^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/))) || (!(HalfDay.match(/^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/)))) {
                    alert(EntervalidTime);
                    return false;
                }
                if ((FullDay.replace(':', '.')) < (HalfDay.replace(':', '.'))) {
                    alert(FullDayCompOffLessThenHalfDay);
                    return false;
                }
                return true;
            }
            else {
                document.getElementById("ctl00_BodyContentPH_hdfOTHourType").value = "0";
                document.getElementById("ctl00_BodyContentPH_hdfOTDayType").value = "0";
                return true;
            }
        }
        // validate App Days       
        function ValidateAppDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_total" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(AppDaysNotZero);
                    document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidAppDays);
                        document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_AppDays_365);
                    document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidAppDays);
                            document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(AppDaysNotEmpty);
                document.getElementById("ctl00_BodyContentPH_total" + rowid).focus();
                return false;
            }
            return true;
        }
        // validate Max Days       
        function ValidateMaxDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_Max" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(MaxDaysPerSpellNotZero);
                    document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidMaxDaysPerSpell);
                        document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_MaxDaysPerSpell_365);
                    document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidMaxDaysPerSpell);
                            document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(MaxDaysPerSpellNotEmpty);
                document.getElementById("ctl00_BodyContentPH_Max" + rowid).focus();
                return false;
            }
            return true;
        }
        // validate Min Days       
        function ValidateMinDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_Min" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(MinDaysPerSpellNotZero);
                    document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidMinDaysPerSpell);
                        document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_MinDaysPerSpell_365);
                    document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidMinDaysPerSpell);
                            document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(MinDaysPerSpellNotEmpty);
                document.getElementById("ctl00_BodyContentPH_Min" + rowid).focus();
                return false;
            }
            return true;
        }
        //validate Max days/spell < App Days 
        function ValidateAppDaysMaxDays(rowid) {
            var ctrl = "";
            ctrl += "ctl00_BodyContentPH_total" + rowid;
            var ctrl1 = "";
            ctrl1 += "ctl00_BodyContentPH_Max" + rowid;
            var val = parseFloat(document.getElementById(ctrl1).value)
            var val1 = parseFloat(document.getElementById(ctrl).value)
            if (val > 0 && val1 > 0) {
                if (val > val1) {
                    alert(MaxDaysLesserThanAppDays);
                    document.getElementById(ctrl1).focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        //validate Min days/spell < App Days 
        function ValidateAppDaysMinDays(rowid) {
            var ctrl = "";
            ctrl += "ctl00_BodyContentPH_total" + rowid;
            var ctrl1 = "";
            ctrl1 += "ctl00_BodyContentPH_Min" + rowid;
            var val = parseFloat(document.getElementById(ctrl1).value)
            var val1 = parseFloat(document.getElementById(ctrl).value)
            if (val > 0 && val1 > 0) {
                if (val > val1) {
                    alert(MinDaysLesserThanAppDays);
                    document.getElementById(ctrl1).focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        // validate Spell/Year
        function ValidateSpellYear(rowid) {
            var ctrl = "";
            ctrl += "ctl00_BodyContentPH_total" + rowid;
            var ctrl1 = "";
            ctrl1 += "ctl00_BodyContentPH_Spell" + rowid;
            var ctrl3 = "";
            ctrl3 += "ctl00_BodyContentPH_Min" + rowid;
            var val3 = parseFloat(document.getElementById(ctrl3).value)
            var val = parseFloat(document.getElementById(ctrl1).value)
            var val1 = parseFloat(document.getElementById(ctrl).value)
            if (val < (val1 / val3)) {
                alert(SpellsPerYearLesserThanAppDays);
                document.getElementById(ctrl1).focus();
                return false;
            }
            else {
                return true;
            }
            //return true;                
        }
        //validate Min days/spell < Max value/spell  
        function ValidateMaxDaysMinDays(rowid) {
            var ctrl = "";
            ctrl += "ctl00_BodyContentPH_Max" + rowid;
            var ctrl1 = "";
            ctrl1 += "ctl00_BodyContentPH_Min" + rowid;
            var val = parseFloat(document.getElementById(ctrl1).value)
            var val1 = parseFloat(document.getElementById(ctrl).value)
            if (val > 0 && val1 > 0) {
                if (val > val1) {
                    alert(MinDaysLesserThanMaxDays);
                    document.getElementById(ctrl1).focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        // validate Max LOP                              
        function ValidateMaxLOP(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(MaxLOPNotZero);
                    document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidMaxLOP);
                        document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_MaxLOP_365);
                    document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidMaxLOP);
                            document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(MaxLOPNotEmpty);
                document.getElementById("ctl00_BodyContentPH_MaxLOP" + rowid).focus();
                return false;
            }
            return true;
        }
        function ValidateMACCDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_Acc" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(MaxAccDaysNotZero);
                    document.getElementById("ctl00_BodyContentPH_Acc" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidMaxAccDays);
                        document.getElementById("ctl00_BodyContentPH_Acc" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_MaxAccDays_365);
                    document.getElementById("ctl00_BodyContentPH_Acc" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidMaxAccDays);
                            document.getElementById("ctl00_BodyContentPH_Acc" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking        
            return true;
        }
        function ValidateAppAfterDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_AppAfter" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(AppAfterDaysNotZero);
                    document.getElementById("ctl00_BodyContentPH_AppAfter" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidAppAfterDays);
                        document.getElementById("ctl00_BodyContentPH_AppAfter" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 730) {
                    alert(MaxValue_AppAfterDays_365);
                    document.getElementById("ctl00_BodyContentPH_AppAfter" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidAppAfterDays);
                            document.getElementById("ctl00_BodyContentPH_AppAfter" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking        
            return true;
        }
        // validate Calc Factor
        function ValidateCalcFactor(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(CalcFactorNotZero);
                    document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidCalcFactor);
                        document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_CalcFactor_365);
                    document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidCalcFactor);
                            document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(CalcFactorNotEmpty);
                document.getElementById("ctl00_BodyContentPH_calcFactor" + rowid).focus();
                return false;
            }
            return true;
        }
        // validate Min Worked Days
        function ValidateMinWorkedDays(rowid) {
            var appDay = document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).value;
            if (appDay != "") {
                if ((appDay == 0)) {
                    alert(MinWorkDaysNotZero);
                    document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).focus();
                    return false;
                }
                else {
                    if ((appDay.charAt(0) == 0) && (appDay.charAt(1) == 0)) {
                        alert(InvalidMinWorkDays);
                        document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).focus();
                        return false;
                    }
                }
                if (appDay > 365) {
                    alert(MaxValue_WorkDay_365);
                    document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).focus();
                    return false;
                }
                else {
                    if (appDay.match(/([1-3][0-6][0-5])/)) {
                        return true;
                    }
                    else {
                        if (appDay % 0.5 != 0) {
                            alert(InvalidMinWorkDays);
                            document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).focus();
                            return false;
                        }
                    }
                }
            }// end app day empty checking 
            else {
                alert(MinWorkDaysNotEmpty);
                document.getElementById("ctl00_BodyContentPH_MinWorkedDays" + rowid).focus();
                return false;
            }
            return true;
        }
        // Accepts only Numbers and Dot (.) without white spaces inbetween 
        // Accept Decimal Numbers
        function chkDecNums(e, obj) {
            if (!e) e = window.event;
            var c = (window.event) ? e.keyCode : e.which;
            if (c == 46 && obj.value.indexOf(".") != -1) {
                return false;
            }
            if ((c >= 48 && c <= 57) || c == 0 || c == 8 || c == 46 || c == 13 || c == 9 || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 39 || c == 46)
                return true;
            else
                return false;
        }
        // Accepts only Numbers and Colon(:) without white spaces inbetween 
        function chkColonNums(e, obj) {
            if (!e) e = window.event;
            var c = (window.event) ? e.keyCode : e.which;
            if (c == 58 && obj.value.indexOf(":") != -1) {
                return false;
            }
            if ((c >= 48 && c <= 57) || c == 0 || c == 8 || c == 58 || c == 13 || c == 9 || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 39 || c == 58)
                return true;
            else
                return false;
        }
        function numbers_dot(e, ctrl) {
            dec_limit = arguments[1];
            var keycode;
            if (window.event) keycode = window.event.keyCode;
            else if (e) keycode = e.which;
            else return true;
            val = ctrl.value;
            dot_index = val.indexOf('.');
            if (dot_index != -1) {
                dec_pts = (val.length - dot_index);
                if (!dec_limit) dec_limit = 3; else dec_limit = dec_limit + 1;
            }
            if (document.selection) {
                var selection = document.selection.createRange();
                var selected_text = selection.text;
            }
            else if (document.getSelection) {
                var start = ctrl.selectionStart;
                var end = ctrl.selectionEnd;
                var selected_text = ctrl.value.substring(start, end);
            }
            //keycodes allowed but not in the beginning - 0,dot
            if ((val.length == 0 || selected_text != "") && (keycode == 46)) {
                return false;
            }
            else if (dot_index != -1 && keycode == 46) {
                return false;
            }
            else if (!(keycode >= 48 && keycode <= 57) && (keycode != 13) && (keycode != 46) && (keycode = 36) && (keycode != 8) && (keycode != 0)) {
                return false;
            }
            else return true;
        }
    </script>

    <div class="content-header">
        <h1 style="background-image: url('../dist/img/leave-policy.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderLeavePolicy" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div>
            <!--FILTERS-->
            <div class="exda-table">
                <h6>
                    <span style="color: Red">|</span>
                    <asp:Label ID="lbl_IndicatesMandatoryFields" runat="server"></asp:Label>
                    (1
                    No.)</h6>
            </div>
            <div class="emp-filter">
                <div class="row">
                    <div class="form-horizontal">
                        <div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <asp:Label ID="lblCompany" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-3">
                                        <asp:Label ID="lblSelectedCompany" runat="server" CssClass="form-control" class="form-control"></asp:Label>
                                    </div>
                                    <div class="col-sm-1">
                                    </div>
                                    <asp:Label ID="lbl_PolicyName" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-4">
                                        <asp:TextBox onpaste="return true" ID="txt_PolicyName" runat="server" CssClass="form-control mandatory"
                                            MaxLength="40" oncut="return false" onDelete="return false" ondrop="return false"
                                            onkeyPress="return chkMaxLen(event,this,40,MaxLength)"></asp:TextBox>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <asp:Label ID="lblEmpCategory" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-3">
                                        <asp:Label ID="lblSelectedCategory" runat="server" CssClass="form-control"></asp:Label>
                                    </div>
                                    <div class="col-sm-1">
                                    </div>
                                    <asp:Label ID="lblEmpType" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-4">
                                        <asp:Label ID="lblSelectedType" runat="server" CssClass="form-control"></asp:Label>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <asp:Label ID="lblGender" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-3">
                                        <asp:Label ID="lblSelectedGender" runat="server" CssClass="form-control"></asp:Label>
                                    </div>
                                    <div class="col-sm-1">
                                    </div>
                                    <asp:Label ID="lblReligion" runat="server" class="col-sm-2 control-label"></asp:Label>
                                    <div class="col-sm-4">
                                        <asp:Label ID="lblSelectedReligion" runat="server" CssClass="form-control"></asp:Label>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-5">
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="pull-right-button">
                                            <asp:LinkButton ID="btn_View" CssClass="btn view-btn fa-eye" runat="server" OnClick="btn_View_Click"
                                                Style="margin-bottom: 10px; display: none;" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-12" style="color: red">
                                        Service Period - Avail is 0 time(s) - No limit. i.e User can avail the leave to any number of times as per the policy creation.
                                            <br />
                                        Appl.After (Days) - Applicable After Days
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix">
                        </div>
                        <div runat="server" id="PH_DynmCtrlDiv">
                            <div class="row">
                                <div class="lve-polhdr1">
                                    <h3>
                                        <asp:Label ID="lbl_LeaveConfi" runat="server" Text="Leave Configuration"></asp:Label></h3>
                                </div>
                            </div>
                            <!--TABLE-->
                            <div class="lvepol-table">
                                <div class="row">
                                    <div class="table-responsive">
                                        <asp:Panel ID="PH_DynmCtrl" runat="server" EnableViewState="true" Style="width: 1570px; overflow: auto;">
                                        </asp:Panel>
                                    </div>
                                </div>
                                <div class="clearfix">
                                </div>
                            </div>
                        </div>
                        <div style="margin-top: 15px">
                            <div class="row">
                                <div class="lve-polhdr2">
                                    <h3>
                                        <asp:CheckBox ID="chkPermission" runat="server" OnClick="javascript:return CheckPermission();"
                                            CssClass="checkbox checkbox-primary" />
                                    </h3>
                                </div>
                            </div>
                            <div class="row">
                                <div class="lve-polhdr4">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <asp:Label ID="lbl_MaxPermissionHoursPerMonth" CssClass="col-sm-2 control-label con-top"
                                                runat="server"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox onpaste="return true" ID="txt_MaxHrsMonth" Enabled="false" runat="server"
                                                    CssClass="form-control" MaxLength="5" onblur="return validatePermissionMonth();"
                                                    onchange="ValidatePermissionHrs();"></asp:TextBox>&nbsp;
                                                <cc1:MaskedEditExtender ID="MaxHrsPerMonth" runat="server" TargetControlID="txt_MaxHrsMonth"
                                                    InputDirection="RightToLeft" MaskType="Time" Mask="99:99" AcceptAMPM="false"
                                                    ClearTextOnInvalid="true" ErrorTooltipEnabled="true">
                                                </cc1:MaskedEditExtender>
                                            </div>
                                            <div class="col-sm-1">
                                            </div>
                                            <asp:Label ID="lbl_MaxNoOfInstancesPerMonth" runat="server" CssClass="col-sm-2 control-label con-top"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox onpaste="return true" CssClass="form-control" ID="txt_MaxInstances"
                                                    Enabled="false" MaxLength="1" onkeypress="return number_only(event,this);" runat="server"
                                                    onblur="return ValidatePermissionHrs();" onDrop="return false;"></asp:TextBox>
                                                <asp:HiddenField ID="txt_MaxHrsInstanceHdn" runat="server" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <asp:Label ID="lbl_MaxPermissionHoursPerInstance" runat="server" CssClass="col-sm-2 control-label con-top"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox onpaste="return true" ID="txt_MaxHrsInstance" ReadOnly="true" runat="server"
                                                    CssClass="form-control" onblur="return chkPermission(event,Permission);" MaxLength="5"
                                                    onkeypress="return AcceptTab(event);" onkeydown="return key_press_nokey(event)"
                                                    onDrop="return false;" onCut="return false;"></asp:TextBox>
                                            </div>
                                            <div class="col-sm-1">
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="col-md-5 pad-left7-right-1">
                                                    <asp:CheckBox ID="chkBeforeLeave" runat="server" Enabled="false" CssClass="checkboxShift checkboxShift-primary" />
                                                </div>
                                                <div class="col-md-6 pad-left7-right-1">
                                                    <asp:CheckBox ID="chkAfterLeave" runat="server" Enabled="false" CssClass="checkboxShift checkboxShift-primary" />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clearfix">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="row">
                                <div class="lve-polhdr3">
                                    <h3>
                                        <asp:CheckBox ID="chkOverTimeType" runat="server" OnClick="javascript:return CheckOverTimeType()"
                                            CssClass="checkbox checkbox-primary" /></h3>
                                </div>
                            </div>
                            <div class="row">
                                <div class="lve-polhdr5">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <div class="col-md-5">
                                                <ul class="list-inline mas-ulbg">
                                                    <li class="list-mar3">
                                                        <asp:RadioButton ID="rbt_HourWise" runat="server" Enabled="false" GroupName="OT"
                                                            CssClass="radio radio-primary" />
                                                    </li>
                                                    <li class="list-mar3">
                                                        <asp:RadioButton ID="rbt_DayWise" runat="server" Enabled="false" GroupName="OT" CssClass="radio radio-primary" />
                                                    </li>
                                                </ul>
                                            </div>
                                            <div class="col-sm-1">
                                            </div>
                                            <asp:Label ID="lblValidsDays" runat="server" Text="Comp Off Validity Days" CssClass="col-sm-2"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox ID="txtValidsDays" runat="server" CssClass="form-control" MaxLength="3"
                                                    onkeypress="return numbers_dot(event,this)" onpaste="return true" onCut="return false;"
                                                    onDrop="return false;" Enabled="false"></asp:TextBox>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <asp:Label ID="lblHalfDayComoff" runat="server" CssClass="col-sm-2" Text="Min Extra Hrs for Half Day Comp Off"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox ID="txtHalfDayComoff" runat="server" CssClass="form-control" onCut="return false"
                                                    onpaste="return true" MaxLength="5" onDrop="return false" Enabled="false"></asp:TextBox>
                                            </div>
                                            <div class="col-sm-1">
                                            </div>
                                            <asp:Label ID="lblFullDayComoff" runat="server" CssClass="col-sm-2" Text="Min Extra Hrs for Full Day Comp Off"></asp:Label>
                                            <div class="col-sm-3">
                                                <asp:TextBox onpaste="return true" ID="txtFullDayComoff" runat="server" CssClass="form-control"
                                                    onCut="return false" MaxLength="5" onDrop="return false" Enabled="false"></asp:TextBox>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clearfix">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="col-md-6">
                                <asp:UpdatePanel ID="upLeave" runat="server">
                                    <ContentTemplate>
                                        <asp:Panel ID="pnlProgress" runat="server" Style="display: none;">
                                            <asp:Panel ID="pnlLoading" runat="server" HorizontalAlign="center">
                                                <div class="InsideProgressBar">
                                                    <div class="row" style="margin-top: 10px">
                                                        <img src="../dist/img/logo-Progress.png" />
                                                    </div>
                                                    <div class="row" style="min-width: 280px">
                                                        <img src="../dist/img/default.gif" style="width: 100px" />
                                                    </div>
                                                    <div class="row" style="margin-bottom: 10px">
                                                        <asp:Label ID="lblLoading" runat="server" ForeColor="black" Style="text-align: center"
                                                            Text="Please Wait..." Font-Bold="true" Font-Size="12px" Font-Italic="true" Font-Family="Arial"></asp:Label>
                                                    </div>
                                                    <div class="clear clearfix">
                                                    </div>
                                                </div>
                                            </asp:Panel>
                                        </asp:Panel>
                                        <asp:HiddenField ID="hdnProgress" runat="server" />
                                        <cc1:ModalPopupExtender ID="popupProgress" runat="server" TargetControlID="hdnProgress"
                                            BackgroundCssClass="ModalPopup" PopupControlID="pnlProgress" BehaviorID="popupProgress">
                                        </cc1:ModalPopupExtender>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </div>
                            <div class="col-md-6">
                                <div class="filter-button">
                                    <%--   <button type="button" class="btn back-btn">
                                        <i class="" aria-hidden="true"></i>Back</button>
                                    <button type="button" class="btn save-btn">
                                        <i class="fa fa-floppy-o"></i>Save</button>--%>
                                    <asp:LinkButton ID="btn_save" CssClass="btn save-btn fa-floppy-o" runat="server"
                                        OnClick="btn_save_Click" OnClientClick="javascript:return ValidateAll();" />
                                    <asp:LinkButton ID="btn_cancel" CssClass="btn save-btn fa-angle-left" runat="server"
                                        CausesValidation="false" OnClick="btn_cancel_Click" />
                                    <%-- Change the value to 1 it will throw alert --%>
                                    <asp:HiddenField ID="hdfValidation" Value="0" runat="server" />
                                    <asp:HiddenField ID="hdnLeaveCount" runat="server" />
                                    <asp:HiddenField ID="hdfOTHourType" runat="server" Value="0" />
                                    <asp:HiddenField ID="hdfOTDayType" runat="server" Value="0" />
                                    <asp:HiddenField ID="hdfFilter" runat="server" Value="0" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
