
(function ($) {
// Sidebar fix for My Cards page
    var $window = $(window);

    function sidebar_height() {
        var $main_sidebar = $('#main-sidebar');
        if (!$main_sidebar) return;

        var wrap_height = $('#main-container').height();
        $main_sidebar.css({
            'min-height': wrap_height + 'px'
        });
    }

    $window.resize(sidebar_height);
    sidebar_height();
})(jQuery);

$('a.cancel').click(function(){
    var formId = $(this).prop('rel');
    var $form = $(formId);
    $form.fadeOut('slow');
    $(this).parent().find('a').delay(600).toggle();
    $(formId.replace('form-', 'display-')).delay(600).fadeIn('slow');
});

$('#btnBuy').click(function(){
    location.href = $(this).data('href');
});

$("#form-communications input#communications").change(function() {
    $("#form-communications").submit();
});

// Prevent multiple form submission
$('form').on('submit', function() {
    $('#waitModal').modal({backdrop: 'static', keyboard: false});
});

$(document).ready(function() {
    $('#egiftPromoModal').modal({backdrop: 'static', keyboard: false});
});

// Ensure labels have the class 'required' when their related input is required
$(':required').each(function () {
    $(this).parent('label').addClass('required');
    if (undefined !== $(this).attr('id')) {
        $("label[for='" + $(this).prop('id') + "']").addClass('required');
    }
});

