﻿// JScript source code
function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

//contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight(controlName, controlHostName, xamlSource, controlWidth, controlHeight, controlBackground, SilverlightVersion, myParams)
{
	Silverlight.createObjectEx({
		source: xamlSource,
		parentElement: document.getElementById(controlHostName),
		id: controlName,
		properties: {
			width: controlWidth,
			height: controlHeight,
			background: controlBackground,
			enableHtmlAccess: "true"
		},
		events:
		{
		    OnError: onSilverlightError
		},
		initParams: myParams
	});
}

function sayBoo()
{
    alert("boo");
}

function sayBooHoo() {
    alert("BooHoo");
}