<script type="text/javascript">
	$(document).ready(function() {

		var ean_bg = $("#ean_number").css('backgroundColor');
		var ean_fg = $("#ean_number").css('color');

		$("#ean_number").keyup(function(e) {
			var ean = $("#ean_number").val();
			$("#ean_number").val(ean.replace(/[^0-9]+/gi, ''));

			if (ean.length == 0 || ean.length == 13) {
				$("#ean_number").css('background', ean_bg);
				$("#ean_number").css('color', ean_fg);
			}
		});

		$("#ean_number").focusout(function(e) {
			var ean = $("#ean_number").val();

			if (ean.length > 0 && ean.length != 13) {
				$("#ean_number").css('background', '#a00');
				$("#ean_number").css('color', '#fff');
			}
			else {
				$("#ean_number").css('background', ean_bg);
				$("#ean_number").css('color', ean_fg);
			}
		});

		$("#address_form").submit(function() {
			var ean = $("#ean_number").val();
			if (ean.length > 0 && ean.length != 13) {
				$("#ean_number").focus();
				alert("Dit EAN-nummer skal være på 13 cifre.");
				return false;
			}
		});

		$("#address_form input").keyup(function() {
			if ($("#copy").is(":checked")) {
				var element = $(this);
				var id = element.attr("id");

				if (id && id.split("_")[0] == "order") {
					$("#del" + id.substr(5)).val(element.val());
				}

			}
		});

		$("#address_form select").change(function() {
			if ($("#copy").is(":checked")) {
				var element = $(this);
				var id = element.attr("id");

				if (id && id.split("_")[0] == "order") {
					$("#del" + id.substr(5)).val(element.val());
				}
			}
		});

		$("#add_company").click(function() {
			if ($(this).is(":checked")) {
				$("#company_info").show();
			}
			else {
				$("#company_info").hide();
			}
		});

		$("#copy").click(function() {
			if ($(this).is(":checked")) {
				$("#del_area").hide();

				$("form input").each(function(index, e) {
					var element = $(e);
					var id = element.attr("id");

					if (id && id.split("_")[0] == "order") {
						$("#del" + id.substr(5)).val(element.val());
					}
				});
			}
			else {
				$("#del_area").show();
			}
		});
	});
</script>

<{if $get.exists}>
	<div class="alert alert-danger">Profilen findes allerede.</div>
<{/if}>

<{if $get.missing_address}>
	<div class="alert alert-danger">Mangler adresse</div>
<{/if}>

<form action="" method="post" id="address_form">
	<div class="row checkoutStep"
		data-step="Address"
		>
		<div class="col-12 col-md-6">

		<div class="checkout-section active"><span>1</span> Faktureringsoplysninger</div>

			<div class="checkout-content">
				<span class="shippping-checkbox">
					<input class="input-checkbox" id="add_company" type="checkbox" name="add_company" value="1" <{if $session_order.company_name || $session_order.vat_number}>checked<{/if}>/>
					<label for="add_company" class="checkbox">Erhverv/offentlig</label>
				</span>

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

				<{assign var="countries" value=$webshop->getCountries()}>
				<{if $countries}>
					<label class="billing">Land: <abbr>*</abbr></label>
					<select id="order_country_id" name="order_country_id" required>
						<{section name="i" loop=$countries}>
							<option value="<{$countries[i]->getCountryId()}>" <{if $session_order.country_id == $countries[i]->getCountryId()}>selected="selected"<{/if}>><{$countries[i]->getName()|escape}></option>
						<{/section}>
					</select>
				<{/if}>

				<label for="order_name">Navn <abbr>*</abbr></label>
				<input type="text" name="order_name" value="<{$session_order.name|escape}>" id="order_name" required/>

				<div id="company_info" <{if !$session_order.company_name && !$session_order.vat_number}>style="display:none"<{/if}>>
					<label for="order_company_name">Evt. firmanavn</label>
					<input type="text" name="order_company_name" value="<{$session_order.company_name|escape}>" id="order_company_name"/>

					<label for="vat_number">Evt. CVR-nummer</label>
					<input type="text" name="vat_number" value="<{$session_order.vat_number|escape}>" id="vat_number"/>

					<label for="ean_number">Evt. EAN-nummer</label>
					<input type="text" maxlength="13" name="ean_number" value="<{$session_order.ean_number|escape}>" id="ean_number"/>
				</div>

				<label for="order_address">Adresse <abbr>*</abbr></label>
				<input type="text" name="order_address" value="<{$session_order.address|escape}>" id="order_address" required/>

				<label for="order_zipcode">Postnummer <abbr>*</abbr></label>
				<input type="text" name="order_zipcode" value="<{$session_order.zipcode|escape}>" id="order_zipcode" required/>

				<label for="order_city">By <abbr>*</abbr></label>
				<input type="text" name="order_city" value="<{$session_order.city|escape}>" id="order_city" required/>

				<label>E-mail-adresse <abbr>*</abbr></label>
				<input type="text" placeholder="" name="email" value="<{$session_order.email|escape}>"  required/>

				<label>Telefonnummer <abbr>*</abbr></label>
				<input type="text" placeholder="" name="phone" value="<{$session_order.phone|escape}>"  required/>

				<label for="comments">Kommentar</label>
				<textarea name="comments" class="fullwidth"><{$session_order.comments|escape}></textarea>

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

				<span class="shippping-checkbox">
					<input class="input-checkbox" id="copy" type="checkbox" name="copy" checked="checked" value="1" />
					<label for="copy" class="checkbox">Levering til ovenstående adresse</label>
				</span>

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

				<{if $settings.settings.show_login}>
					<span class="shippping-checkbox">
						<input class="input-checkbox" type="checkbox" id="create_profile" name="create_profile" value="1" checked/>
						<{if $webshop->hasLoyaltyProgram() && $webshop->getLoyaltyProgramSignupPoints()}>
							<label for="create_profile" class="checkbox">Opret gratis konto, og optjen <{$webshop->getLoyaltyProgramSignupPoints()|number_format:0:",":"."}> point.</label>
						<{else}>
							<label for="create_profile" class="checkbox">Opret gratis konto</label>
						<{/if}>
					</span>

					<div class="clearfix"></div>
				<{/if}>

				<span class="shippping-checkbox">
					<input class="input-checkbox" type="checkbox" name="mailinglist" id="mailinglist" <{if $join_mailinglist}>checked="checked"<{/if}> value="1"/>
					<label for="mailinglist" class="checkbox">Tilmeld dig nyhedsbrev?</label>
				</span>

				<{if $settings.gdpr.newsletter}>
					<div class="clearfix"></div>
					<{if $settings.gdpr.newsletter|strlen > 100}>
						<div class="newsletter-terms">
							<small><{$settings.gdpr.newsletter}></small>
						</div>
					<{else}>
						<div>
							<small><{$settings.gdpr.newsletter}></small>
						</div>
					<{/if}>
				<{/if}>

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

				<div id="del_area" style="display:none;">
					<div class="my-2"></div>

					<h3 class="headline">Leveringsadresse</h3>
					<span class="line"></span>
					<div class="clearfix"></div>

					<div class="my-2"></div>

					<label for="del_name">Navn</label>
					<input type="text" name="del_name" value="<{$session_del.name|escape}>" id="del_name"/>

					<label for="del_company_name">Firmanavn</label>
					<input type="text" name="del_company_name" value="<{$session_del.company_name|escape}>" id="del_company_name"/>

					<label for="del_address">Adresse</label>
					<input type="text" name="del_address" value="<{$session_del.address|escape}>" id="del_address"/>

					<label for="del_zipcode">Postnummer</label>
					<input type="text" name="del_zipcode" value="<{$session_del.zipcode|escape}>" id="del_zipcode"/>

					<label for="del_city">By</label>
					<input type="text" name="del_city" value="<{$session_del.city|escape}>" id="del_city"/>

					<{assign var="countries" value=$webshop->getCountries()}>
					<{if $countries}>
						<label for="del_country_id">Land</label>
						<select id="del_country_id" name="del_country_id">
							<{section name="i" loop=$countries}>
								<option value="<{$countries[i]->getCountryId()}>" <{if $session_del.country_id == $countries[i]->getCountryId()}>selected="selected"<{/if}>><{$countries[i]->getName()|escape}></option>
							<{/section}>
						</select>
					<{/if}>

				</div>

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

			</div>

			<{if $webshop->getSkipApprove()}>
				<div class="my-3 checkout-content">
					<h3>Handelsbetingelser</h3>
					<div class="terms">
						<{if $settings.texts.terms}>
							<{$settings.texts.terms}>
						<{else}>
							Denne shop har ikke nogen betingelser.
							Enten opret nogen, eller indsæt en tom tekst under dine <a href="<{$url|escape}>/theme-setup/settings#tabs-5" target="_blank">designindstillinger</a>.
						<{/if}>
					</div>
				</div>

				<div class="my-4"></div>

				<div class="form-group">
					<input class="input-checkbox" id="accept" type="checkbox" name="accept" value="1" required/>
					<label for="accept" class="checkbox">Jeg accepterer ovenstående handelsbetingelser.</label>
				</div>

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

				<div class="my-4"></div>
			<{/if}>

			<{assign var="shippings" value=$webshop->getShippings()}>

			<{if $shippings|@count == 1 && $webshop->getSkipApprove()}>
				<input class="btn btn-success continue button color checkoutStepProceed" type="submit" name="skip_next" value="Godkend ordre og betal"/>
			<{else}>
				<input class="btn btn-success continue button color checkoutStepProceed" type="submit" name="next" value="Fortsæt"/>
			<{/if}>

			<div class="checkout-section"><span>2</span> Levering</div>

			<{if $webshop->getSkipApprove()}>
				<div class="checkout-section"><span>3</span> Betaling</div>
			<{else}>
				<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>

<div class="margin-top-50"></div>