﻿(function()
{
    function isIE()
    {
        var isIE = false;
        
        if (navigator.appName.toLowerCase().indexOf('internet explorer') >= 0)
        {
            isIE = true;
        }
        
        return isIE;
    }
    
    function initalizeSelectElement(
        selectElement)
    {
        if ((selectElement) &&
            (selectElement.options) &&
            (selectElement.options.length > 0))
        {
            for (var index = 0; index < selectElement.options.length; index++)
            {
                if (selectElement.options[index].disabled)
                {
                    var option = selectElement.options[index];
            
                    var optGroup = document.createElement(
                        'optgroup');
                    
                    optGroup.label = option.innerHTML.replace(
                        '&amp;',
                        '&');
                    
                    optGroup._option = option;
                    
                    optGroup.style.color = 'Gray';
                      
                    var parent = option.parentNode;
                    
                    if (parent)
                    {
                        parent.replaceChild(
                            optGroup,
                            option);
                    }
                }
            }
        }
    }
    
    window.initializeSelectElements = function()
    {
        if (isIE())
        {
            var selects = document.getElementsByTagName(
                'select');
            
            if ((selects) &&
                (selects.length > 0))
            {
                for (var index = 0; index < selects.length; index++)
                {
                    initalizeSelectElement(
                        selects[index]);
                }
            }
        }
    };
})();