
(function($) {
    if($('.select2').length) {
        $('.select2').select2();
    }
    /*
    $('#monthSelect').on('change', function() {
        window.location.href = $(this).find('option:selected').val();
    });
*/
    /*$('#hasAddress').on('change', function() {
        var isChecked = $(this).is(':checked');
        $('.address-field').prop('disabled', false);

        if(!isChecked) {
            $('.address-field').prop('disabled', true);
        }
    });

    $('.amountInput input').on('change', function(e) {
        var $parent = $(this).parents('.amountInput');
        var min = $parent.data('min');
        var max = $parent.data('max');
        var value = $(this).val();

        if(isNaN(parseInt(value))) {
            value = 0;
        }

        if(value > max) {
            value = max;
        }

        if(value < min) {
            value = min;
        }

        $(this).val(value);
    });

    $('.amountInput .amount-plus').on('click', function(e) {
        e.preventDefault();
        var $parent = $(this).parents('.amountInput');
        var max = $parent.data('max');
        var $input = $parent.find('input');
        var value = $input.val();

        if(isNaN(parseInt(value))) {
            value = 1;
        } else {
            value = parseInt(value) + 1;
        }

        if(value > max) {
            value = max;
        }

        $input.val(value);
    });

    $('.amountInput .amount-minus').on('click', function(e) {
        e.preventDefault();
        var $parent = $(this).parents('.amountInput');
        var min = $parent.data('min');
        var $input = $parent.find('input');
        var value = $input.val();

        if(isNaN(parseInt(value))) {
            value = -1;
        } else {
            value = parseInt(value) - 1;
        }

        if(value < min) {
            value = min;
        }

        $input.val(value);
    });*/
    if($('.calendar-confirm').length) {
	$('.calendar-confirm').on('click', window.initDeleteConfirm );
    }
    if($('form #reservations-hasBillAddress').length) {
        var $billAddressField = $('form #reservations-hasBillAddress');
        if($billAddressField.is(':checked')) {
            $('form .bill-field').addClass('show');
            $('form .bill-field input[type="text"]').attr('required', true);
            $('form .bill-field input[type="text"]').prop('required', true);
        }
        $billAddressField.on('change', function(e) {
            $('form .bill-field').removeClass('show');
            $('form .bill-field input[type="text"]').attr('required', false);
            $('form .bill-field input[type="text"]').prop('required', false);

            if($(this).is(':checked')) {
                $('form .bill-field').addClass('show');
                $('form .bill-field input[type="text"]').attr('required', true);
                $('form .bill-field input[type="text"]').prop('required', true);
            }
        });
    }

    if($('.approvalList-search').length) {
        $('.approvalList-search select').on('change', function() {
            $(this).parents('form').trigger('submit');
        });
    }
})(jQuery);
