
function continue_shopping()
{
	history.go(-1);
}


function change_product_image(image_src)
{
    document.getElementById("product_image").src = image_src;
}

function select_size(size)
{
	$('.active_size').removeClass('selected_size').attr('title', 'Select size');

	var id = '#size_' + size;
	$(id).addClass('selected_size').attr('title', 'Selected');

	$('#selected_size').attr('value', size);
}


function add_catalog_item(product_id, size)
{
	if (size == 'Q') {
		var size = $('#selected_size').attr('value');

		if (! size) {
			alert('Please select a size.');
			return;
		}
	}

	var success_callback = function(data) { catalog_item_added(product_id, data); };

    // add the product to the cart
    cart.add_item(product_id, size, success_callback);
}


function catalog_item_added(product_id, data)
{
	if (data.error_message)	{
		alert(data.error_message);
		return;
	}

    // change the button text and onClick function
	var cart_button_id = "#cart_button_" + product_id;
    $(cart_button_id).attr('value', 'view cart');
	$(cart_button_id).removeAttr('onclick');
	$(cart_button_id).click(cart.view);
}


