﻿// common js file
    
    function hideSelBoxes() {
        if (document.getElementsByTagName) {
            var aSels = document.getElementsByTagName("select");
            for (var i=0;i<aSels.length;i++) {
                aSels[i].style.visibility = "hidden"; // hide - don't remove...
            }
        }
    }
    
    function showSelBoxes() {
        if (document.getElementsByTagName) {
            var aSels = document.getElementsByTagName("select");
            for (var i=0;i<aSels.length;i++) {
                aSels[i].style.visibility = "visible";
            }
        }
    }
    
    function popUp(sWinName, sURL) {
        var oWin = window.open(sURL, sWinName, "width=780,height=540,resizable=1,scrollbars=1");
        if (oWin) oWin.focus();
    }
    
     function expand(sTargetID, sLinkID, sLabelID, sLabelActive, sLabelAlternate) {
        if (document.getElementById(sTargetID).style.display=='block') { 
            document.getElementById(sTargetID).style.display='none'; 
            document.getElementById(sLinkID).className = "expand-sublinks";
            document.getElementById(sLabelID).innerHTML = sLabelActive;
        } else {
            document.getElementById(sTargetID).style.display='block';
            document.getElementById(sLinkID).className = "collapse-sublinks";
            document.getElementById(sLabelID).innerHTML = sLabelAlternate;
        }
    }

    function openMediaFile(sMediaFileURL) {
        var oWin = window.open(sMediaFileURL);
        if (oWin) oWin.focus();
    }

    // this function is need to work around a bug in IE related to element attributes
    function hasClass(obj) {
        var result = false;
        if (obj.getAttributeNode("class") != null) {
            result = obj.getAttributeNode("class").value;
        }
        return result;
    }
    
    // is the row make up of only th cells
    function isHeaderRow(objRow) {
        var cellCount = objRow.getElementsByTagName("td").length;
        return (cellCount == 0);
    }

    //the striping function
    function stripeTables() {
        var containerClass = arguments[0] ? arguments[0] : "alt";
        var evenColor = arguments[1] ? arguments[1] : "alt";
        var rowHeaderClass = arguments[2] ? arguments[2] : "";
        var even = false;
        
        var containerDivs = document.getElementsByTagName("div");
        
        if (containerDivs.length) {
            for (var currDiv = 0; currDiv < containerDivs.length; currDiv++) {
            
                if (hasClass(containerDivs[currDiv]) == containerClass) {
                    
                    var tableArr = containerDivs[currDiv].getElementsByTagName("table");
                    
                    if (tableArr.length) {
                        if (!hasClass(tableArr[0])) {
                        
                            var trs = tableArr[0].getElementsByTagName("tr");
                            if (trs.length) {
                                var nStartRow = 0;
                                if (isHeaderRow(trs[0])) { 
                                    // format the header row and start the alternate rows on the 3rd row
                                    trs[0].className = rowHeaderClass;
                                    ++nStartRow; 
                                }
                                
                                even = false;
                                for (var currRow = nStartRow; currRow < trs.length; currRow++) {
                                
                                    if (! hasClass(trs[currRow]) && ! trs[currRow].style.backgroundColor) {
                                        if(even) {     trs[currRow].className =  evenColor; }
                                    }
                                    
                                    even = !even;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    function applyStripeToTables() {
        if(document.getElementById) {
            stripeTables('stripedTable', 'altrow', 'thead');
        }
    }
 
   bCommonJSLoaded = true;
