﻿//SES.SilverlightManager.js - v1.0
//Requires Microsoft's Silverlight.js (v2.0.30511.0) (http://msdn.microsoft.com/en-us/library/cc838126(v=vs.95).aspx)
//Requires Microsoft's Silverlight.supportedUserAgent.js (v4.0.50401.0) (http://archive.msdn.microsoft.com/SLsupportedUA)

function GetSilverlightVersionText() {

    document.write("QMRPlus requires <a href='http://www.microsoft.com/silverlight/' target='_blank'>Microsoft Silverlight</a> v4.0.60310.0.<br><br>");

    if (HasSilverlightInstalled()) {
        if (HasCorrectSilverlightVersion()) {
            document.write("You have the latest version installed.");
        } else {
            if (Silverlight.isBrowserRestartRequired) {
                //This doesn't actually work. On upgrade isBrowserRestartRequired is always false.
                document.write("Silverlight was successfully installed. Please now close your browser, open it again, and re-navigate to this page.");
            } else {
                document.write("You have v" + GetSilverlightVersion() + " installed<br>");
                document.write("<a href=\"#\" onClick=\"Silverlight.getSilverlight('')\">Click here</a> to install the latest version (6MB).<br>");
                document.write("After the install you will need to close your browser, open it again and re-navigate to this page.");
            }
        }
    } else {
        if (Silverlight.supportedUserAgent("4.0", "")) {
            document.write("You currently don't have it installed.<br>");
            document.write("<a href=\"#\" onClick=\"Silverlight.getSilverlight('')\">Click here</a> to install the latest version (6MB).");
        } else {
            document.write("Your current browser / operating system combination does not support the required version of silverlight.<br>");
            document.write("Go to <a href='http://www.microsoft.com/getsilverlight/get-started/install/default.aspx' target='_blank'>http://www.microsoft.com/getsilverlight/get-started/install/default.aspx</a> and click \'System Requirements\' to see a list of compatible browsers");
        }
    }
}

function GetSilverlightVersion() {

    //Version numbers from http://msdn.microsoft.com/en-us/library/cc265156(v=vs.95).aspx

    if (Silverlight.isInstalled("4.0.60310.0")) {
        return "4.0.60310.0";
    } else if (Silverlight.isInstalled("3.0.50106")) {
        return "3.0.50106";
    } else if (Silverlight.isInstalled("2.0.40115")) {
        return "2.0.40115";
    } else if (Silverlight.isInstalled("1.0.30715")) {
        return "1.0.30715";
    } else {
        return "-1";
    }
}

function HasCorrectSilverlightVersion() {

    return (GetSilverlightVersion() == "4.0.60310.0");

}

function HasSilverlightInstalled() {
    
    return (GetSilverlightVersion() != "-1");
}
