// Name:        SilverlightPlugin.debug.js
// Assembly:    System.Web.Extensions
// Version:     3.6.0.0
// FileVersion: 3.6.20830.0
//!-----------------------------------------------------------------------
//! Copyright (C) Microsoft Corporation. All rights reserved.
//!-----------------------------------------------------------------------
//! SilverlightPlugin.js
//! Sys.UI.Silverlight.Plugin component
Type.registerNamespace('Sys.UI.Silverlight');

Sys.UI.Silverlight.InstallationMode = function Sys$UI$Silverlight$InstallationMode() {
    /// <summary locid="M:J#Sys.UI.Silverlight.InstallationMode.#ctor" />
    /// <field name="none" type="Number" integer="true" static="true" locid="F:J#Sys.UI.Silverlight.InstallationMode.none"></field>
    /// <field name="inline" type="Number" integer="true" static="true" locid="F:J#Sys.UI.Silverlight.InstallationMode.inline"></field>
    /// <field name="linked" type="Number" integer="true" static="true" locid="F:J#Sys.UI.Silverlight.InstallationMode.linked"></field>
    if (arguments.length !== 0) throw Error.parameterCount();
    throw Error.notImplemented();
}




Sys.UI.Silverlight.InstallationMode.prototype = {
    none: 0,
    inline: 1,
    linked: 2
}
Sys.UI.Silverlight.InstallationMode.registerEnum('Sys.UI.Silverlight.InstallationMode');
Sys.UI.Silverlight.Plugin = { };

// caches the result of calling sl.IsVersionSupported()
Sys.UI.Silverlight.Plugin._supportedVersionsCache = {};

Sys.UI.Silverlight.Plugin._followFWLink = function Sys$UI$Silverlight$Plugin$_followFWLink(fwLink) {
    // TODO: support HTTPS when there are fwlinks in place that work with it
    // detect https via: ((document.location.toString().toLowerCase().indexOf('https:') === 0) ? "https" : "http")
    window.top.location = "http://go.microsoft.com/fwlink/?LinkID=" + fwLink;
}

Sys.UI.Silverlight.Plugin._getFWLinks = function Sys$UI$Silverlight$Plugin$_getFWLinks(installationMode, forVersion, agent, agentVersion, ua) {
    // Determine if silverlight is supported...
    var supported =
        // IE 6 or greater supported but not on Mac or the 64 bit version
        (   (agent === Sys.Browser.InternetExplorer) &&
            (agentVersion >= 6) &&
            (ua.indexOf('Win64') === -1) &&
            (ua.indexOf('Mac OS X') === -1)) ||
        // FF 1.5 or greater supported
        ((agent === Sys.Browser.Firefox) && (agentVersion >= 1.5)) ||
        // Safari supported but not for Windows
        ((agent === Sys.Browser.Safari) && (ua.indexOf("Windows NT") === -1));

    var v = 0;
    try { v = parseFloat(forVersion); }
    catch (e) { }
    if (v >= 1.1) {
        return Sys.UI.Silverlight.Plugin._getFWLinksAlpha(supported, ua);
    }
    
    var isInline = (installationMode === Sys.UI.Silverlight.InstallationMode.inline);
    
    // defaults for unsupported 
    var fwLinks = { install: "92822", eula: "93481", privacy: "93483" };

    if (Sys.UI.Silverlight.Plugin._installed) {
        // upgrade
        fwLinks.image1 = isInline ? "104746" : "94377";
    }
    else {
        fwLinks.image1 = isInline ? "104747" : "92801";
    }
    fwLinks.image2 = "104745";
    
    if (supported) {
        if (ua.indexOf('Windows NT') !== -1) {
            fwLinks.install = isInline ? "92799" : "92800";
            fwLinks.eula = "92803";
            fwLinks.privacy = "92805";
        }
        else if (ua.indexOf('PPC Mac OS X') !== -1) {
            fwLinks.install = isInline ? "92807" : "92811";
            fwLinks.eula = "92815";
            fwLinks.privacy = "92816";
        }
        else if (ua.indexOf('Intel Mac OS X') !== -1) {
            fwLinks.install = isInline ? "92808" : "92812";
            fwLinks.eula = "92804";
            fwLinks.privacy = "92806";
        }
        // else -- may be a supported browser but on an unsupported platform
    }
    
    fwLinks.installHtml = isInline ?
        Sys.UI.Silverlight.PluginRes.inlineInstallHtml :
        Sys.UI.Silverlight.PluginRes.linkedInstallHtml;
    return fwLinks;
}

Sys.UI.Silverlight.Plugin._getFWLinksAlpha = function Sys$UI$Silverlight$Plugin$_getFWLinksAlpha(supported, ua) {
    var fwLinks = { install: "92821", image2: null, eula: null, privacy: null };
    fwLinks.image1 = Sys.UI.Silverlight.Plugin._installed ? "94378" : "92810";

    // 1.1 does not support Mac PPC
    supported = supported && (ua.indexOf("PPC Mac OS X") === -1);
   
    if (supported) {
        if (ua.indexOf("Windows NT") !== -1) {
            fwLinks.install = "92809";
        }
        else if (ua.indexOf("Mac OS X") !== -1) {
            fwLinks.install = "92813";
        }
    }
    
    fwLinks.installHtml = Sys.UI.Silverlight.PluginRes.linkedInstallHtml;
    return fwLinks;
}

Sys.UI.Silverlight.Plugin._getInstallPrompt = function Sys$UI$Silverlight$Plugin$_getInstallPrompt(installationMode, version, template) {
    var container = document.createElement("div");
    
    // when template is specified, apply certain attributes to the install prompt div
    if (template) {
        container.id = template.id;
        container.width = template.style.width;
        container.height = template.style.height;
        container.className = template.className;
        container.style.cssText = template.style.cssText;
    }
    
    var fwLinks = Sys.UI.Silverlight.Plugin._getFWLinks(installationMode,
        version,
        Sys.Browser.agent,
        Sys.Browser.version,
        navigator.userAgent);
        
    container.innerHTML = String.format(fwLinks.installHtml,
        fwLinks.install,
        fwLinks.image1,
        fwLinks.eula,
        fwLinks.privacy,
        fwLinks.image2);
        
    return container;
}

Sys.UI.Silverlight.Plugin.supportsVersion = function Sys$UI$Silverlight$Plugin$supportsVersion(version) {
    /// <summary locid="M:J#Sys.UI.Silverlight.Plugin.supportsVersion" />
    /// <param name="version" type="String"></param>
    /// <returns type="Boolean"></returns>
    var e = Function._validateParams(arguments, [
        {name: "version", type: String}
    ]);
    if (e) throw e;
    
    var supported = Sys.UI.Silverlight.Plugin._supportedVersionsCache[version];
    if (typeof(supported) === "undefined") {
        // must dynamically create a plugin and query it
        var plugin = Sys.UI.Silverlight.Plugin._createInstance();
        
        if (plugin && typeof(plugin.IsVersionSupported) !== "undefined") {
            // don't compare with "function", it shows up "unknown" in IE since not a javascript function.
            Sys.UI.Silverlight.Plugin._installed = true;
            supported = plugin.IsVersionSupported(version);
        }
        else {
            Sys.UI.Silverlight.Plugin._installed = false;
            supported = false;
        }
        
        if (plugin && Sys.Browser.agent !== Sys.Browser.InternetExplorer) {
            // remove temporary instance from dom
            plugin.parentNode.removeChild(plugin);
        }
    }
    
    Sys.UI.Silverlight.Plugin._supportedVersionsCache[version] = supported;
    return supported;
}

Sys.UI.Silverlight.Plugin._createInstance = function Sys$UI$Silverlight$Plugin$_createInstance() {
    // this function is overwritten/mocked for unit testing
    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
        try {
            return new ActiveXObject('AgControl.AgControl');
        }
        catch(ex) {
        }
    }
    else if (navigator.plugins["Silverlight Plug-In"]) {
        var e = document.createElement('div');
        e.style.width = "0px";
        e.style.height = "0px";
        
        if (Sys.Browser.agent === Sys.Browser.Safari) {
            e.innerHTML = '<embed type="application/x-silverlight"></embed>';
        }
        else {
            // data:"data," attribute is a workaround for an issue in FF that causes it to make
            // a webrequest to the server when instantiating a new plugin
            e.innerHTML = '<object type="application/x-silverlight" data="data:,"></object>';                    
        }
        // note: this line will cause "Operation Aborted" in IE, but for IE we use ActiveXObject
        document.body.appendChild(e);
        return e.childNodes[0];
    }
    return null;
}

Sys.UI.Silverlight.Plugin.create = function Sys$UI$Silverlight$Plugin$create(parentId, version, installationMode, html) {
    /// <summary locid="M:J#Sys.UI.Silverlight.Plugin.create" />
    /// <param name="parentId" type="String"></param>
    /// <param name="version" type="String"></param>
    /// <param name="installationMode" type="Sys.UI.Silverlight.InstallationMode"></param>
    /// <param name="html" type="String"></param>
    var e = Function._validateParams(arguments, [
        {name: "parentId", type: String},
        {name: "version", type: String},
        {name: "installationMode", type: Sys.UI.Silverlight.InstallationMode},
        {name: "html", type: String}
    ]);
    if (e) throw e;
    var placeholder = document.getElementById(parentId);
    if (!placeholder) {
        throw Error.invalidOperation(String.format(Sys.UI.Silverlight.PluginRes.placeholderNotFound, parentId));
    }
    
    // null or empty version means dev does not care what version is installed or if it is installed
    if (!version || Sys.UI.Silverlight.Plugin.supportsVersion(version)) {
        placeholder.innerHTML = html;
    }
    else if (installationMode !== Sys.UI.Silverlight.InstallationMode.none) {
        var container = document.createElement("div");
        container.innerHTML = html;
        var nodes = container.childNodes;
        var template = null;
        for (var i=0, l=nodes.length; i < l; i++) {
            var node = nodes[i];
            if (node.tagName && 
                ((node.tagName.toUpperCase() === "OBJECT") || (node.tagName.toUpperCase() === "EMBED"))) {
                template = node;
                break;
            }
        }
        placeholder.innerHTML = "";
        placeholder.appendChild(Sys.UI.Silverlight.Plugin._getInstallPrompt(installationMode, version, template));
    }
}

Type.registerNamespace('Sys.UI.Silverlight');
Sys.UI.Silverlight.PluginRes={
"placeholderNotFound":"A placeholder element with id \"{0}\" could not be found.",
"inlineInstallHtml":"\u003ctable border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:206px; font-size: 55%; font-family: Verdana;  color: #5E5D5D;\"\u003e\u003ctr\u003e\u003ctd\u003e\u003cimg style=\"display: block; cursor: pointer; border= 0;\" title=\"Get Microsoft Silverlight\" alt=\"Get Microsoft Silverlight\" onclick=\"javascript:Sys.UI.Silverlight.Plugin._followFWLink({0})\" src=\"http://go.microsoft.com/fwlink/?LinkID={1}&amp;clcid=0x409\" /\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd style=\"width: 206px; margin: 0px; background: #FFFFFF; text-align: left; border-left-style: solid; border-right-style: solid; border-color: #c7c7bd;padding-left: 6px; padding-right: 6px; padding-top: 3px; padding-bottom: 10px; border-width: 2px; \"\u003eBy clicking \u003cb\u003e\"Get Microsoft Silverlight\"\u003c/b\u003e you accept the\u003cbr /\u003e\u003ca title=\"Silverlight License Agreement\" href=\"http://go.microsoft.com/fwlink/?LinkID={2}\" target=\"_blank\" style=\"text-decoration: underline; color: #0000CC\"\u003e\u003cb\u003eSilverlight license agreement\u003c/b\u003e\u003c/a\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd style=\"width: 206px; margin: 0px; background: #FFFFFF; text-align: left; border-left-style: solid; border-right-style: solid; padding-left: 6px; padding-right: 6px; border-color: #c7c7bd;padding-top: 0px; padding-bottom: 2px; border-width: 2px; \"\u003eSilverlight updates automatically, \u003ca title=\"Silverlight Privacy Statement\" href=\"http://go.microsoft.com/fwlink/?LinkID={3}\" target=\"_blank\" style=\"text-decoration: underline; color: #0000CC\"\u003e\u003cb\u003elearn more\u003c/b\u003e\u003c/a\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cimg alt=\"\" src=\"http://go.microsoft.com/fwlink/?LinkID={4}\" style=\"display:block\" /\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e",
"linkedInstallHtml":"\u003cdiv style=\"display:block; width: 205px; height: 67px;\"\u003e\u003cimg onclick=\"javascript:Sys.UI.Silverlight.Plugin._followFWLink({0})\" style=\"border:0; cursor:pointer; display:block\" src=\"http://go.microsoft.com/fwlink/?LinkID={1}&amp;clcid=0x409\" title=\"Get Microsoft Silverlight\" alt=\"Get Microsoft Silverlight\"/\u003e\u003c/div\u003e"
};

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();