// Makes an external function call. If this is in the standalone, it goes through a COM sink to the container. On the web, it uses the XmlHttpRequest object.
// It returns true if it is able to do a synchronous call, false if it has to asynchronously (it falls through to the old script trick with callbacks).
function run_external(ScriptId, Uri, NoEval)
{
	// If you got three or more arguments, the third one ought to be a boolean
	if (arguments.length >= 3)
	{
		if (typeof(arguments[2]) != typeof(true))
		{
			alert("NoEval argument to run_external is incorrect");
		}
		var x = 3;
		var args = "";
		while (arguments[x])
		{
			args = args + (x > 3 ? "&" : "") + arguments[x].toString();
			x++;
		}
		Uri = (args ? Uri + "?" + args : Uri);
	}
	// First test to see if this is the web client. If it is, we'll attempt to use the XmlHttpRequest object to fulfill the request
	try
	{
		var xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
			// JScript gives us Conditional compilation, we can cope with old IE versions.
			// and secUrity blocked creation of the objects.
			try 
			{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch(e)
			{
				try
				{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch(E) 
				{
					xmlhttp = false;
				}
			}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
		// False here tells it to block until the result comes back... they recommend against it, but I think we need it here
		xmlhttp.open("GET", Uri, false);
		xmlhttp.send(null);
		// If this is returning a hard value instead of Javascript code, don't try to interpret it
		if (NoEval == true)
		{
			return xmlhttp.responseText;
		}
		return eval(xmlhttp.responseText);
	}
	catch(f)
	{
		var head = document.getElementsByTagName('head').item(0);
		var child = document.getElementById(ScriptId);
		if (child)
		{
			child.parentNode.removeChild(child);
		}
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.defer = true;
		script.id = ScriptId;
		script.src = Uri;
		void(head.appendChild(script));
		return false;
	}
}
