/* IE6 doesn't allow transparent table borders so we use the "chroma" filter to achieve
the same effect.  Unfortunately, IE7 rendering corrupts with this filter so we need
to tell it to use the transparent border. Thus we detect browser version and use it
below to swap some styles out for IE7 */
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie7 = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.") != -1));

// a cache of the icon styles that are available...
var styleCouncil = new Array();

function getIconStyle(styleName)
{
    var retStyle = styleCouncil[styleName];

    if (retStyle == null)
    {
        retStyle = new Object();
        retStyle.style = new Object();
        retStyle.styleH = new Object();
        retStyle.styleS = new Object();

        // Parse the stylesheet to extract the styles we want...
        var ssCount = document.styleSheets.length;
        for (sheetNo = 0; sheetNo < ssCount; sheetNo = sheetNo + 1)
        {
            var ssLen = document.styleSheets[sheetNo].rules.length;
            for (i = 0; i < ssLen; i = i + 1)
            {
                // If we find a style we want, cache on the icon attributes that
                //  contain the styles we are interested in...
                if (document.styleSheets[sheetNo].rules[i].selectorText == '.' + styleName)
                {
                    retStyle.style.backgroundColor = document.styleSheets[sheetNo].rules[i].style.backgroundColor;
                    retStyle.style.borderColor = document.styleSheets[sheetNo].rules[i].style.borderColor;
                    retStyle.style.color = document.styleSheets[sheetNo].rules[i].style.color;
                    if (is_ie7)
                        document.styleSheets[sheetNo].rules[i].style.filter = '';
                }
                if (document.styleSheets[sheetNo].rules[i].selectorText == '.' + styleName + 'H')
                {
                    retStyle.styleH.backgroundColor = document.styleSheets[sheetNo].rules[i].style.backgroundColor;
                    retStyle.styleH.borderColor = document.styleSheets[sheetNo].rules[i].style.borderColor;
                    retStyle.styleH.color = document.styleSheets[sheetNo].rules[i].style.color;
                }
                if (document.styleSheets[sheetNo].rules[i].selectorText == '.' + styleName + 'S')
                {
                    retStyle.styleS.backgroundColor = document.styleSheets[sheetNo].rules[i].style.backgroundColor;
                    retStyle.styleS.borderColor = document.styleSheets[sheetNo].rules[i].style.borderColor;
                    retStyle.styleS.color = document.styleSheets[sheetNo].rules[i].style.color;
                }
            }
        }

        styleCouncil[styleName] = retStyle;
    }

    return retStyle;
}

function icoDis(obId)
{
    var ob = document.getElementById(obId);

    // If we can't find the icon object then give up...
    if (ob == null)
        return;

    // Hack for IE 6 to work with transparent borders...
    if (is_ie7)
    {
        ob.style.borderColor = "transparent";
    }
}

function icoHkUp(obId)
{
    var ob = document.getElementById(obId);
    // Locate the child text object...
    var kidId = obId.substring(0, obId.length - 3);
    var kid = document.getElementById(kidId);

    // If we can't find the icon object or it's child, then give up...
    if (ob == null || kid == null)
        return;

    // Obtain the name of the base css name...
    var baseStyle = ob.className;
    // If it doesn't have one set then assume "ico2"...
    if (baseStyle == null || baseStyle == "")
        baseStyle = "ico2";

    // Set the appearance...
    ob.className = baseStyle;
    ob.style.height = "100%";
    ob.style.cursor = "pointer";
    kid.style.textDecoration = "none";

    // Get the style and cache the values on the object...
    var iconStyle = getIconStyle(baseStyle);
    ob.epiIcoBgCol = iconStyle.style.backgroundColor;
    ob.epiIcoBdCol = iconStyle.style.borderColor;
    ob.epiIcoFgCol = iconStyle.style.color;
    ob.epiIcohBgCol = iconStyle.styleH.backgroundColor;
    ob.epiIcohBdCol = iconStyle.styleH.borderColor;
    ob.epiIcohFgCol = iconStyle.styleH.color;
    ob.epiIcosBgCol = iconStyle.styleS.backgroundColor;
    ob.epiIcosBdCol = iconStyle.styleS.borderColor;
    ob.epiIcosFgCol = iconStyle.styleS.color;

    // Hack for IE 6 to work with transparent borders...
    if (is_ie7)
    {
        ob.style.borderColor = "transparent";
        kid.style.borderColor = "transparent";
        ob.epiIcoBdCol = "transparent";
    }

    // Set the interaction...
    ob.onmouseover = function()
    {
        ob.style.backgroundColor = ob.epiIcohBgCol;
        ob.style.borderColor = ob.epiIcohBdCol;
        kid.style.color = ob.epiIcohFgCol;
    };
    ob.onmouseout = function()
    {
        ob.style.backgroundColor = ob.epiIcoBgCol;
        ob.style.borderColor = ob.epiIcoBdCol;
        kid.style.color = ob.epiIcoFgCol;
    };
    ob.onmousedown = function()
    {
        ob.style.backgroundColor = ob.epiIcosBgCol;
        ob.style.borderColor = ob.epiIcosBdCol;
        kid.style.color = ob.epiIcosFgCol;
    };
    ob.onmouseup = function()
    {
        ob.style.backgroundColor = ob.epiIcohBgCol;
        ob.style.borderColor = ob.epiIcohBdCol;
        kid.style.color = ob.epiIcohFgCol;
    };
    // Hook the table click event up to the child control...
    ob.onclick = function() { kid.click(); };
}
