
// this function is called from the validation callback setup in the newsletter ctl
function newsletterSignupFormCallback(formObj) {
    var emailAddress = $('#newsletterInput').val();
    var url = $(formObj).attr('action');
    $.get(url, { emailAddress: emailAddress }, function(data, textStatus) {
        if (data.Message === "SUCCESS") {
            $('#newsletter-error').hide();
            $('#home-newsletter-input form').html("<p>Thank you for signing up for the<br />newsletter.</p>");
        }
        else {
            // we got some other message the 'success'
            $('#newsletter-error').html(data.Text).show();
        }
    }, "json");
}


$(document).ready(function() {
    $('a[rel=new-window]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    $('#promo-link').live("click", function() {
        var promocode = $('#promocode').val();
        var url = $('#cart-promo-code form').attr('action');
        $.ajax({
            type: 'POST',
            url: url,
            data: "promocode=" + promocode,
            success: function(html) {
                $('#cart-footer').html(html);
            }
        });
        return false;
    });


    $('#sales-tax-link').live("click", function() {
        var tax = $('#tax').val();
        var url = $('#cart-sales-tax form').attr('action');
        $.ajax({
            type: 'POST',
            url: url,
            data: "tax=" + tax,
            success: function(html) {
                $('#cart-footer').fadeOut("slow").html(html).fadeIn("slow");
            }
        });
        return false;
    });


    $('.offense-toggle input.button').click(function() {
        var details = $(this).parents('.report-offense').find('.report-offense-details');
        var display = ($(details).css('display') === 'none');
        details.toggle(display);
        var src = $(this).attr('src');

        if (display) {
            $(this).val('Hide').toggleClass('open').toggleClass('closed');
            $(this).attr('src', src.replace("show", "hide"));
        }
        else {
            $(this).val('Show').toggleClass('open').toggleClass('closed');
            $(this).attr('src', src.replace("hide", "show"));
        }
        return false;
    });
});
