<!-- template content_cash_desk.tpl -->

{if $error_message}
	{foreach from=$error_message item=message}
		<div style="font-weight:bold;font-size:14px;color:#cc0000;border:#cc0000 1px solid;padding:10px;text-align:center;">
			{$message}
		</div>
		<br />
	{/foreach}
{/if}

{if $customer_data->burth_date == '0000-00-00'}
	<div id="need_customer_burth_date" style="font-weight:bold;font-size:14px;color:#cc0000;border:#cc0000 1px solid;padding:10px;text-align:center;display:none;">
		ACHTUNG!:<br>
		Die Zahlungsart Klarna ben&ouml;tigt Ihr Geburtsdatum. Dieses k&ouml;nnen Sie in Ihren Kontoeinstellungen setzten -> <a href="/Kundencenter/">Kundencenter</a>
	</div>
{/if}

<div class="cashdesk">
	{if isset($guest_order) && $guest_order == 1}<div class="dropdown_title"><span class="info" style="font-size:22px;">Gastbestellung</span></div><br /><br />{/if}
	<form id="order_form" method="post" action="">
		{include file='content_cash_desk/address_invoice.tpl'}
		<br />
		{include file='content_cash_desk/address_shipping.tpl'}
		<br />
		{if $system_configuration.shoppingcart_ordertext == 1}
			{include file='content_cash_desk/customer_info.tpl'}
		{/if}
		<br />
		{include file='content_cash_desk/payments.tpl'}
		<br />
		{include file='content_cash_desk/shipping.tpl'}
		<br />
		{include file='content_cash_desk/agreements.tpl'}
		<br />
		{include file='content_cash_desk/shoppingcart.tpl'}
		<br />

		<input type="hidden" id="cashdesk_action" name="cashdesk_action" value="" />

	</form>
</div>


<script type="text/javascript">

{if !isset($guest_order) || (!$guest_order && $addresses)}
	var addresses = new Array();

	{foreach from=$addresses key=num item=address}
	addresses[{$num}] = {literal} { {/literal}
		company: '{$address->company}',
		honorific: '{$address->honorific}',
		firstname: '{$address->firstname}',
		surname: '{$address->surname}',
		street: '{$address->street}',
		house_number: '{$address->house_number}',
		zip_code: '{$address->zip_code}',
		city: '{$address->city}',
		country: '{$address->country}'
	{literal} } {/literal};
	{/foreach}
{else}
	var addresses = undefined;
{/if}

{if isset($guest_order) && $guest_order == 1}
{literal}
	$('#send_order_button').click(function(e) {
		e.preventDefault();

		if ($('#guest_order_email').val() == '' || 
			$('#billing_honorific').val() == '' || 
			(($('#billing_honorific').val() == '0' || $('#billing_honorific').val() == 1) && ( $('#billing_firstname').val() == '' ||  $('#billing_surname').val() == '')) ||
			($('#billing_honorific').val() == 2 && $('#billing_company').val() == '') ||
			$('#billing_zip_code').val() == '' || 
			$('#billing_city').val() == '' || 
			$('#billing_street').val() == '' || 
			$('#billing_phone').val() == '' || 
			$('#billing_house_number').val() == ''
		) {
			alert('Bitte geben Sie eine vollständige Rechnungsadresse an!');
		}
		else if ($('#shipping_address_select').val() != -1 && 
				(
					$('#shipping_honorific').val() == '' || 
					(($('#shipping_honorific').val() == '0' || $('#shipping_honorific').val() == 1) && ( $('#shipping_firstname').val() == '' ||  $('#shipping_surname').val() == '')) ||
					($('#shipping_honorific').val() == 2 && $('#shipping_company').val() == '') ||
					$('#shipping_zip_code').val() == '' || 
					$('#shipping_city').val() == '' || 
					$('#shipping_street').val() == '' || 
					$('#shipping_house_number').val() == ''
				)
		) {
			alert('Bitte geben Sie eine vollständige Lieferadresse an!');
		}
                else if(!$('#agreements_accepted').attr('checked') || !($('#klarna_agreements_info').css('display') == 'none' || $('#klarna_agreements_accepted').attr('checked'))){
			alert("Sie müssen unsere AGB's bestätigen!");
		}
		else {		
			$('#cashdesk_action').val('ready2fly');
			$('#order_form').submit();
		}

	});

        
	$(document).ready(function() {

	$('#bill_country, #shipping_country').change(function(e) {
		$('#cashdesk_action').val('reload');
		$('#order_form').submit();
	});



});
{/literal}
{else}
{literal}
	$('#send_order_button').click(function(e) {
		e.preventDefault();
		if ($('#billing_address_select').val() == '') {
			//alert('Bitte geben Sie eine vollständige Rechnungsadresse an!');
			alert('Sie haben noch nicht Ihre neue Rechnungsadresse abgespeichert. Der Button "Daten speichern" befindet sich oben beim Adressreld! Durch die Änderung erfolgt eine neue Bezahlkostenberechnung.');
		}
		else if ($('#shipping_address_select').val() == '') {
			//alert('Bitte geben Sie eine vollständige Lieferadresse an!');
			alert('Sie haben noch nicht Ihre neue Lieferadresse abgespeichert. Der Button "Daten speichern" befindet sich oben beim Adressreld! Durch die Änderung erfolgt eine neue Versandkostenberechnung.');
		}
                else if($('#customer_order_email').length && $('#customer_order_email').val() == ''){
			alert("Bitte geben Sie eine E-Mail Adresse ein!");
		}
                else if(!$('#agreements_accepted').attr('checked') || !($('#klarna_agreements_info').css('display') == 'none' || $('#klarna_agreements_accepted').attr('checked'))){
			alert("Sie müssen unsere AGB's bestätigen!");
		}
		else {		
			$('#cashdesk_action').val('ready2fly');
			$('#order_form').submit();
		}

	});
{/literal}
{/if}

</script>

<script src="{$PARENT_THEME_DIR}/media/js/content_cash_desk.js?version=1" type="text/javascript"></script>
