﻿/* Hide an element and fill the space it took up */
function hide(elementId) {
    changeClass(elementId, 'off');
}

function show(elementId) {
    changeClass(elementId, 'on');
}

/*************************
* UTILITY FUNCTIONS    	 *
**************************/
/*************************
* changeClass          	 *
***************************************************
* Switches the className value of an element      *
* Parameters:          							  *
*   - elementId: The id of the element to switch  *
*   - className: The class to set the element to  *
* Results:             							  *
*   - The element will be set to the given class  *
***************************************************/
function changeClass(elementId, className) {
    //alert('Setting ' + elementId + ' to ' + className);
    // Get a reference to the element
    element = document.getElementById(elementId);
    // Make sure the element was on the page
    if (element) {
        // Update the element's className property
        element.className = className;
    } else {
        //  alert(elementId + ' not found.');
    }
}

// Please leave this comment in place
// Created by: Randy Drisgill (The Mossman)
// August 17, 2007
//
// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue
//
// To use in masterpage use this syntax in the <head>:
//  	<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
//   	<script type="text/javascript" src="/_catalogs/masterpage/custom_activex_override.js"></script>
function ProcessDefaultOnLoad(onLoadFunctionNames) {
    //** Uncomment this to see when this runs
    //alert('Fixing the Issue');

    ProcessPNGImages();
    UpdateAccessibilityUI();

    //** We comment out the offending ootb function
    //** and leave the rest of the functions as they were
    //ProcessImn();
    for (var i = 0; i < onLoadFunctionNames.length; i++) {
        var expr = "if(typeof(" + onLoadFunctionNames[i] + ")=='function'){" + onLoadFunctionNames[i] + "();}";
        eval(expr);
    }
    if (typeof (_spUseDefaultFocus) != "undefined")
        DefaultFocus();
}

function isSilverlightInstalled(version) {
    if (version == undefined)
        version = null;

    var isVersionSupported = false;
    var container = null;

    try {
        var control = null;
        var tryNS = false;

        if (window.ActiveXObject) {
            try {
                control = new ActiveXObject('AgControl.AgControl');
                if (version === null) {
                    isVersionSupported = true;
                } else if (control.IsVersionSupported(version)) {
                    isVersionSupported = true;
                }
                control = null;
            } catch (e) {
                tryNS = true;
            }
        } else {
            tryNS = true;
        }

        if (tryNS) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (version === null) {
                    isVersionSupported = true;
                } else {
                    var actualVer = plugin.description;
                    if (actualVer === "1.0.30226.2")
                        actualVer = "2.0.30226.2";
                  
                    var actualVerArray = actualVer.split(".");
                    while (actualVerArray.length > 3) {
                        actualVerArray.pop();
                    }
                    
                    while (actualVerArray.length < 4) {
                        actualVerArray.push(0);
                    }
                    
                    var reqVerArray = version.split(".");
                    while (reqVerArray.length > 4) {
                        reqVerArray.pop();
                    }

                    var requiredVersionPart;
                    var actualVersionPart;
                    var index = 0;

                    do {
                        requiredVersionPart = parseInt(reqVerArray[index]);
                        actualVersionPart = parseInt(actualVerArray[index]);
                        index++;
                    } while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);

                    if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
                        isVersionSupported = true;
                    }
                }
            }
        }
    } catch (e) {
        isVersionSupported = false;
    }

    return isVersionSupported;
}