function qc_addToCart(productform, url) {
    $.fancybox.showActivity();
    $.ajax({
        type: "POST",
        url: url + ".js",
        dataType: "json",
        data: $("#" + productform).serialize(),
        success: function (postResponse) {
            var content = '';
            var options = '';
            if (postResponse.response.options != undefined) {
                if (postResponse.response.options.length == undefined) {
                    $.each([postResponse.response.options], function (key, value) {
                        options = options + '<p>' + this.name + ': ' + this.value + '</p>';
                    });
                } else {
                    $.each(postResponse.response.options, function (key, value) {
                        options = options + '<p>' + this.name + ': ' + this.value + '</p>';
                    });
                };
            }

            if (postResponse.response.status == "success") {
                var itemDisplay = " items";
                if (postResponse.response.quantity == 1) {
                    itemDisplay = " item";
                }
                content = '<div style="margin:10px">' +
                    '<h1 style="font-size:24px;font-weight:bold;color:#434343;">You\'ve added ' + postResponse.response.quantity + itemDisplay + ' to your cart!</h1><br/>' +
                    '<img src="http://images.buyitsellit.com/' + postResponse.response.imageid + '_132.jpg" style="vertical-align:middle;margin-right:10px;float:left;">' +
                    '<p style="font-weight:bold;">' + postResponse.response.producttitle + '</p>' +
                    options +
                    '<p style="margin-top:15px;"><span style="font-weight:bold;color:#5eb920;font-size:24px;">' + postResponse.response.totalprice + '</span><em style="margin-left:15px;font-style:italic;">' + postResponse.response.price + ' each</em></p>' +
                    '</div>'
            } else {
                content = '<div style="margin:10px">' +
                        '<h1 style="font-size:24px;font-weight:bold;color:#434343;">Unable to add item(s) to cart.</h1><br/>' +
                        '<p>Error: ' + postResponse.response.message + '</p>' +
                        '</div>'
            }
            $.fancybox({
                'titleShow': false,
                'type': 'html',
                'scrolling': 'hidden',
                'content': content
            });
            refreshCart();
        }
    });
};

function refreshCart() {
    $.ajax({
        url: '/cart.js',
        dataType: "json",
        success: function (response) {
            $("#cartcount").text(response.cart.cartcount);
            $("#carttotal").text(response.cart.total);
        }
    });
}
