<link href="js/jqueryui/themes/base/jquery-ui.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery-datetimepicker/build/jquery.datetimepicker.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery-datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery-datatables-responsive/css/dataTables.responsive.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery-chosen/chosen.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery-simple-combobox/css/jquery.scombobox.min.css" rel="stylesheet" type="text/css">
<link href="js/select2/css/select2.min.css" rel="stylesheet" type="text/css">
<script>
	var $_LANG = {}
</script>
<script src="js/locale/{$lms_language}.js"></script>
<script src="js/language.js"></script>
<script src="js/jquery/jquery.min.js"></script>
<script src="js/jqueryui/jquery-ui.min.js"></script>
<script src="js/jqueryui/ui/minified/i18n/datepicker-{$language}.js"></script>
<script src="js/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
<script src="js/jquery-datatables/media/js/jquery.dataTables.min.js"></script>
<script src="js/jquery-datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="js/tinymce/tinymce.min.js"></script>
<script src="js/input-autogrow.min.js"></script>
<script src="js/Autolinker.min.js"></script>
<script src="js/clipboard.min.js"></script>
<script src="js/jquery-chosen/chosen.jquery.min.js"></script>
{*
<script src="js/jquery-simple-combobox/js/jquery.scombobox.min.js"></script>
*}
<script src="js/select2/js/select2.min.js"></script>
<script src="js/select2/js/i18n/{$language}.js"></script>
<script src="js/sprintf.min.js"></script>
<script src="js/galleria/galleria.min.js"></script>
<script src="js/galleria/themes/classic/galleria.classic.min.js"></script>
<script>

	var lmsSettings = {
		language: '{$language}',
		uiLanguage: '{$lms_language}',
		fontAwesomeName: 'Font Awesome 6 Free',
		settingsTimeout: {intval(ConfigHelper::getConfig('phpui.settings_timeout', 28800))},
		wysiwygEditor: {if ConfigHelper::getConfig('phpui.default_editor') == 'wysiwyg'}true{else}false{/if},
		helpdeskWysiwygEditor: {if ConfigHelper::getConfig('rt.default_editor') == 'wysiwyg'}true{else}false{/if},
		quickSearchAutoSubmit: '{ConfigHelper::getConfig('phpui.quicksearch_autosubmit', 'true')}',
		defaultTerytCity: '{ConfigHelper::getConfig('phpui.default_teryt_city')}',
        zipCodeBackend: JSON.parse('{json_encode(preg_split("/([\s]+|[\s]*,[\s]*)/", strtolower(ConfigHelper::getConfig('phpui.zipcode_backend', 'osm')), -1, PREG_SPLIT_NO_EMPTY))}'),
        multiSelectPopupOnBottom: {if ConfigHelper::checkConfig('phpui.multiselect_popup_on_bottom', true)}true{else}false{/if},
		multiSelectMaxVisible: '{intval(ConfigHelper::getConfig('phpui.multiselect_max_visible', 5))}',
        eventTimeStep: {ConfigHelper::getConfig('timetable.event_time_step', ConfigHelper::getConfig('phpui.event_time_step', 30))},
		openCalendarOnInputClick: {if ConfigHelper::checkConfig('phpui.open_calendar_on_input_click')}true{else}false{/if},
		uploadedImageMaxSize: {intval(ConfigHelper::getConfig('phpui.uploaded_image_max_size', 0))},
		monthlyPeriod: {$smarty.const.MONTHLY},
		touchDeviceTooltips: {if ConfigHelper::checkConfig('phpui.touch_device_tooltips', 'false')}true{else}false{/if},
		terytShowNumericIdentifiers: {if ConfigHelper::checkConfig('teryt.show_numeric_identifiers')}true{else}false{/if},
		missedNodeWarning: {if ConfigHelper::checkConfig('assignments.missed_node_warning', ConfigHelper::checkConfig('phpui.node_assignment_warning'))}true{else}false{/if},
		discountPercentage: {$smarty.const.DISCOUNT_PERCENTAGE},
		discountAmount: {$smarty.const.DISCOUNT_AMOUNT},
		office2pdfCommand: '{ConfigHelper::getConfig('documents.office2pdf_command', '', true)}',
		mapCreateNewPointAfterLinkEditStart: {if ConfigHelper::checkConfig('map.create_new_point_after_link_edit_start', ConfigHelper::checkConfig('phpui.map_create_new_point_after_link_edit_start'))}true{else}false{/if}
	};

	var lms = {
		utils: {
			smartNumberFormatter: Intl.NumberFormat(lmsSettings.language, {
				style: "decimal",
				useGrouping: "always",
				minimumFractionDigits: 2,
				maximumFractionDigits: 3
			}),
			numberFormatter: Intl.NumberFormat(lmsSettings.language, {
				style: "decimal",
				useGrouping: "always",
				minimumFractionDigits: 2,
				maximumFractionDigits: 2
			}),
			formatNumber: function (value) {
				return this.numberFormatter.format(value);
			},
			smartFormatNumber: function (value) {
				return this.smartNumberFormatter.format(value);
			},
			formatMoney: function (value, currency) {
				return this.formatNumber(value) + ' ' + currency;
			},
			smartFormatMoney: function (value, currency) {
				return this.smartFormatNumber(value) + ' ' + currency;
			}
		},
		permissions: {
			fullAccess: {if ConfigHelper::checkPrivilege('superuser')}true{else}false{/if},
			networkMapEdit: {if ConfigHelper::checkPrivilege('network_map_edit', false)}true{else}false{/if}
		}
	}

	var tooltipsEnabled = true;
	if ("ontouchstart" in document.documentElement && !lmsSettings.touchDeviceTooltips) {
		tooltipsEnabled = false;
	}

	{if ConfigHelper::checkConfig('phpui.disable_mobile_tooltips', true)}
	$(function() {
		if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
			$('[title]').removeAttr('title');
		}
	});
	{/if}

	$(function() {
		{if isset($error) && is_array($error)}
			{foreach $error as $k => $v}
				{if is_array($v)}
					{$v = ""}
				{/if}
				$('[name="{$k|replace:'"':'\"'}"]')
					.attr('title', "{$v|replace:'"':'\"'}")
					.addClass('lms-ui-error');
			{/foreach}
		{/if}
		{if isset($warning) && is_array($warning)}
			{foreach $warning as $k => $v}
				{if is_array($v)}
					{$v = ""}
				{/if}
				var name = "{$k|replace:'"':'\"'}";
				var elem = $('[name="' + name + '"]');
				var form = elem.attr('form');
				var html = '<input type="hidden" name="warning[' + name.replace(/[\[\]]/g, '-') + ']" value="1"' + (typeof(form) != 'undefined' ? ' form="' + form + '"' : '') + '>';
				$('[name="' + name + '"]')
					.attr('title', "{$v|replace:'"':'\"'}")
					.addClass('lms-ui-warning')
					.after(html);
			{/foreach}
		{/if}
	});

</script>
<script src="js/jquery.js"></script>
<script src="js/lms-ui-customer-select.js"></script>
<script src="js/lms-ui-deferred-submit.js"></script>
<script src="js/lms-ui-persistent-filter.js"></script>
<script src="js/lms-ui-dialog.js"></script>
<script src="js/lms-ui-multiselect.js"></script>
<script src="js/lms-ui-dragslider.js"></script>
<script src="js/lms-ui-datepicker.js"></script>
<script src="js/lms-ui-combobox.js"></script>
<script src="js/lms-ui-fileupload.js"></script>
<script src="js/lms-ui-fileview.js"></script>
<script src="js/lms-ui-karma.js"></script>
<script>

	$(function() {
		var elems = $('.lms-ui-error:visible');
		if (elems.length) {
			// scroll view into first erroneous form element
			setTimeout(function () {
				elems.first().get(0).scrollIntoView({
					block: "center"
				});
			}, 0);
		} else {
			elems = $('.lms-ui-warning:visible');
			if (elems.length) {
				// scroll view into first warning form element
				setTimeout(function () {
					elems.first().get(0).scrollIntoView({
						block: "center"
					});
				}, 0);
			}
		}
	});

</script>
