﻿function initComboBox(elID) {
    if ((screen.width >= 800) && (screen.height >= 600)) {
        if (elID == 'all') {
            var cbList = document.getElementsByTagName('select');
            for (var y = 0; y < cbList.length; y++) {
                elID[y] = cbList[y].id;
            };
        };
        if (cbList.length == 0) {
            return false;
        }
        else {
            for (var i = 0; i < elID.length; i++) {
                var el = $(elID[i]);
                var elWidth = el.clientWidth;
                var elUL = document.createElement('ul');
                var elContainer = document.createElement('div');
                elContainer.setAttribute('id', elID[i]);
                var selected = document.createElement('div');
                elContainer.appendChild(selected);
                selected.className = 'selected';
                elContainer.className = 'selectBox';
                for (var x = 0; x < el.options.length; x++) {
                    var elLI = document.createElement('li');
                    var aLink = document.createElement('a');
                    aLink.setAttribute('href', el.options[x].value);
                    aLink.setAttribute('rel', 'nofollow');
                    if (x == 0) {
                        selected.innerHTML = el.options[x].text;
                    };
                    if (el.options[x].selected) {
                        selected.innerHTML = el.options[x].text;
                    };
                    aLink.innerHTML = el.options[x].text;
                    elLI.appendChild(aLink);
                    elUL.appendChild(elLI);
                };
                /*
                    if (elUL.childNodes.length > 10) {
                        elUL.style.height = '245px';
                        elUL.style.overflow = 'scroll';
                    };
                */
                elUL.className = 'select';
                elContainer.appendChild(elUL);
                elUL.style.width = elWidth + 'px';
                if (elWidth < 100) {
                    elUL.style.width = (elWidth + 20) + 'px';
                };
                if (navigator.appName != "Microsoft Internet Explorer") {
                    el.parentNode.replaceChild(elContainer, el);

                    var elParent = document.getElementById(elID[i]).parentNode.id;

                    $(elParent).style.visibility = "visible";
                }
                else {
                    el.replaceNode(elContainer);

                    var elParent = document.getElementById(elID[i]).parentNode.id;

                    $(elParent).style.visibility = "visible";
                };
            };
        };
    };
};