
$jBD = jQuery.noConflict();
var Strartdate = document.getElementById('dtStartDate');
var Enddate = document.getElementById('dtEndDate');
var DtTodate = document.getElementById('dtToDate');
var dtFromDate = document.getElementById('dtFromDate');
var dtExecutedOn = document.getElementById('dtExecutedOn');
var dtDueOnDate = document.getElementById('dtDueOnDate');
var dtWrntyStDate = document.getElementById('dtWrntyStDate');
var dtWrntyEndDate = document.getElementById('dtWrntyEndDate');

//--------------------------History & Alarm Page DateTime Picker---------------------//
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 6);
    if (Strartdate != null) {
        $jBD('#dtStartDate').datetimepicker({
            format: "DD-MMM-YYYY LT",
            showTodayButton: true,
            defaultDate: startdate,
            //showClear: true,
            showClose: true

        }
    );
        $jBD('#dtStartDate').data("DateTimePicker").minDate(startdate);
        //$jBD('#dtStartDate').data("DateTimePicker").maxDate(today);
    }
});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 6);
    if (Enddate != null) {
        $jBD('#dtEndDate').datetimepicker({
            format: "DD-MMM-YYYY LT",
            showTodayButton: true,
            //showClear: true,
            showClose: true
            //minDate: startdate,
            //maxDate: today
        }
    );
        $jBD('#dtEndDate').data("DateTimePicker").minDate(startdate);
        //$jBD('#dtEndDate').data("DateTimePicker").maxDate(today);
    }

});
//--------------------------History & Alarm Page End --------------------------------//

//--------------------------Report Page DatePicker ---------------------------------//
$jBD(function () {
    $jBD('#txtReportFromHrs').datetimepicker({
        format: "LT",
        showTodayButton: true,
        showClose: true
    });
});
$jBD(function () {
    $jBD('#txtReportToHrs').datetimepicker({
        format: "LT",
        showTodayButton: true,
        showClose: true
    });
});
$jBD(function () {
    $jBD('#txtReportGenerationTime').datetimepicker({
        format: "LT",
        showTodayButton: true,
        showClose: true
    });
});
$jBD(function () {
    $jBD('#txtReportWeeklyGenerateTime').datetimepicker({
        format: "LT",
        showTodayButton: true,
        showClose: true
    });
});
$jBD(function () {
    $jBD('#txtReportMonthlyGenerationTime').datetimepicker({
        format: "LT",
        showTodayButton: true,
        showClose: true
    });
});

$jBD(function () {
    $jBD('#txtEffectiveFrom').datetimepicker({
        format: "DD-MMM-YYYY",
        showTodayButton: true,
        showClose: true
    });
});
$jBD(function () {
    $jBD('#txtEffectiveTo').datetimepicker({
        format: "DD-MMM-YYYY",
        showTodayButton: true,
        showClose: true
    });
});

$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 1);
    $jBD("[id$='_txtTimeBasedInitializationValue']").datetimepicker({
        format: "DD-MMM-YYYY",
        showTodayButton: true,
        //showClear: true,
        showClose: true
    }
    );
});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours() - 24)
    startdate.setMonth(startdate.getMonth() - 6);
    if (dtFromDate != null) {
        $jBD('#dtFromDate').datetimepicker({
            format: "DD-MMM-YYYY",
            showTodayButton: true,
            //defaultDate: startdate,
            //showClear: true,
            showClose: true,
            minDate: startdate,
            maxDate: today
        }
    );
        $jBD('#dtFromDate').data("DateTimePicker").minDate(startdate);
        $jBD('#dtFromDate').data("DateTimePicker").maxDate(today);
    }

});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 6);
    if (DtTodate != null) {
        $jBD('#dtToDate').datetimepicker({
            format: "DD-MMM-YYYY",
            showTodayButton: true,
            //showClear: true,
            showClose: true
            //minDate: startdate,
            //maxDate: today
        });
        $jBD('#dtToDate').data("DateTimePicker").minDate(startdate);
        $jBD('#dtToDate').data("DateTimePicker").maxDate(today);
    }

});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 6);
    if (dtExecutedOn != null) {
        $jBD('#dtExecutedOn').datetimepicker({
            format: "DD-MMM-YYYY",
            showTodayButton: true,
            //defaultDate: startdate,
            //showClear: true,
            showClose: true
        }
    );
        $jBD('#dtExecutedOn').data("DateTimePicker").minDate(startdate);
        $jBD('#dtExecutedOn').data("DateTimePicker").maxDate(today);
    }

});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() + 6);
    if (dtDueOnDate != null) {
        $jBD('#dtDueOnDate').datetimepicker({
            format: "DD-MMM-YYYY",
            showTodayButton: true,
            //showClear: true,
            showClose: true
        }
   );
        $jBD('#dtDueOnDate').data("DateTimePicker").minDate(today);
        $jBD('#dtDueOnDate').data("DateTimePicker").maxDate(startdate);
    }

});
$jBD(function () {
    var startdate = new Date();
    var today = new Date();
    today.setHours(today.getHours())
    startdate.setMonth(startdate.getMonth() - 1);
    if ($jBD("[id$='_gtxtServicedOn']") != null) {
        $jBD("[id$='_gtxtServicedOn']").datetimepicker({
            format: "DD-MMM-YYYY",
            showTodayButton: true,
            //showClear: true,
            showClose: true,
            maxDate: today
        }
        );
        //$jBD("[id$='_gtxtServicedOn']").data("DateTimePicker").minDate(startdate);
        //$jBD("[id$='_gtxtServicedOn']").data("DateTimePicker").maxDate(today);
    }

});

//---------------------Make ManageMgmt ------------------------------//
$jBD(function () {
    $jBD('#txtsft1s').datetimepicker({
        format: "HH:mm",
        //format: 'LT',
        showTodayButton: true,
        showClear: true,
        showClose: true
    });
});
//$jBD(function () {

//});

//$jBD(function () {
//    try {
//        var startdate = new Date();
//        var today = new Date();
//        today.setMonth(startdate.getMonth() + 130)
//        startdate.setMonth(startdate.getMonth() - 121);
//        $jBD('#dtWrntyEndDate').datetimepicker({
//            format: "DD-MMM-YYYY",
//            showTodayButton: true,
//            //showClear: true,
//            showClose: true,
//            minDate: startdate,
//            maxDate: today
//        }
//        );
//    } catch (e) {

//    }
//    // $jBD('#dtWrntyEndDate').data("DateTimePicker").minDate(startdate);
//    // $jBD('#dtWrntyEndDate').data("DateTimePicker").minDate(today);
//});
// -----------------------Page Load ---------------------------------//

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
    $jBD(function () {
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 6);
            if (Strartdate != null) {
                $jBD('#dtStartDate').datetimepicker({
                    format: "DD-MMM-YYYY LT",
                    showTodayButton: true,
                    //defaultDate: startdate,
                    //showClear: true,
                    showClose: true
                    //minDate: startdate,
                    //maxDate: today
                }
            );
                $jBD('#dtStartDate').data("DateTimePicker").minDate(startdate);
                //$jBD('#dtStartDate').data("DateTimePicker").maxDate(today);
            }

        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 6);
            if (Enddate != null) {
                $jBD('#dtEndDate').datetimepicker({
                    format: "DD-MMM-YYYY LT",
                    showTodayButton: true,
                    //showClear: true,
                    showClose: true,
                    //minDate: startdate,
                    //maxDate: today
                }
           );
                $jBD('#dtEndDate').data("DateTimePicker").minDate(startdate);
                //$jBD('#dtEndDate').data("DateTimePicker").maxDate(today);
            }

        });

        $jBD(function () {
            $jBD('#txtReportFromHrs').datetimepicker({
                format: "LT",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtReportToHrs').datetimepicker({
                format: "LT",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtReportGenerationTime').datetimepicker({
                format: "LT",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtReportWeeklyGenerateTime').datetimepicker({
                format: "LT",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtReportMonthlyGenerationTime').datetimepicker({
                format: "LT",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtEffectiveFrom').datetimepicker({
                format: "DD-MMM-YYYY",
                showTodayButton: true,
                showClose: true
            });
        });
        $jBD(function () {
            $jBD('#txtEffectiveTo').datetimepicker({
                format: "DD-MMM-YYYY",
                showTodayButton: true,
                showClose: true
            });
        });

        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 1);
            $jBD("[id$='_txtTimeBasedInitializationValue']").datetimepicker({
                format: "DD-MMM-YYYY",
                showTodayButton: true,
                //showClear: true,
                showClose: true
            }
            );
        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours() - 24)
            startdate.setMonth(startdate.getMonth() - 6);
            if (dtFromDate != null) {
                $jBD('#dtFromDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //defaultDate: startdate,
                    //showClear: true,
                    showClose: true,
                    //minDate: startdate,
                    //maxDate: today
                }
            );
                $jBD('#dtFromDate').data("DateTimePicker").minDate(startdate);
                $jBD('#dtFromDate').data("DateTimePicker").maxDate(today);
            }

        });

        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 6);
            if (DtTodate != null) {
                $jBD('#dtToDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //showClear: true,
                    showClose: true
                    //minDate: startdate,
                    //maxDate: today
                }
            );
                $jBD('#dtToDate').data("DateTimePicker").minDate(startdate);
                $jBD('#dtToDate').data("DateTimePicker").maxDate(today);
            }
        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 6);
            if (dtExecutedOn != null) {
                $jBD('#dtExecutedOn').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //defaultDate: startdate,
                    //showClear: true,
                    showClose: true

                }
            );
                $jBD('#dtExecutedOn').data("DateTimePicker").minDate(startdate);
                $jBD('#dtExecutedOn').data("DateTimePicker").maxDate(today);
            }

        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() + 6);
            if (dtDueOnDate != null) {
                $jBD('#dtDueOnDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //showClear: true,
                    showClose: true
                }
            );
                $jBD('#dtDueOnDate').data("DateTimePicker").minDate(today);
                $jBD('#dtDueOnDate').data("DateTimePicker").maxDate(startdate);
            }

        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setHours(today.getHours())
            startdate.setMonth(startdate.getMonth() - 1);
            $jBD("[id$='_gtxtServicedOn']").datetimepicker({
                format: "DD-MMM-YYYY",
                showTodayButton: true,
                //showClear: true,
                showClose: true,
                maxDate: today
            }
            );
            //$jBD('#dtEndDate').data("DateTimePicker").minDate(startdate);
            //$jBD("[id$jBD='_gtxtServicedOn']").data("DateTimePicker").maxDate(today);
        });
        $jBD(function () {
            var startdate = new Date();
            var today = new Date();
            today.setMonth(startdate.getMonth() + 130)
            startdate.setMonth(startdate.getMonth() - 121);
            //if (dtWrntyStDate != null) {
            $jBD('#dtWrntyStDate').datetimepicker({
                format: "DD-MMM-YYYY",
                showTodayButton: true,
                //defaultDate: startdate,
                //showClear: true,
                showClose: true
                //beforeShow: function (dateText, inst) {
                //    var the_date = $jBD('input[id$jBD=dtWrntyStDate]').datetimepicker('getDate');
                //    $jBD("input[id$jBD=dtWrntyStDate]").datetimepicker('option', 'maxDate', the_date);
                //}
            }
        );
            //$jBD('#dtWrntyStDate').data("DateTimePicker").minDate(startdate);
            //$jBD('#dtWrntyStDate').data("DateTimePicker").maxDate(today);
            // }

        });
        $jBD(function () {
            try {
                var startdate = new Date();
                var today = new Date();
                today.setMonth(startdate.getMonth() + 130)
                startdate.setMonth(startdate.getMonth() - 121);
                $jBD('#dtWrntyEndDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //showClear: true,
                    showClose: true,
                    minDate: startdate,
                    maxDate: today
                }
                );
            } catch (e) {

            }
            // $jBD('#dtWrntyEndDate').data("DateTimePicker").minDate(startdate);
            // $jBD('#dtWrntyEndDate').data("DateTimePicker").minDate(today);
        });
        $jBD(function () {
            try {
                var startdate = new Date();
                var today = new Date();
                today.setHours(today.getHours())
                startdate.setMonth(startdate.getMonth() - 120);
                $jBD('#dtPurchasedDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //defaultDate: startdate,
                    //showClear: true,
                    showClose: true,
                    minDate: startdate,
                    maxDate: today,
                    //locale: 'en_US'
                }
                );
                // $jBD('#dtPurchasedDate').data("DateTimePicker").minDate(startdate);
                //$jBD('#dtPurchasedDate').data("DateTimePicker").maxDate(today);
            } catch (e) {

            }
        });
        $jBD(function () {
            try {
                var startdate = new Date();
                var today = new Date();
                today.setHours(today.getHours())
                startdate.setMonth(startdate.getMonth() - 120);
                $jBD('#dtBatteryDate').datetimepicker({
                    format: "DD-MMM-YYYY",
                    showTodayButton: true,
                    //defaultDate: startdate,
                    //showClear: true,
                    showClose: true,
                    minDate: startdate,
                    maxDate: today,
                    //locale: 'en_US'
                }
                );
                // $jBD('#dtPurchasedDate').data("DateTimePicker").minDate(startdate);
                //$jBD('#dtPurchasedDate').data("DateTimePicker").maxDate(today);
            } catch (e) {

            }
        });
        $jBD(function () {
            $jBD('#txtsft1s').datetimepicker({
                format: "HH:mm",
                //format: 'LT',
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft1e').datetimepicker({
                format: "HH:mm",
                //format: 'LT',
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft2s').datetimepicker({
                //format: 'LT',
                format: "HH:mm",
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft3s').datetimepicker({
                //format: 'LT',
                format: "HH:mm",
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft4s').datetimepicker({
                //format: 'LT',
                format: "HH:mm",
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft5s').datetimepicker({
                //format: 'LT',
                format: "HH:mm",
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
            $jBD('#txtsft6s').datetimepicker({
                //format: 'LT',
                format: "HH:mm",
                showTodayButton: true,
                showClear: true,
                showClose: true
            });
        });

    });
    $jBD("#dtWrntyStDate").on("dp.change", function (e) {
        var oldDate = new Date(e.date);
        var newDate = new Date();
        newDate.setDate(oldDate.getDate() + 1);
        $jBD('#dtWrntyEndDate').data("DateTimePicker").minDate(newDate);
    });
});
