function confirmRemove(element) {
	if (confirm("Are you sure?")) {
		$(element).remove();
	}
}

function productFilters(params) {
	var filters = new Hash();
	$$('#productFiltersWrap input[type="radio"]').pluck('name').uniq().each(function(f) {
		filters.set(f, $$('input:checked[type="radio"][name="' + f + '"]').pluck('value'));
	});
	new Ajax.Updater(params.container, '/js/ajax.php', { parameters: Object.extend ({filters: filters.toJSON()}, params)});
}

function productPrice(productId) {
	var optionIds = "";
	$('purchaseOptions').select('input.option').each(function(s) {
		if ($(s).getValue()) {
			if (optionIds) {
				optionIds = optionIds + ',';
			}
			optionIds = optionIds + $(s).getValue();
		}
	});
	new Ajax.Updater('showPrice', '/js/ajax.php', { parameters: {action: 'productPrice', productId: productId, optionIds: optionIds} });
	new Ajax.Updater('showPriceTotal', '/js/ajax.php', { parameters: {action: 'productPriceTotal', productId: productId, optionIds: optionIds, qty: $('qty').getValue()} });
}

function request(params) {
	new Ajax.Request('/js/ajax.php', { parameters: params });
}

function shopCartAdd() {
	if (confirm('Add item to basket?')) {
		$('shopCartAdd').request({
			onComplete: function(xhr) {
				updater({container: 'shopCartOverview', action: 'shopCartOverview', sc: $('configId').getValue()});
			}
		});
	}
}

function shopCartRemove(params) {
	if (confirm('Delete item from basket?')) {
		new Ajax.Request('/js/ajax.php', { 
			parameters: params, 
			onComplete: function(xhr) {
				updater({container: 'shopCartContent', action: 'shopCartContent', sc: $('sc').getValue()});
			}
		});
	}
}

function shopCartUpdate() {
	if (confirm('Update basket content quantities?')) {
		$('shopCart').request({
			onComplete: function(xhr) {
				updater({container: 'shopCartContent', action: 'shopCartContent', sc: $('sc').getValue()});
			}
		});
	}
}

function shopCartCheckout() {
	if (confirm('Place an order for all the items currently in your basket?')) {
		window.location="/content/" + $('cp').getValue() + "/checkout";
	}
}

function socialSite(params) {
	new Ajax.Updater(params.container, '/js/ajax.php', { 
		method:'get',
		parameters: params
	});
}

function updater(params) {
	if (!params.evalScripts) {
		params.evalScripts = false;
	}
	if (params.insertion) {
		new Ajax.Updater(params.container, '/js/ajax.php', { parameters: params, evalScripts: params.evalScripts, insertion: params.insertion});
	} else {
		new Ajax.Updater(params.container, '/js/ajax.php', { parameters: params, evalScripts: params.evalScripts});
	}
}