﻿function createSilverlight(xapFile)
{
  createSilverlight("silverlightControlHost", "SilverlightControl", xapFile);
}

function createSilverlight(divId, controlId, xapFile)
{
  createSilverlight(divId, controlId, xapFile, "#FFFFFF");
}

function createSilverlight(divId, controlId, xapFile, backgroundColor) {
  Silverlight.createObjectEx(
	{
	  source: xapFile,
	  parentElement: document.getElementById(divId),
	  id: controlId,
	  properties: {
	    background: backgroundColor,
	    width: "100%",
	    height: "100%",
	    version: "2.0",
	    enableHtmlAccess: "true"
	  },
	  events: {}
	});

  // Give the keyboard focus to the Silverlight control by default
  document.body.onload = function() {
    var silverlightControl = document.getElementById(controlId);
    if (silverlightControl)
      silverlightControl.focus();
  }
}


function createSilverlight(divId, controlId, xapFile, backgroundColor, args) {
  Silverlight.createObjectEx(
	{
	  source: xapFile,
	  parentElement: document.getElementById(divId),
	  id: controlId,
	  properties: {
	    background: backgroundColor,
	    width: "100%",
	    height: "100%",
	    version: "2.0",
	    enableHtmlAccess: "true"
	  },
	  events: {
	    onLoad: function pluginLoaded(sender) {
        try {
  	      var silverlightControl = document.getElementById(controlId);
  	      var app = silverlightControl.Content.App;
  	      if (app)
  	        app.SetInitialization(args);
        }
        catch(err) {
        }
	    }
	  }
	});

  // Give the keyboard focus to the Silverlight control by default
  document.body.onload = function() {
    var silverlightControl = document.getElementById(controlId);
    if (silverlightControl)
      silverlightControl.focus();
  }
}