//v2.0.40818.0
if(!window.Silverlight)window.Silverlight={};Silverlight._silverlightCount=0;Silverlight.__onSilverlightInstalledCalled=false;Silverlight.fwlinkRoot="http://go2.microsoft.com/fwlink/?LinkID=";Silverlight.__installationEventFired=false;Silverlight.onGetSilverlight=null;Silverlight.onSilverlightInstalled=function(){window.location.reload(false)};Silverlight.isInstalled=function(b){if(b==undefined)b=null;var a=false,m=null;try{var i=null,j=false;if(window.ActiveXObject)try{i=new ActiveXObject("AgControl.AgControl");if(b===null)a=true;else if(i.IsVersionSupported(b))a=true;i=null}catch(l){j=true}else j=true;if(j){var k=navigator.plugins["Silverlight Plug-In"];if(k)if(b===null)a=true;else{var h=k.description;if(h==="1.0.30226.2")h="2.0.30226.2";var c=h.split(".");while(c.length>3)c.pop();while(c.length<4)c.push(0);var e=b.split(".");while(e.length>4)e.pop();var d,g,f=0;do{d=parseInt(e[f]);g=parseInt(c[f]);f++}while(f<e.length&&d===g);if(d<=g&&!isNaN(d))a=true}}}catch(l){a=false}return a};Silverlight.WaitForInstallCompletion=function(){if(!Silverlight.isBrowserRestartRequired&&Silverlight.onSilverlightInstalled){try{navigator.plugins.refresh()}catch(a){}if(Silverlight.isInstalled(null)&&!Silverlight.__onSilverlightInstalledCalled){Silverlight.onSilverlightInstalled();Silverlight.__onSilverlightInstalledCalled=true}else setTimeout(Silverlight.WaitForInstallCompletion,3e3)}};Silverlight.__startup=function(){navigator.plugins.refresh();Silverlight.isBrowserRestartRequired=Silverlight.isInstalled(null);if(!Silverlight.isBrowserRestartRequired){Silverlight.WaitForInstallCompletion();if(!Silverlight.__installationEventFired){Silverlight.onInstallRequired();Silverlight.__installationEventFired=true}}else if(window.navigator.mimeTypes){var b=navigator.mimeTypes["application/x-silverlight-2"],c=navigator.mimeTypes["application/x-silverlight-2-b2"],d=navigator.mimeTypes["application/x-silverlight-2-b1"],a=d;if(c)a=c;if(!b&&(d||c)){if(!Silverlight.__installationEventFired){Silverlight.onUpgradeRequired();Silverlight.__installationEventFired=true}}else if(b&&a)if(b.enabledPlugin&&a.enabledPlugin)if(b.enabledPlugin.description!=a.enabledPlugin.description)if(!Silverlight.__installationEventFired){Silverlight.onRestartRequired();Silverlight.__installationEventFired=true}}if(!Silverlight.disableAutoStartup)if(window.removeEventListener)window.removeEventListener("load",Silverlight.__startup,false);else window.detachEvent("onload",Silverlight.__startup)};if(!Silverlight.disableAutoStartup)if(window.addEventListener)window.addEventListener("load",Silverlight.__startup,false);else window.attachEvent("onload",Silverlight.__startup);Silverlight.createObject=function(m,f,e,k,l,h,j){var d={},a=k,c=l;d.version=a.version;a.source=m;d.alt=a.alt;if(h)a.initParams=h;if(a.isWindowless&&!a.windowless)a.windowless=a.isWindowless;if(a.framerate&&!a.maxFramerate)a.maxFramerate=a.framerate;if(e&&!a.id)a.id=e;delete a.ignoreBrowserVer;delete a.inplaceInstallPrompt;delete a.version;delete a.isWindowless;delete a.framerate;delete a.data;delete a.src;delete a.alt;if(Silverlight.isInstalled(d.version)){for(var b in c)if(c[b]){if(b=="onLoad"&&typeof c[b]=="function"&&c[b].length!=1){var i=c[b];c[b]=function(a){return i(document.getElementById(e),j,a)}}var g=Silverlight.__getHandlerName(c[b]);if(g!=null){a[b]=g;c[b]=null}else throw"typeof events."+b+" must be 'function' or 'string'";}slPluginHTML=Silverlight.buildHTML(a)}else slPluginHTML=Silverlight.buildPromptHTML(d);if(f)f.innerHTML=slPluginHTML;else return slPluginHTML};Silverlight.buildHTML=function(a){var b=[];b.push('<object type="application/x-silverlight" data="data:application/x-silverlight,"');if(a.id!=null)b.push(' id="'+Silverlight.HtmlAttributeEncode(a.id)+'"');if(a.width!=null)b.push(' width="'+a.width+'"');if(a.height!=null)b.push(' height="'+a.height+'"');b.push(" >");delete a.id;delete a.width;delete a.height;for(var c in a)if(a[c])b.push('<param name="'+Silverlight.HtmlAttributeEncode(c)+'" value="'+Silverlight.HtmlAttributeEncode(a[c])+'" />');b.push("</object>");return b.join("")};Silverlight.createObjectEx=function(b){var a=b,c=Silverlight.createObject(a.source,a.parentElement,a.id,a.properties,a.events,a.initParams,a.context);if(a.parentElement==null)return c};Silverlight.buildPromptHTML=function(b){var a="",d=Silverlight.fwlinkRoot,c=b.version;if(b.alt)a=b.alt;else{if(!c)c="";a="<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";a=a.replace("{1}",c);a=a.replace("{2}",d+"108181")}return a};Silverlight.getSilverlight=function(e){if(Silverlight.onGetSilverlight)Silverlight.onGetSilverlight();var b="",a=String(e).split(".");if(a.length>1){var c=parseInt(a[0]);if(isNaN(c)||c<2)b="1.0";else b=a[0]+"."+a[1]}var d="";if(b.match(/^\d+\056\d+$/))d="&v="+b;Silverlight.followFWLink("149156"+d)};Silverlight.followFWLink=function(a){top.location=Silverlight.fwlinkRoot+String(a)};Silverlight.HtmlAttributeEncode=function(c){var a,b="";if(c==null)return null;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);if(a>96&&a<123||a>64&&a<91||a>43&&a<58&&a!=47||a==95)b=b+String.fromCharCode(a);else b=b+"&#"+a+";"}return b};Silverlight.default_error_handler=function(e,b){var d,c=b.ErrorType;d=b.ErrorCode;var a="\nSilverlight error message     \n";a+="ErrorCode: "+d+"\n";a+="ErrorType: "+c+"       \n";a+="Message: "+b.ErrorMessage+"     \n";if(c=="ParserError"){a+="XamlFile: "+b.xamlFile+"     \n";a+="Line: "+b.lineNumber+"     \n";a+="Position: "+b.charPosition+"     \n"}else if(c=="RuntimeError"){if(b.lineNumber!=0){a+="Line: "+b.lineNumber+"     \n";a+="Position: "+b.charPosition+"     \n"}a+="MethodName: "+b.methodName+"     \n"}alert(a)};Silverlight.__cleanup=function(){for(var a=Silverlight._silverlightCount-1;a>=0;a--)window["__slEvent"+a]=null;Silverlight._silverlightCount=0;if(window.removeEventListener)window.removeEventListener("unload",Silverlight.__cleanup,false);else window.detachEvent("onunload",Silverlight.__cleanup)};Silverlight.__getHandlerName=function(b){var a="";if(typeof b=="string")a=b;else if(typeof b=="function"){if(Silverlight._silverlightCount==0)if(window.addEventListener)window.addEventListener("unload",Silverlight.__cleanup,false);else window.attachEvent("onunload",Silverlight.__cleanup);var c=Silverlight._silverlightCount++;a="__slEvent"+c;window[a]=b}else a=null;return a};Silverlight.onRequiredVersionAvailable=function(){};Silverlight.onRestartRequired=function(){};Silverlight.onUpgradeRequired=function(){};Silverlight.onInstallRequired=function(){};Silverlight.IsVersionAvailableOnError=function(d,a){var b=false;try{if(a.ErrorCode==8001&&!Silverlight.__installationEventFired){Silverlight.onUpgradeRequired();Silverlight.__installationEventFired=true}else if(a.ErrorCode==8002&&!Silverlight.__installationEventFired){Silverlight.onRestartRequired();Silverlight.__installationEventFired=true}else if(a.ErrorCode==5014||a.ErrorCode==2106){if(Silverlight.__verifySilverlight2UpgradeSuccess(a.getHost()))b=true}else b=true}catch(c){}return b};Silverlight.IsVersionAvailableOnLoad=function(b){var a=false;try{if(Silverlight.__verifySilverlight2UpgradeSuccess(b.getHost()))a=true}catch(c){}return a};Silverlight.__verifySilverlight2UpgradeSuccess=function(d){var c=false,b="3.0.40818",a=null;try{if(d.IsVersionSupported(b+".99")){a=Silverlight.onRequiredVersionAvailable;c=true}else if(d.IsVersionSupported(b+".0"))a=Silverlight.onRestartRequired;else a=Silverlight.onUpgradeRequired;if(a&&!Silverlight.__installationEventFired){a();Silverlight.__installationEventFired=true}}catch(e){}return c}//----------------------------------------------------------------------//
// IDV Solutions Visual Fusion Suite                                    //
// Copyright (C) 2009 IDV Solutions                                     //
//----------------------------------------------------------------------//

// Constructs a new XAP host instance
function VfxXapHost(div, src, id) {
	this.Initialize(div, src, id);
};

// Table of XAP instances
VfxXapHost.Instances = new Object();
VfxXapHost.NamedInst = new Object();

// Accessor for XAP host instances
VfxXapHost.GetXap = function(id) {
	return VfxXapHost.NamedInst[id];
}

// **DEPRICATED: use the appropriate SetXxx method instead**
// Sets an object to use during initialization [must be
// called *before* calling LoadXap][**VFX4.0 bhack**]
VfxXapHost.prototype.SetInitVariable = function(name, value) {

   this.SetInitObject(name, value);

   switch(name) {
   case "IconFiles":    this.SetIconArchives(value); break;
   case "SafeDomains":  this.SetSafeDomains(value);  break;
   case "VirtualEarth": this.SetBingMapsArgs(value); break;
   case "ViewFence":    this.SetViewFence(value);    break;
   case "InitialView":  this.SetInitialView(value);  break;
   }
}

// Convenience method for getting map interface
VfxXapHost.prototype.GetMap = function() {
   return this.GetInterface("Map");
}

// Convenience method for getting the feeds interface
VfxXapHost.prototype.GetFeeds = function() {
	return this.GetInterface("Feeds");
}


// Sets the prefix to put before URLs that must be proxied
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetHttpProxyPrefix = function(value) {
   this.SetInitString("__httpproxy", value);
}

// Sets the address of the client tools configuration file
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetClientConfigPath = function(value) {
   this.SetInitString("__clientconfig", value);
}

// Sets the address of the root feed configuration file
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetRootFeedsPath = function(value) {
   this.SetInitString("__rootfeeds", value);
}

// Sets list of HTTP domains that can be directly queried
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetSafeDomains = function(value) {
   this.SetInitObject("__safedomains", value);
}

// Sets list of icon archives to load into the application
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetIconArchives = function(value) {
   this.SetInitObject("__iconarchs", value);
}

// Sets the Bing Maps Web Service configuration for an app
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetBingMapsArgs = function(value) {
   this.SetInitObject("__bingmaps", value);
}

// Sets the initial map view configuration for an app
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetInitialView = function(value) {
   this.SetInitObject("__initview", value);
}

// Sets the fence for a map view for an application
// [this method must be called *before* calling LoadXap]
VfxXapHost.prototype.SetViewFence = function(value) {
   this.SetInitObject("__viewfence", value);
}


// Sets the value of a URL variable
VfxXapHost.prototype.SetUrlVariable = function(name, value) {
   this.UrlVars[name] = value;
}

// Sets a string to use during initialization
// [must be called *before* calling LoadXap]
VfxXapHost.prototype.SetInitString = function(name, value) {
   this.InitStrings[name] = value;
}

// Sets an object to use during initialization
// [must be called *before* calling LoadXap]
VfxXapHost.prototype.SetInitObject = function(name, value) {
   this.InitObjects[name] = value;
}


// Loads the XAP file into the browser
// init: (optional) arguments in form "arg1=value1&arg2=value2&..."
VfxXapHost.prototype.LoadXap = function(init)
{
   // create a DIV for holding VFX
   var parentDiv = document.getElementById(this.Parent);
   var vfxXapDiv = document.createElement("div");
   
   // clear all children of parent node [**VFX4.0 bhack**]
   for(var i = parentDiv.lastChild; i != null; i = i.previousSibling) {
      parentDiv.removeChild(i);
   }

   // insert a DIV for holding VFX
   vfxXapDiv.style.width = '100%';
   vfxXapDiv.style.height = '100%';
   parentDiv.appendChild(vfxXapDiv);

   // create Silverlight control container
	Silverlight.createObjectEx({
		parentElement: vfxXapDiv,
		source: this.GetXapSource(),
		id: this.ID,
		initParams: init,
		properties: {
			width: "100%",
			height: "100%",
			version: "2.0",
			isWindowless: "false",
			enableHtmlAccess: "true"
			//++enableCacheVisualization: "true",
			//++enableGPUAcceleration: "true"
		},
		events: {
			onLoad:  this.HandleXapLoaded,
			onError: this.HandleXapError
		}
	});
}


// Constructs a new VfxXapHost object instance
VfxXapHost.prototype.Initialize = function(div, src, id)
{
   // setup internal properties
   this.ID = div+"_xapobj";
   this.VfxVer = "Unknown";
   this.Parent = div;
   this.Source = src;
   this.Loaded = false;
   this.UrlVars = new Object();
   this.InitObjects = new Object();
   this.InitStrings = new Object();

   // save reference to XapHost object
   VfxXapHost.Instances[this.ID] = this;

   // set default values [**VFX4.0 bhacks**]
   this.SetHttpProxyPrefix("HttpRequestProxy.vfs?query=");
   this.SetClientConfigPath("{MapConfigFile}");
   this.SetRootFeedsPath("{RootFeedsFile}");

   // store in named instances table
   if(id != null && id.length > 0) {
      VfxXapHost.NamedInst[id] = this;
   }
}


// Called when XAP file has been loaded [NOTE: this
// method is executed in context other than VfxXapHost]
VfxXapHost.prototype.HandleXapLoaded = function(sender, args)
{
	if(sender != null) {
		VfxXapHost.Instances[sender.id].HandleXapLoadedImpl(sender, args);
	}
}


// An error occured inside of the XAP file [NOTE: this
// method is executed in context other than VfxXapHost]
VfxXapHost.prototype.HandleXapError = function(sender, args)
{
	if(args.errorType != "ImageError") {
		for(var i in VfxXapHost.Instances) {
			VfxXapHost.Instances[i].HandleXapErrorImpl(sender, args);
		}
	}
}


// Obtains an interface into the VFX application
VfxXapHost.prototype.GetInterface = function(name)
{
	try {
		return this.ManagedObject.Content[name];
	} catch(ex) {
		return null;
	}
}


// Called when XAP file has been loaded
VfxXapHost.prototype.HandleXapLoadedImpl = function(sender, args)
{
	// save reference to managed XAP object
	this.ManagedObject = sender;
	this.Common = this.GetInterface("VfxXapHostCommon");
	this.Loaded = true;

	// initialize silverlight control
	if(this.Common != null) {

		// get VFX version string
		this.VfxVer = this.Common.GetVfxVersion();

		// set extra URL variables
		for(var i in this.UrlVars) {
			this.Common.SetUrlVariable(i, this.UrlVars[i]);
		}

		// let Silverlight know JS is ready
		this.Common.JavaScriptIsReady(
		   this.Parent,
		   this.ID,
		   this.InitObjects,
		   this.InitStrings
		);
	}

	// notify caller that load has occured
	if(this.onLoadXap != null) {
		this.onLoadXap();
	}
}


// Gets the full address of the XAP file to load
VfxXapHost.prototype.GetXapSource = function()
{
   var tmp = this.Source;
	var loc = window.location;

   // replace {host}, {webapp}, and {domain}
   tmp = tmp.replace(/{host}/gi, loc.host);
   tmp = tmp.replace(/{random}/gi, Math.random());
   tmp = tmp.replace(/{webapp}/gi, this.GetWebApp(loc));
   tmp = tmp.replace(/{domain}/gi, this.GetDomain(loc));

   // return the new XAP source URL
   return tmp;
}


// Gets value for the {domain} URL varible "http://server"
VfxXapHost.prototype.GetDomain = function(loc)
{
	return (loc.protocol+"//"+loc.host);
}


// Gets value for the {webapp} URL varible "http://server/path"
VfxXapHost.prototype.GetWebApp = function(loc)
{
	var url = loc.href;
	var i = url.lastIndexOf('/');
	if(i >= 0) {
		return url.substring(0, i);
	} else {
		return url;
	}
}


// An error occured inside of the XAP file
VfxXapHost.prototype.HandleXapErrorImpl = function(sender, args)
{
	var newNode;
	var parNode;
	var errMsg;

	// create new text area element;
	// get Silverlight control host
	errMsg = this.CreateDefaultErrMsg(args);
	parNode = document.getElementById(this.Parent);

	// remove all child nodes
	while(parNode.firstChild != null) {
		parNode.removeChild(parNode.firstChild);
	}

	// create and embed a new text area
	newNode = document.createElement("textarea");
	newNode.appendChild(document.createTextNode(errMsg));
	newNode.setAttribute("cols", Math.floor((parNode.clientWidth/8)-10));
	newNode.setAttribute("rows", Math.floor(parNode.clientHeight/18));
	newNode.setAttribute("readOnly", "readonly");
	newNode.setAttribute("wrap", "off");
	parNode.appendChild(newNode);

	// clear map viewer reference
	gMapViewer = null;
}


// Message for runtime failure
VfxXapHost.prototype.CreateDefaultErrMsg = function(args)
{
	if(args.errorType == "InitializeError" && args.errorCode == 2104) {
		return (
			"Could not download the Silverlight XAP file:\r\n" +
			this.Source +"\r\n\r\n"+
			"Check web server settings and ensure that *.xap\r\n"+
			"files are supported in MIME type settings. See\r\n"+
			"http://learn.iis.net/page.aspx/262/silverlight/\r\n"+
			"for server setup instructions."
		);
	} else {
		return (
			"Silverlight Application Error\r\r"+
			"VFX Version:  " + this.VfxVer    +"\r"+
			"VFX XAP File: " + this.Source    +"\r"+
			"VFX XAP DIV:  " + this.Parent    +"\r"+
			"Error Type:   " + args.errorType +"\r"+
			"Error Code:   " + args.errorCode +"\r"+
			"\r"+ args.errorMessage +"\r"
		);
	}
}


// Populates a details page
VfxXapHost.PopulateDetailsPage = function(wnd, doc, contentName)
{
   // get information about details page
   var url = wnd.location.href;
   var fore = VfxXapHost.GetUrlArgValue(url, "fgcolor", "000000");
   var back = VfxXapHost.GetUrlArgValue(url, "bgcolor", "ffffff");
   var link = VfxXapHost.GetUrlArgValue(url, "linkcolor", "0000ff");
   var content = VfxXapHost.GetDetailsContent(wnd);
   var element = doc.getElementById(contentName);

   // set color for links
   if(doc.styleSheets[0].insertRule) {
      doc.styleSheets[0].insertRule("a { color:#"+link+"; }", 0);
   } else {
      doc.styleSheets[0].addRule("a", "color:#"+link);
   }

   // set text and background color
   doc.documentElement.style.backgroundColor="#"+back;
   doc.documentElement.style.color="#"+fore;

   // populate content area
   element.innerHTML = content;
}


// Accessor for details content (internal use only)
VfxXapHost.GetDetailsContent = function(wnd)
{
   var id = VfxXapHost.GetUrlArgValue(wnd.location.href, "contentID");

   for(var i in VfxXapHost.Instances) {
      var common = VfxXapHost.Instances[i].Common;
      if(common != null) {
         var content = common.GetDetailsContent(id);
         if(content != null) {
            return content;
         }
      }
   }

   return null;
}


// Reads the value of an argument from container page
VfxXapHost.GetPageArgValue = function(argName, defval)
{
   return VfxXapHost.GetUrlArgValue(window.location.href, argName, defval);
}


// Reads the value of a URL parameter [internal use only]
VfxXapHost.GetUrlArgValue = function(url, arg, defval)
{
   // quit now if URL is not valid
   if(url.length <= 0) {
      return defval;
   }

   // get index of 1st character of value
   arg = arg+"=";
   begin = url.indexOf(arg)+arg.length;

   // argument was not found
   if(begin < arg.length) {
      return defval;
   }

   // get index of end character of value
   if((end = url.indexOf("&", begin)) == -1) {
      end = url.length;
   }

   // return unescaped value
   return unescape(url.substring(begin, end));
}

