function onSilverlightError(sender, args) {
	var appSource = "";
	if (sender != null && sender != 0) {
		appSource = sender.getHost().Source;
	} 
	var errorType = args.ErrorType;
	var iErrorCode = args.ErrorCode;
	
	var errMsg = "Unhandled Error in Silverlight 2 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);
}

function embedSL(src){
	document.write('<object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">');
	document.write('<param name="source" value="'+src+'"');
	document.write('<param name="onerror" value="onSilverlightError" />');
	document.write('<param name="background" value="black" />');
	document.write('<br/><br/>');
	document.write('<div style="color:#FFFFFF; width:350px;margin-left:300px;">');
	document.write('You must install <a href="http://go.microsoft.com/fwlink/?LinkID=124807" target="_blank" style="color:#BBBBBB;">Microsoft Silverlight 2</a> in order to view International Photography Contest entries. (Not available for Power PC Macs.)<br/><br/>');
	document.write('<a href="http://go.microsoft.com/fwlink/?LinkID=124807" target="_blank" style="color:#BBBBBB;">Download Microsoft Silverlight 2</a><br/><br/>');
	document.write('<a href="http://go.microsoft.com/fwlink/?LinkID=124807" target="_blank" style="text-decoration: none;">');
	document.write('<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>');
	document.write('</a><br/><br/><br/>');
	document.write('<b>More International Photography Contest Features</b><br/><br/>');
	document.write('<a href="http://ngm.nationalgeographic.com/photo-contest/photo-contest" style="color:#BBBBBB;">&#8226; Learn more about the <b>International Photography Contest</b>.</a><br/><br/>');
	document.write('<a href="http://ngm.nationalgeographic.com/photo-contest/places-puzzles" style="color:#BBBBBB;">&#8226; Try your hand at <b>jigsaw puzzles</b> created from contest entries.</a><br/><br/>');
	document.write('<a href="http://ngm.nationalgeographic.com/photo-contest/wallpaper" style="color:#BBBBBB;">&#8226; Decorate your desktop with <b>wallpaper</b> from contest entries.</a></div>');
	document.write('</object>');
}
