﻿Silverlight.InstallAndCreateSilverlight = function(version, SilverlightDiv, installExperienceHTML, installPromptDivID, createSilverlightDelegate,xamlFile)
{
    var RetryTimeout=2000;
    /*if(Silverlight.isInstalled('2.0')){ //若使用2.0測試版
        document.getElementById("installText").innerHTML = "您好,目前此系統僅支援Microsoft SilverLight 1.0 ,"+
        "若您已經安裝Microsoft SilverLight 2.0 beta 測試版,<font color='red'><b>請先移除</b></font>後重新安裝Microsoft SilverLight 1.0 ,下載安裝網址如下:<br/>"+
        "<a href='http://www.microsoft.com/silverlight/resources/installationFiles.aspx'>Microsoft SilverLight 1.0下載網址</a>";
        if ( installExperienceHTML && SilverlightDiv )
        {
            //SilverlightDiv.innerHTML=installExperienceHTML;
            document.body.innerHTML;
        }
        if(confirmPanel!=null){
            confirmPanel.open();
            confirmPanel.setBkImage("images/installBg.jpg");
            confirmPanel.setShadowWidth(980);
            confirmPanel.setContentDisplay(false);
            confirmPanel.setShadowBorder('');
        }
        if (installPromptDivID)
        {
            var installPromptDiv = document.getElementById(installPromptDivID);
            
            if ( installPromptDiv ){
                installPromptDiv.innerHTML = Silverlight.createObject(null, null, null, {version: version, inplaceInstallPrompt:true},{}, null);
            }
        }
        
        TimeoutDelegate = function()
        {
            Silverlight.InstallAndCreateSilverlight(version, null, null, null, createSilverlightDelegate,xamlFile);
        }
        
        setTimeout(TimeoutDelegate, RetryTimeout);
    } 
    else */if ( Silverlight.isInstalled(version) )
    {
        if(confirmPanel!=null){
            
            confirmPanel.close();
            confirmPanel.setBkImage(null);
            confirmPanel.setShadowBorder('1px solid #000000');            
        }
        createSilverlightDelegate(xamlFile);
    }
    else
    {
        document.getElementById("installText").innerHTML = "您好，您目前瀏覽的網頁需要安裝Microsoft SilverLight 軟體，請點選下面圖示進行安裝！";
        if ( installExperienceHTML && SilverlightDiv )
        {
            //SilverlightDiv.innerHTML=installExperienceHTML;
            document.body.innerHTML;
        }
        if(confirmPanel!=null){
            confirmPanel.open();
            confirmPanel.setBkImage("images/installBg.jpg");
            confirmPanel.setShadowWidth(980);
            confirmPanel.setContentDisplay(false);
            confirmPanel.setShadowBorder('');
        }
        if (installPromptDivID)
        {
            var installPromptDiv = document.getElementById(installPromptDivID);
            
            if ( installPromptDiv ){
                installPromptDiv.innerHTML = Silverlight.createObject(null, null, null, {version: version, inplaceInstallPrompt:true},{}, null);
            }
        }
        
        TimeoutDelegate = function()
        {
            Silverlight.InstallAndCreateSilverlight(version, null, null, null, createSilverlightDelegate,xamlFile);
        }
        
        setTimeout(TimeoutDelegate, RetryTimeout);
    }
}

function createSilverlight(xaml)
{
	    
	var scene = new DP_SilverLight.Page();

	Silverlight.createObjectEx({
		source: xaml,
		parentElement: document.getElementById("SilverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: "100%",
			height: "100%",
			isWindowless: "true",
			version: "1.0"
		},
		events: {
			onLoad: Silverlight.createDelegate(scene, scene.handleLoad)
		}
	});
	
}


if (!window.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
		return method.apply(instance, arguments);
	}
}
