
// Test for ECW installation.  This code will test to see if the ECW plugin has
// already been installed, and if it is compatible with the browser.
// The page will be redirected to /ecwplugins/download.htm or /ecwplugins/sorry.htm
// if the plugin is not installed or not supported.
// The full check function
function ECWCheck() {
	var sBrowser = navigator.appName;
	var sAgent   = navigator.userAgent.toLowerCase();	
	var nVersion = parseFloat(navigator.appVersion);
	var sECWMime = "application/x-ImageWebServer-ecw";
	var sECWActiveX = "NCSViewManager.NCSView.1";
	var sECWVersion = "1,7,1,43";
	var bWinIE = 0;	// 1 = Windows IE

	if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1))
		bWinIE = 1;

	var nResult = 0;		// 0 = not supported; 1 = IE; 2 = Netscape; -1 = must download
	// must be >= IE 4.0 or >= Netscape 4.5
	if( sBrowser == "Netscape" && nVersion >= 4.5 )
		nResult = 2;
	else if( sBrowser == "Microsoft Internet Explorer" && nVersion >= 4.0 )
		nResult = 1;
	if( nResult )
		if( sAgent.indexOf("win") == -1 )	//only available on the windows platform
			nResult = 0;
	if( nResult ) {
		var bECWInstalled = 0;
		var nPlugins = navigator.plugins.length;
		// Check to see if the Mime is installed - either in IE or Netscape
      	if (nPlugins > 1) {
			if(	navigator.mimeTypes &&	navigator.mimeTypes[sECWMime] && 	navigator.mimeTypes[sECWMime].enabledPlugin ) {
				if(netscape.softupdate.Trigger.UpdateEnabled()) {
       			var sVersion;
  
					sVersion = netscape.softupdate.Trigger.GetVersionInfo("plugins/IWS/ImageViewer");
					if(sVersion.compareTo(sECWVersion.replace(/,/g, ".")) >= 0) {
						bECWInstalled = 1;
					}
				} else {
					alert("You must enable SmartUpdate before you can automatically download the Image Web Server image viewing plug-in.");
				}
			}
		}
		// If no mime, check if VB
		if( !bECWInstalled && nResult == 1 && bWinIE ) {
			if(ECWCheckActiveX(sECWActiveX, sECWVersion))
				bECWInstalled = 1;
		}
		if( !bECWInstalled )
			nResult = -1;		// not found, but we can install the plug-in
	}
	return(nResult);
}


