{% if (languages|length > 1) %}
<!-- Language -->
<div id="language_form">

	<div class="dropdown">
		{% for language in languages %}
			{% if (language['code'] == code) %}
				<a href="#" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown">{{ language['name'] }}</a>
			{% endif %}
		{% endfor %}
		<ul class="dropdown-menu">
			{% for language in languages %}
				<li>
					{% if language.main %}
						<a href="{{ language.url }}" onclick="lm_deleteCookie('languageauto'); window.location = '{{ language.url }}'">{{ language['name'] }}</a>
					{% else %}
						<a href="{{ language.url }}" onclick="lm_setCookie('languageauto', '1', {expires: 180});  window.location = '{{ language.url }}'">{{ language['name'] }}</a>
					{% endif %}
				</li>
			{% endfor %}
		</ul>
	</div>

</div>

<script>
function lm_setCookie(name, value, options = {}) {
options = {
path: '/',
...options
};

	let date = new Date(Date.now() + (86400e3 * options.expires));
	date = date.toUTCString();
	options.expires = date;

	let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);

	for (let optionKey in options) {
		updatedCookie += "; " + optionKey;
		let optionValue = options[optionKey];
		if (optionValue !== true) {
			updatedCookie += "=" + optionValue;
		}
	}
	document.cookie = updatedCookie;
}

function lm_deleteCookie(name) {
	lm_setCookie(name, "", {'max-age': -1});
}
</script>
{% endif %}
