/*
Elxis CMS - module Search
Copyright (c) 2006-2025 elxis.org
*/

function msearchPick() {
	if (!document.getElementById('elx_modsearch_eng')) { return; }
	var fmObj = document.getElementById('fmmodsearch');
	var selObj = document.getElementById('elx_modsearch_eng');
	var selidx = selObj.selectedIndex;
	var img = selObj.options[selidx].getAttribute('data-image');
	fmObj.setAttribute('action', selObj.options[selidx].getAttribute('data-act'));
	selObj.style.backgroundImage = "url('"+img+"')";
}

function msearchOnLoad() {
	if (document.getElementById('elx_modsearch_eng')) {
		document.getElementById('elx_modsearch_eng').addEventListener('change', function(){ msearchPick(); }, false);
	}
}

if (document.getElementById('elx_modsearch_eng')) {
	msearchPick();
} else {
	if (document.readyState != 'loading') {
		msearchPick();
	} else if (document.addEventListener) {
		document.addEventListener('DOMContentLoaded', function(){ msearchPick(); });
	} else {
		document.attachEvent('onreadystatechange', function() { if (document.readyState == 'complete') { msearchPick(); } });
	}
}
