



//<!--
/* <![CDATA[ */

/*
 * ID:EXTERNAL_WIDGET_FITANALYTICS_CORE
 */

jQuery(document).bind("track:onview", function(event) {

	var reportPurchaseURL = "//collector.fitanalytics.com/report_purchase.js";

	// report confirmation page
	var reportPurchase = function() {
		// get country and language from pagecontext
		var shopCountry = (PageContext.get('global.constants.locale.country') == "")?"DE":PageContext.get('global.constants.locale.country');
		var language = (PageContext.get('global.constants.locale.language') == "")?"de":PageContext.get('global.constants.locale.language');

		jQuery.each(PageContext.get('order.allProductLineItems'),function(key,pli) {
			var jsonProduct = new Object();
			jsonProduct.productId = PageContext.get('global.constants.brand.name') + "-" + pli.masterId;
			jsonProduct.orderId = PageContext.get('order.orderNo');
			jsonProduct.userId = PageContext.get('customer.id');
			jsonProduct.purchasedSize = pli.size;
			jsonProduct.price = pli.price.value;
			jsonProduct.currency = pli.price.currencyCode;
			jsonProduct.shopCountry = shopCountry;
			jsonProduct.language = language;
			jsonProduct.hostname = '';
			var hostnameSuffix = '';
			if (PageContext.get('global.instanceType') != 'prd') {
				hostnameSuffix = '-test';
			}
			if(MMS.Webview.isAndroid()) {
				jsonProduct.hostname = "embed-android" + hostnameSuffix;
			} else if(MMS.Webview.isIOS()) {
				jsonProduct.hostname = "embed-ios" + hostnameSuffix;
			}
			_sendPurchaseInformation(jsonProduct);
		});
	}

	if (PageContext.get('global.pageType') == PageContext.get('global.availablePages.coconfirmation')) {
		CoreUtils.loadExternalScript(reportPurchaseURL, function(){return true;}, reportPurchase);
	}

});

/* ]]> */
// -->


//<!--
/* <![CDATA[ */

jQuery(document).bind("page:ready", function(event) {

	// check if login modal is enabled
	let loginModalEnabled = PageContext.get('global.constants.loginmodalenabled');
	if (!loginModalEnabled) {
		return;
	}

	// check if current page type is allowed for login modal
	let currentPageType = PageContext.get('global.pageType');
	let avPages = PageContext.get('global.availablePages');
	let notAllowedPages = new Array();

	// add all checkout and myaccount pages to the non allowed pages array
	for (let p in avPages) {
		if (  (p.indexOf('co') == 0 && p.indexOf('contact') == -1)
			|| p.indexOf('myaccount') != -1 ) {
			notAllowedPages.push(avPages[p]);
		}
	}

	if (jQuery.inArray(currentPageType, notAllowedPages) >= 0) {
		return;
	}

	// check if customer is returning
	let customerAuthenticated = PageContext.get('customer.authenticated');
	let customerReturning = PageContext.get('customer.returning');
	if (customerAuthenticated || !customerReturning) {
		return;
	}

	// check if modal was already shown in this session
	let loginModalShown = (CookieUtils.readCookie('loginModalShown') == 1);
	if (loginModalShown) {
		return;
	}
	// create the cookie to control if login modal was already shown
	CookieUtils.createCookie('loginModalShown',1);

	// launch the modal dialog
	let loginModalUrl = PageContext.get('global.constants.url.loginmodal');
	let loginModalOptions = PageContext.get('global.constants.layer.loginmodal');
	ContentUtils.loadDialog(loginModalUrl, loginModalOptions);

});

/* ]]> */
// -->



