﻿$(function () {

    $.datepicker.setDefaults($.datepicker.regional['de']);
    $('#tbanreise, #tbabreise').datepicker({ beforeShow: customRange, dateFormat: "dd.mm.yy", firstDay: 1, changeFirstDay: false });
    $('#ctl06_tbanreise2, #ctl06_tbabreise2').datepicker({ beforeShow: customRange2, dateFormat: "dd.mm.yy", firstDay: 1, changeFirstDay: false });
});

function customRange(input) {
    var min = new Date(2008, 11 - 1, 1), //Set this to your absolute minimum date
        dateMin = min,
        dateMax = null,
        dayRange = 6; // Set this to the range of days you want to restrict to

    if (input.id === "tbanreise") {
        if ($("#tbabreise").datepicker("getDate") != null) {
            dateMax = null,
                  dateMin = new Date(2008, 11 - 1, 1);
            dateMin.setDate(dateMin.getDate());
            if (dateMin < min) {
                dateMin = min;
            }
        }
        else {
            dateMax = new Date; //Set this to your absolute maximum date
        }
    }
    else if (input.id === "tbabreise") {
        dateMax = new Date; //Set this to your absolute maximum date
        if ($("#tbanreise").datepicker("getDate") != null) {
            dateMin = $("#tbanreise").datepicker("getDate");
            var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate());

            if (rangeMax < dateMax) {
                //                      dateMax = rangeMax;
            }
        }
    }
    return {
        minDate: dateMin,
        maxDate: null
    };
}



function customRange2(input) {
    var min = new Date(2008, 11 - 1, 1), //Set this to your absolute minimum date
        dateMin = min,
        dateMax = null,
        dayRange = 6; // Set this to the range of days you want to restrict to

    if (input.id === "ctl06_tbanreise2") {
        if ($("#ctl06_tbabreise2").datepicker("getDate") != null) {
            dateMax = null,
                  dateMin = $("#ctl06_tbabreise2").datepicker("getDate");
            dateMin.setDate(dateMin.getDate());
            if (dateMin < min) {
                dateMin = min;
            }
        }
        else {
            dateMax = new Date; //Set this to your absolute maximum date
        }
    }
    else if (input.id === "ctl06_tbabreise2") {
        dateMax = new Date; //Set this to your absolute maximum date
        if ($("#ctl06_tbanreise2").datepicker("getDate") != null) {
            dateMin = $("#ctl06_tbanreise2").datepicker("getDate");
            var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate());

            if (rangeMax < dateMax) {
                //                      dateMax = rangeMax;
            }
        }
    }
    return {
        minDate: dateMin,
        maxDate: null
    };
}
