jQuery.fn.initBooking = function () {
    $('.bookingSection').addClass('ui-widget').clearFix();
    $('.bookingSectionControls a, .bookingHeader a, a.button').button();
    $('.bookingSection.section .option .title').fixOptionTitle();

    $.datepicker.setDefaults({
        dateFormat: "dd-mm-yy",
        defaultDate: +1,
        minDate: 0,
        showOtherMonths: true,
        selectOtherMonths: true
    });

    $(this).setBookingHeaderStep();
    $(this).setBookingHeaderDisabled();
};

jQuery.fn.setDateRange = function (input, inputs, inputFromId, inputToId, selectedDate) {
    option = (input.id == inputFromId) ? "minDate" : "maxDate";
    instance = $(input).data("datepicker");
    date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
    if (input.id == inputFromId)
        date.setDate(date.getDate() + 1);
    else
        date.setDate(date.getDate() - 1);
    inputs.not(input).datepicker("option", option, date);
};

// highlight the active step in booking header navigation
jQuery.fn.setBookingHeaderStep = function () {
    var step = $('#booking').attr('data-booking-step');
    //	alert(step);
    $('.bookingHeader a').each(function () {
        $(this).removeClass('ui-state-highlight');
    });
    $('.selected').addClass('ui-state-highlight');
};

//Set appropriate status of buttons on top
jQuery.fn.setBookingHeaderDisabled = function () {
    //var disableOther = $(".bookingHeader a.disable-other");
    //var disableThis = (disableOther.length > 0) ? true : false;
    $(".bookingHeader a").each(function () {
        //var isSelected = $(this).hasClass("selected");
        //var isDisableOther = $(this).hasClass("disable-other");
        //if (isDisableOther)
        //    disableThis = false;
        $(this).button("option", "disabled", $(this).hasClass('aspNetDisabled'));
        //if (isSelected)
        //    disableThis = true;
    });
};

jQuery.fn.updateBookingHeaderStep = function (step) {
    $('#booking').attr('data-booking-step') = step;
    $(this).setBookingHeaderStep();
};

jQuery.fn.clearFix = function () {
    $(this).append('<div class="clear"></div>');
    return this;
};

jQuery.fn.fixOptionTitle = function () {
    var titleHeightMax = 0;
    $(this).each(function (index, element) {
        var $element = $(element);
        var titleHeight = $element.height();
        titleHeightMax = (titleHeight > titleHeightMax) ? titleHeight : titleHeightMax;
    });
    $(this).each(function (index, element) {
        var $element = $(element);
        $element.height(titleHeightMax);
    });
    return this;
};
