<?php
header("Content-type: text/javascript; charset=utf-8");
if (!isset($_GET['controller']) || $_GET['controller'] != 'pjFront' || $_GET['action'] != 'pjActionLoadInvoice')
{
	header("HTTP/1.1 403 Forbidden");
	exit;
}
?>
<script>
var ShoppingCart_<?php echo (int) $_GET['id']; ?> = (function () {
	"use strict";
	var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor),
		loadCss = function (url) {
			var link = document.createElement("link");
			link.type = "text/css";
			link.rel = "stylesheet";
			link.href = url;
			document.getElementsByTagName("head")[0].appendChild(link);
		},
		loadScript = function (url, callback) {
			var script = document.createElement("script");
			script.type = "text/javascript";
			script.async = true;
			if (script.readyState) {
				script.onreadystatechange = function () {
					if (script.readyState == "loaded" || script.readyState == "complete") {
						script.onreadystatechange = null;
						if (callback && typeof callback === "function") {
							callback();
						}
					}
				};
			} else {
				script.onload = function () {
					if (callback && typeof callback === "function") {
						callback();
					}
				};
			}
			script.src = url;
			document.getElementsByTagName("head")[0].appendChild(script);
		},
		createSessionId = function () {
			var sessionId = getSessionId();
			if (sessionId) {
				return;
			}
			sessionId = "";
			var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
			for (var i = 0; i < 32; i++) {
				sessionId += chars.charAt(Math.floor(Math.random() * chars.length));
			}
			sessionStorage.setItem("pjShoppingCart_session_id", sessionId);
		},
		getSessionId = function () {
			return sessionStorage.getItem("pjShoppingCart_session_id");
		},
		options = {
			server: "<?php echo PJ_INSTALL_URL; ?>",
			folder: "<?php echo PJ_INSTALL_FOLDER; ?>",
			layout: <?php echo (int) $tpl['option_arr']['o_layout']; ?>,
			locale: <?php echo (int) $controller->getLocaleId(); ?>,
			index: <?php echo (int) $_GET['id']; ?>,
			hide: <?php echo (int) @$_GET['hide']; ?>,
			queryString: <?php echo json_encode($_GET); ?>,
			theme: "<?php echo $tpl['option_arr']['o_theme']; ?>",
			rb_theme: "<?php echo str_replace('theme', '', $tpl['option_arr']['o_theme']); ?>",
			google_api_key: "<?php echo @$tpl['option_arr']['o_google_api_key']; ?>",
			address_searching: "<?php echo pjSanitize::html(__('front_address_searching', true) ?: 'Searching address...'); ?>",
			address_no_results: "<?php echo pjSanitize::html(__('front_address_no_results', true) ?: 'No results found'); ?>",
			address_select_hint: "<?php echo pjSanitize::html(__('front_address_select_hint', true) ?: 'Select an address from the list'); ?>",
			phone_invalid: "<?php echo pjSanitize::html(__('front_phone_invalid', true) ?: 'Enter a valid phone number'); ?>",
			email_suggestion: "<?php echo pjSanitize::html(__('front_email_suggestion', true) ?: 'Did you mean'); ?>",
			vat_number: "<?php echo pjSanitize::html(__('front_vat_number', true) ?: 'VAT number'); ?>",
			vat_placeholder: "<?php echo pjSanitize::html(__('front_vat_number_placeholder', true) ?: 'e.g. NL123456789B01'); ?>",
			vat_validating: "<?php echo pjSanitize::html(__('front_vat_validating', true) ?: 'Checking VAT number...'); ?>",
			vat_valid: "<?php echo pjSanitize::html(__('front_vat_valid', true) ?: 'Valid VAT number'); ?>",
			vat_invalid: "<?php echo pjSanitize::html(__('front_vat_invalid', true) ?: 'Invalid VAT number'); ?>",
			vat_reverse_charge: "<?php echo pjSanitize::html(__('front_vat_reverse_charge', true) ?: 'VAT reverse charged'); ?>",
			vat_reverse_charge_note: "<?php echo pjSanitize::html(__('front_vat_reverse_charge_note', true) ?: 'VAT reverse charged according to EU regulations — no VAT applicable'); ?>",
			vat_company_notice: "<?php echo pjSanitize::html(__('front_vat_company_notice', true) ?: 'Business customer? Enter your VAT number for VAT-free delivery within the EU.'); ?>",
			vat_country_mismatch: "<?php echo pjSanitize::html(__('front_vat_country_mismatch', true) ?: 'Country code in VAT number does not match the selected country'); ?>",
			vat_country_mismatch_detail: "<?php echo pjSanitize::html(__('front_vat_country_mismatch_detail', true) ?: 'VAT number starts with {vat_country}, but the billing address is set to {billing_country}. Change the country at Billing Address.'); ?>",
			<?php $pi = isset($tpl['popup_i18n']) ? $tpl['popup_i18n'] : array(); ?>
			cart_added_title: "<?php echo pjSanitize::html(!empty($pi['cart_added_title']) ? $pi['cart_added_title'] : (__('added_to_cart', true) ?: 'Added to cart')); ?>",
			cart_btn_continue: "<?php echo pjSanitize::html(!empty($pi['cart_btn_continue']) ? $pi['cart_btn_continue'] : 'Continue shopping'); ?>",
			cart_btn_go_to_cart: "<?php echo pjSanitize::html(!empty($pi['cart_btn_go_to_cart']) ? $pi['cart_btn_go_to_cart'] : (__('go_to_cart_btn', true) ?: 'To shopping cart')); ?>",
			front_cart_recommendations_title: "<?php echo pjSanitize::html(__('front_cart_recommendations_title', true) ?: 'You might also be interested in'); ?>",
			front_checkout_continue_btn: "<?php echo pjSanitize::html(__('front_checkout_continue_btn', true) ?: 'Continue to checkout'); ?>",
			front_add_to_cart: "<?php echo pjSanitize::html(__('front_add_to_cart', true) ?: 'Add to cart'); ?>",
			front_price_from: "<?php echo pjSanitize::html(__('front_price_from', true) ?: 'from'); ?>",
			front_price_for: "<?php echo pjSanitize::html(__('front_price_for', true) ?: 'for'); ?>",
			front_qty_max_exceeded: "<?php echo pjSanitize::html(__('front_qty_max_exceeded', true) ?: 'Only {max} items available.'); ?>",
			shipping_no_title: "<?php echo pjSanitize::html(!empty($pi['shipping_no_title']) ? $pi['shipping_no_title'] : 'No shipping available'); ?>",
			shipping_no_text: "<?php echo !empty($pi['shipping_no_text']) ? addslashes($pi['shipping_no_text']) : 'Shipping is not available for the chosen country.'; ?>",
			shipping_no_btn_address: "<?php echo pjSanitize::html(!empty($pi['shipping_no_btn_address']) ? $pi['shipping_no_btn_address'] : 'Enter another address'); ?>",
			shipping_no_btn_option: "<?php echo pjSanitize::html(!empty($pi['shipping_no_btn_option']) ? $pi['shipping_no_btn_option'] : 'Choose another option'); ?>",
			delivery_area_title: "<?php echo pjSanitize::html(!empty($pi['delivery_area_title']) ? $pi['delivery_area_title'] : (__('front_delivery_area_outside_title', true) ?: 'Outside delivery area')); ?>",
			delivery_area_text: "<?php echo !empty($pi['delivery_area_text']) ? addslashes($pi['delivery_area_text']) : (__('front_delivery_area_outside_text', true) ?: 'Unfortunately we do not deliver to postcode <strong>{postcode}</strong>.<br>What would you like to do?'); ?>",
			delivery_area_btn_address: "<?php echo pjSanitize::html(!empty($pi['delivery_area_btn_address']) ? $pi['delivery_area_btn_address'] : (__('front_delivery_area_btn_other_address', true) ?: 'Enter another address')); ?>",
			delivery_area_btn_option: "<?php echo pjSanitize::html(!empty($pi['delivery_area_btn_option']) ? $pi['delivery_area_btn_option'] : 'Choose another option'); ?>",
			checkout_change_title: "<?php echo pjSanitize::html(!empty($pi['checkout_change_title']) ? $pi['checkout_change_title'] : (__('front_change_address', true) ?: 'Change address')); ?>",
			checkout_change_text: "<?php echo pjSanitize::html(!empty($pi['checkout_change_text']) ? $pi['checkout_change_text'] : (__('front_checkout_change_warning', true) ?: 'Note: changing the address may change the shipping costs.')); ?>",
			checkout_change_btn: "<?php echo pjSanitize::html(!empty($pi['checkout_change_btn']) ? $pi['checkout_change_btn'] : (__('front_change_address', true) ?: 'Change')); ?>",
			checkout_cancel_btn: "<?php echo pjSanitize::html(!empty($pi['checkout_cancel_btn']) ? $pi['checkout_cancel_btn'] : 'Cancel'); ?>",
			front_cart_manual_address: "<?php echo pjSanitize::html(__('front_cart_manual_address', true) ?: 'Or enter your address manually'); ?>",
			front_apply_address: "<?php echo pjSanitize::html(__('front_apply_address', true) ?: 'Apply address'); ?>",
			front_cancel: "<?php echo pjSanitize::html(__('front_cancel', true) ?: 'Cancel'); ?>",
			ship_shipping_area: "<?php echo pjSanitize::html(__('front_ship_shipping_area', true) ?: 'Shipping area'); ?>",
			ship_we_ship_to: "<?php echo pjSanitize::html(__('front_ship_we_ship_to', true) ?: 'We ship to'); ?>",
			ship_more_info_rates: "<?php echo pjSanitize::html(__('front_ship_more_info_rates', true) ?: 'More information and rates'); ?>",
			ship_area_and_rates: "<?php echo pjSanitize::html(__('front_ship_area_and_rates', true) ?: 'Shipping area & rates'); ?>",
			ship_delivery_area: "<?php echo pjSanitize::html(__('front_ship_delivery_area', true) ?: 'Delivery area'); ?>",
			ship_close: "<?php echo pjSanitize::html(__('front_ship_close', true) ?: 'Close'); ?>",
			ship_show_large_map: "<?php echo pjSanitize::html(__('front_ship_show_large_map', true) ?: 'Show large map'); ?>",
			ship_free_from: "<?php echo pjSanitize::html(__('front_ship_free_from', true) ?: 'Free from'); ?>",
			ship_from_price: "<?php echo pjSanitize::html(__('front_ship_from_price', true) ?: 'from'); ?>",
			ship_your_costs: "<?php echo pjSanitize::html(__('front_ship_your_costs', true) ?: 'Shipping costs for your order:'); ?>",
			ship_hint: "<?php echo pjSanitize::html(__('front_ship_hint', true) ?: 'Enter your address above to calculate shipping costs.'); ?>",
			ship_letterbox: "<?php echo pjSanitize::html(__('front_ship_letterbox', true) ?: 'Letterbox'); ?>",
			ship_small: "<?php echo pjSanitize::html(__('front_ship_small', true) ?: 'Small'); ?>",
			ship_standard: "<?php echo pjSanitize::html(__('front_ship_standard', true) ?: 'Standard'); ?>",
			ship_large: "<?php echo pjSanitize::html(__('front_ship_large', true) ?: 'Large'); ?>",
			ship_delivery_zone: "<?php echo pjSanitize::html(__('front_ship_delivery_zone', true) ?: 'Delivery zone'); ?>",
			pay_order_number: "<?php echo pjSanitize::html(__('front_pay_order_number', true) ?: 'Order number:'); ?>",
			pay_total: "<?php echo pjSanitize::html(__('front_pay_total', true) ?: 'Total:'); ?>",
			pay_confirmation_to: "<?php echo pjSanitize::html(__('front_pay_confirmation_to', true) ?: 'Confirmation to:'); ?>",
			pay_reason: "<?php echo pjSanitize::html(__('front_pay_reason', true) ?: 'Reason:'); ?>",
			pay_back_to_shop: "<?php echo pjSanitize::html(__('front_pay_back_to_shop', true) ?: 'Back to the webshop'); ?>",
			pay_status_error: "<?php echo pjSanitize::html(__('front_pay_status_error', true) ?: 'Could not retrieve status'); ?>",
			pay_still_pending: "<?php echo pjSanitize::html(__('front_pay_still_pending', true) ?: 'Payment is still being processed. Please try again in a few seconds.'); ?>",
			pay_connection_error: "<?php echo pjSanitize::html(__('front_pay_connection_error', true) ?: 'Connection error. Please try again.'); ?>",
			pay_checking: "<?php echo pjSanitize::html(__('front_pay_checking', true) ?: 'Checking...'); ?>",
			pay_create_error: "<?php echo pjSanitize::html(__('front_pay_create_error', true) ?: 'An error occurred while creating the payment.'); ?>",
			pay_provider_error: "<?php echo pjSanitize::html(__('front_pay_provider_error', true) ?: 'An error occurred while connecting to the payment provider. Please try again.'); ?>",
			pay_form_error: "<?php echo pjSanitize::html(__('front_pay_form_error', true) ?: 'An error occurred while loading the payment form. Please try again.'); ?>",
			auth_no_account: "<?php echo pjSanitize::html(__('front_auth_no_account', true) ?: 'No account found with this email address.'); ?>",
			auth_create_account: "<?php echo pjSanitize::html(__('front_auth_create_account', true) ?: 'Create a new account'); ?>",
			auth_order_as_guest: "<?php echo pjSanitize::html(__('front_auth_order_as_guest', true) ?: 'order as guest'); ?>",
			auth_fill_credentials: "<?php echo pjSanitize::html(__('front_auth_fill_credentials', true) ?: 'Enter your email address and password.'); ?>",
			auth_logging_in: "<?php echo pjSanitize::html(__('front_auth_logging_in', true) ?: 'Logging in...'); ?>",
			auth_logged_in: "<?php echo pjSanitize::html(__('front_auth_logged_in', true) ?: 'Logged in! Loading checkout...'); ?>",
			auth_login_failed: "<?php echo pjSanitize::html(__('front_auth_login_failed', true) ?: 'Login failed. Please check your credentials.'); ?>",
			auth_login_btn: "<?php echo pjSanitize::html(__('front_auth_login_btn', true) ?: 'Log in'); ?>",
			auth_email_in_use: "<?php echo pjSanitize::html(__('front_auth_email_in_use', true) ?: 'This email address is already in use.'); ?>",
			auth_login_existing: "<?php echo pjSanitize::html(__('front_auth_login_existing', true) ?: 'Log in with your existing account'); ?>",
			error_generic: "<?php echo pjSanitize::html(__('front_error_generic', true) ?: 'An error has occurred'); ?>",
			shop_unavailable_title: "<?php echo pjSanitize::html(__('front_shop_unavailable_title', true) ?: 'Not available'); ?>",
			shop_unavailable_text: "<?php echo pjSanitize::html(__('front_shop_unavailable_text', true) ?: 'This webshop is temporarily unavailable for orders.'); ?>",
			searching: "<?php echo pjSanitize::html(__('front_searching', true) ?: 'Searching...'); ?>",
			cart_address_required: "<?php echo pjSanitize::html(__('front_cart_address_required', true) ?: 'Please enter a complete address (including house number)'); ?>",
			s2f_title: "<?php echo pjSanitize::html(!empty($pi['s2f_popup_title']) ? $pi['s2f_popup_title'] : (__('front_send_to_friend', true) ?: 'Forward to a friend')); ?>",
			s2f_your_name: "<?php echo pjSanitize::html(!empty($pi['s2f_your_name_label']) ? $pi['s2f_your_name_label'] : (__('front_s2f_your_name', true) ?: 'Your name')); ?>",
			s2f_your_email: "<?php echo pjSanitize::html(!empty($pi['s2f_your_email_label']) ? $pi['s2f_your_email_label'] : (__('front_s2f_your_email', true) ?: 'Your email address')); ?>",
			s2f_friend_name: "<?php echo pjSanitize::html(!empty($pi['s2f_friend_name_label']) ? $pi['s2f_friend_name_label'] : (__('front_s2f_friend_name', true) ?: 'Friend name')); ?>",
			s2f_friend_email: "<?php echo pjSanitize::html(!empty($pi['s2f_friend_email_label']) ? $pi['s2f_friend_email_label'] : (__('front_s2f_friend_email', true) ?: 'Friend email')); ?>",
			s2f_message: "<?php echo pjSanitize::html(!empty($pi['s2f_message_label']) ? $pi['s2f_message_label'] : (__('front_s2f_message', true) ?: 'Personal message (optional)')); ?>",
			s2f_message_placeholder: "<?php echo pjSanitize::html(!empty($pi['s2f_message_placeholder']) ? $pi['s2f_message_placeholder'] : 'Write a message...'); ?>",
			s2f_send: "<?php echo pjSanitize::html(!empty($pi['s2f_btn_send']) ? $pi['s2f_btn_send'] : (__('front_send', true) ?: 'Send')); ?>",
			s2f_cancel: "<?php echo pjSanitize::html(!empty($pi['s2f_btn_cancel']) ? $pi['s2f_btn_cancel'] : (__('front_cancel', true) ?: 'Cancel')); ?>",
			s2f_err_required: "<?php echo pjSanitize::html(__('front_s2f_err_required', true) ?: 'Please fill in all required fields'); ?>",
			s2f_err_email: "<?php echo pjSanitize::html(__('front_s2f_err_email', true) ?: 'Please enter a valid email address'); ?>",
			s2f_sent_title: "<?php echo pjSanitize::html(!empty($pi['s2f_success_title']) ? $pi['s2f_success_title'] : 'Sent!'); ?>",
			s2f_sent_text: "<?php echo pjSanitize::html(!empty($pi['s2f_success_text']) ? $pi['s2f_success_text'] : 'The product has been forwarded to your friend.'); ?>"
		
	};
	<?php
	$dm = new pjDependencyManager(PJ_INSTALL_PATH, PJ_THIRD_PARTY_PATH);
	$dm->load(PJ_CONFIG_PATH . 'dependencies.php')->resolve();
	$shopping_cart_js = PJ_JS_PATH . 'pjShoppingCart.js';
	$shopping_cart_js_version = @filemtime(PJ_INSTALL_PATH . $shopping_cart_js);
	?>
	loadScript("<?php echo PJ_INSTALL_URL . $dm->getPath('storage_polyfill'); ?>storagePolyfill.min.js", function () {
		if (isSafari) {
			createSessionId();
			options.session_id = getSessionId();
		}else{
			options.session_id = "";
		}
		loadScript("<?php echo PJ_INSTALL_URL . $shopping_cart_js . ($shopping_cart_js_version ? '?v=' . $shopping_cart_js_version : ''); ?>", function () {
			ShoppingCart.init(options);
		});
	});
})();
