"use strict";

// will not be obfuscated
var TTAPI;

window.onload = function () {
	// find TTAPI
	TTAPI = findAPI(parent);
	if (typeof TTAPI === "undefined") {
		return false;
	}

	var objContent = GetParameter("display");
	if (objContent && TTAPI.objTextpool.heap["static_texts"][objContent]) {
		objContent = TTAPI.objTextpool.heap["static_texts"][objContent];
	}

	var objInfo = document.getElementById("ttwpdlgwarninginfo1");
	if (objInfo) {
		objInfo.innerHTML = WarningMessageReplaceTexts(objContent["text01"]._text);
	}

	objInfo = document.getElementById("ttwpdlgwarninginfo2");
	if (objInfo) {
		objInfo.innerHTML = WarningMessageReplaceTexts(objContent["text02"]._text);
	}

	var objCheck = GetParameter("checkbox");
	if (objCheck) {
		var objCheckDiv = document.getElementById(objCheck);
		if (objCheckDiv) {
			objCheckDiv.style.display = "block";
			// input
			var objCheckInput = document.getElementById("ttwecheck1");
			if (objCheckInput) {
				g_objCrossBrowserModel.AddEventListener(objCheckInput, "click", OnClickWarningCheckbox1);
			}
			// label
			var objCheckLabel = document.getElementById("ttwelabelcheck1");
			if (objCheckLabel) {
				objCheckLabel.innerHTML = objContent["text50"]._text;
			}
		}
	}

	// Custom-JS laden?
	var sJSFile = TTAPI.GetProperty("adddlgwarningjs1");
	if (sJSFile) {
		TTAPI.objCrossBrowserModel.LoadJavaScriptFile(TTAPI.GetPathByProperty("adddlgwarningjs1") + sJSFile, window);
	}

	// Custom-CSS laden?
	var sCSSFile = TTAPI.GetProperty("adddlgwarningcss1");
	if (sCSSFile) {
		TTAPI.objCrossBrowserModel.LoadCSSFile(TTAPI.GetPathByProperty("adddlgwarningcss1") + sCSSFile, window, Continue_01);
	} else {
		Continue_01();
	}
};

function WarningMessageReplaceTexts(sText) {
	var nMinutes = TTAPI.GetTimelimit();
	nMinutes = isNaN(nMinutes) ? 0 : nMinutes;
	var minutesOrMinuteText = nMinutes > 1 ? TTAPI.objTextpool.heap["static_texts"]["MINUTES"]["_text"] : TTAPI.objTextpool.heap["static_texts"]["MINUTE"]["_text"];
	return sText.replace("###UNIT###", minutesOrMinuteText).replace("###MINUTES###", nMinutes);
}

function Continue_01() {
	// Don't remove this function! It can be overwritten in player configs!
}

function OnClickWarningCheckbox1(e) {
	var objSource = g_objCrossBrowserModel.EventSource(e);
	if (objSource) {
		TTAPI.Cookies.writeSessionCookie("showpreviewpooldialogue", (objSource.checked ? "false" : "true"));
	}
}
