function widget_loaded(responseText, textStatus, XMLHttpRequest) {
//function widget_loaded(data, textStatus) {
//	var sId = this.widget_id;
	var sId = $(this).attr('id');
	var asId = sId.split("_");
	var sWidgetType = asId[0];
	var sWidgetKey = asId[1];
	var sScriptName = "http://www.flygupplevelse.se/js/widget_loaded/" + sWidgetType + "/" + sWidgetKey;

//	$('#' + sId).html(data);

	var head = document.getElementsByTagName('head')[0];
	script = document.createElement('script');
	script.src = sScriptName;
	script.type = 'text/javascript';
	head.appendChild(script)
}

function refresh_widgets( $action ){
	$('.widget').each(function(){
		var sId = $(this).attr('id');
		var asId = sId.split("_");
		var sWidgetType = asId[0];
		var sWidgetKey = asId[1];

		$(this).load("/" + sWidgetType + "/show_widget/" + sWidgetKey + '/#' + new Date().getTime(), $action, widget_loaded);
/*
		$.ajax({
			widget_id: sId,
			cache: false,
			type: 'POST',
			url: "/" + sWidgetType + "/show_widget/" + sWidgetKey + '/#' + new Date().getTime(),
			dataType: 'html',
			data: $action,
			success: widget_loaded
		});
*/
	});
}

	function addToShoppingcart($product_id, $product_quantity){
		$.post("/shoppingcart/increase_product_count", { product_id: $product_id, count: $product_quantity },
			function(data){
				refresh_widgets( { shoppingcart_product_update_id: $product_id } );
			}
		);
	}
	function removeFromShoppingcart($product_id, $product_quantity){
		$.post("/shoppingcart/decrease_product_count", { product_id: $product_id, count: $product_quantity },
			function(data){
				refresh_widgets( { shoppingcart_product_update_id: $product_id } );
			}
		);
	}
	function removeProductFromShoppingcart($product_id){
		$.post("/shoppingcart/remove_product", { product_id: $product_id },
			function(data){
				refresh_widgets( {} );
			}
		);
	}

	function selectPaymentOption($payment_type_id){
		$.post("/shoppingcart/select_payment_type", { payment_type_id: $payment_type_id },
			function(data){
				refresh_widgets( {} );
			}
		);
	}

	function selectDeliveryOption($delivery_type_id){
		$.post("/shoppingcart/select_delivery_type", { delivery_type_id: $delivery_type_id },
			function(data){
				refresh_widgets( {} );
			}
		);
	}

