/**
 * Javascript to manage winkelmandje actions
 * 
 */

$(document).ready( function() {
	$('form.formInWinkelmandje').submit(function() {
		var id=$('form.formInWinkelmandje input[name="voorstelling_id"]').attr("value");
	    $.post("/index.php?ajax=true", $(this).serialize(),
	    		
    		function(data) {
				var c = data.html;
				var blnVroegBoekKorting = data.showVroegBoekKorting;
				var blnEerstAfronden = data.blnEerstAfronden;
				if (blnEerstAfronden) {
					var btns = {
							'afronden': {
								action: function() {
									$(this).dialog('close');
									document.location = "/mijntheater/reserveer/";
								}
							},
							'annuleren': {
								action: function() {
									$(this).dialog('close');
									document.location = "/mijntheater/afrekenen/annuleer";
								}
							}
						};
				} else {
					var btns = {
							'bestel tickets': {
								action: function() {
									$(this).dialog('close');
									//document.forms['formOrderBasket'].submit();
									document.location = "/mijntheater/winkelwagen/";
								}
							},
							'verder winkelen': {
								action: 'cancel'
							}
						};
    			}
				
				$.pDialog({
					id: 'addedToCart',
					type: 'message',
					title: (blnEerstAfronden) ? 'Reservering afronden' : 'Concert toegevoegd',
					content: c,
					modal: true,
					keepInDom: false,
					resizable: false,
					draggable: false,
					bringInFocusOnOutsideclick: true,
					width: 360,
					//height: blnVroegBoekKorting ? 380 : 220,
					buttons: btns,
					hideTitleBar: true
				});

				$("#uiDialog-addedToCart").dialog({
				   close: function(event, ui) {
						$("#shoppingBasketContainer").slideDown("normal", function() {
							$("#shoppingBasketContainer .submit").fadeIn(200);
						});
						if (data.count == 1) {
							$("#winkelmandjeAantal").text("1 concert");
						} else {
							$("#winkelmandjeAantal").text(data.count + " concerten");
						}
					}
				});
    		}, 'json'
    		
	    );
		return false;
	});
});

