<script type="text/javascript">
	$(document).ready(function() {
		var check_module = function() {
			// Gemmer alle
			$(".shipping_module").hide();

			$("#shop").val('');

			// Finder den der er checked
			var e = $("input[type=radio].shipping:checked");

			var shipping_id = e.data('shipping-id');

			if (e) {
				var module_name = e.attr('module');

				// Hvis den der er checked også har en module-attribut, så viser vi den
				if (module_name.length > 1) {
					var module = $("#shipping_module_" + shipping_id).show();

					$("#shop").val($(module.find('select option:selected')).val());
				}
			}

		}
		// Loader
		$("input.shipping").ready(check_module).change(check_module);

		$(".shop_select").change(function() {
			$("#shop").val($(this).val());
		});
	});
</script>

<{if $get.missing}>
	<div class="alert alert-warning">Du skal vælge leveringsmetode</div>
<{/if}>

<{if $is_postdanmark_down_again}>
	<div class="alert alert-warning">PostNord er desværre ikke tilgængelig i øjeblikket.</div>
<{/if}>

<{if $shipping && $shipping->getModule() && $no_shops}>
	<div class="alert alert-warning">
		<p>Vi fandt desværre ikke nogen pakkeshop - er du sikker på at din adresse er rigtig?</p>
		<p><a href="/address"/>&laquo; gå tilbage og ret</a></p>
	</div>
<{/if}>

<{if $shipping && $shipping->getModule() == "burd" && !$bird_delivery}>
	<div class="alert alert-warning">Der er <strong>desværre ikke</strong> Burd levering til postnummer <{$session_del.zipcode|escape}></div>
<{/if}>

<form action="" method="post">

	<div class="row justify-content-center checkoutStep"
		data-step="Shipping"
		>
		<div class="col-12 col-md-6">

			<{include file="check-out-billing.html"}>

			<div class="checkout-section active"><span>2</span> Leveringsmetode</div>
				<div class="checkout-delivery active">

				<{assign var="shippings" value=$webshop->getShippings()}>
				<ul class="delivery-options">
					<li><strong>Vælg leveringsmetode</strong></li>
					<li>
						<{section name="i" loop=$shippings}>
							<div class="delivery-option">
								<input class="shipping" data-shipping-id="<{$shippings[i]->getShippingId()}>" type="radio" module="<{$shippings[i]->getModule()|escape}>" value="<{$shippings[i]->getShippingId()}>" name="shipping_id" id="shipping<{$shippings[i]->getShippingId()}>" <{if $session_del.shipping_id == $shippings[i]->getShippingId()}>checked="checked"<{/if}>/>
								<label for="shipping<{$shippings[i]->getShippingId()}>" class="checkbox"><{$shippings[i]->getName()|escape}><span><{$shippings[i]->getCost()|number_format:2:",":"."}> <{$webshop->getCurrency()}></label>
							</div>
							<div class="clearfix"></div>
						<{/section}>
					</li>

				</ul>

				<input type="hidden" name="shop" id="shop" value="">

				<{section name="i" loop=$shippings}>
					<{if $shippings[i]->getModule()}>
						<{assign var="shops" value=$shippings[i]->getDeliveryShops()}>

						<div class="shipping_module" id="shipping_module_<{$shippings[i]->getShippingId()}>">
							<div class="checkout-content">
								<label>Hvor vil du hente din pakke?</label>
								<select class="shop_select">
									<{section name="j" loop=$shops}>
										<option value="<{$shops[j].number}>" <{if $session_del.shop == $shops[j].number}>selected="selected"<{/if}>/>
											(<{$shops[j].number}>) <{$shops[j].name|escape}> &middot; <{$shops[j].street|escape}> &middot; <{$shops[j].zip|escape}> <{$shops[j].city|escape}>
										</option>
									<{/section}>
								</select>
							</div>
						</div>

					<{/if}>
				<{/section}>

				<{if $shops && false}>
					<div class="shipping_module" id="shipping_module" style="display:none;">
						<div class="checkout-content">
							<label>Hvor vil du hente din pakke?</label>
							<select name="shop">
								<{section name="i" loop=$shops}>
									<option value="<{$shops[i].number}>" <{if $session_del.shop == $shops[i].number}>selected="selected"<{/if}>/>
										<{$shops[i].name|escape}> &middot; <{$shops[i].street|escape}> &middot; <{$shops[i].zip|escape}> <{$shops[i].city|escape}>
									</option>
								<{/section}>
							</select>
						</div>
					</div>
				<{/if}>

			</div>

			<div class="clearfix"></div>

			<{if $webshop->getSkipApprove()}>
				<input class="btn btn-success continue button color checkoutStepProceed paymentStep" type="submit" name="next" value="Godkend ordre og betal"/>
				<div class="checkout-section"><span>3</span> Betaling</div>
			<{else}>
				<input class="btn btn-success continue button color checkoutStepProceed" type="submit" name="next" value="Fortsæt"/>
				<div class="checkout-section"><span>3</span> Godkendelse</div>
				<div class="checkout-section"><span>4</span> Betaling</div>
			<{/if}>

		</div>

		<div class="col-12 col-md-6">
			<{include file="check-out-basket.html"}>
		</div>

	</div>

</form>