
/** @var g_msie_windows
	@brief Set equal to 1 if the browser is Microsoft Internet Explorer.  Used to determine if VBScript ActiveX detection is possible.
*/
// Header info for VBScript specific functions
var g_msie_windows = 0;

// Current DLM version
var g_ESD_CurrentVer = 1.1;

//#ifndef DOXYGEN_SHOULD_SKIP_THIS
// optional function for MSIE browsers only
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1))
{
	g_msie_windows = 1;
	document.writeln('<script language="VBscript">');
	document.writeln('Dim vbs_detectPossible');
	document.writeln('vbs_detectPossible = 0');
	document.writeln('If ScriptEngineMajorVersion >= 2 then');
	document.writeln('  vbs_detectPossible = 1');
	document.writeln('End If');

	// Inline the vbs_getADMVersion function
	document.writeln('Function vbs_getADMVersion(activeXname)');
	document.writeln('on error resume next');
	document.writeln('Dim oObj');
	document.writeln('Set oObj = CreateObject(activeXname)');
	document.writeln('If (IsObject(oObj) = True) Then');
	document.writeln('vbs_getADMVersion = oObj.GetVersion()');
	document.writeln('Exit Function');
	document.writeln('Else');
	document.writeln('vbs_getADMVersion = 0');
	document.writeln('End If');
	document.writeln('vbs_getADMVersion = 0');
	document.writeln('End Function');
	document.writeln('</' +'script>');
}
//#endif // DOXYGEN_SHOULD_SKIP_THIS


/** @fn fESDGetDLMVersion()
	@ingroup Exported
	@brief Main call to determine the current ESD version installed on the client machine.
	@return (float) Current ESD version
*/
function fESDGetDLMVersion()
{
	// Params needed for detection
	var plugindescription, pluginxtension, pluginmime, activeXname;
	plugindescription = 'ESD Manager';
	pluginxtension = 'aomver';
	pluginmime = 'application/aom-getversion';
	activeXname = 'ADM.Document';

  // local state variables
  var i,pluginUndetectable=0, oPlugin=new Object();

  // the current version
  var sESDVer = 0;

  // Then we check to see if it's an MSIE browser that you can actually
  // check for the plugin in question.
  if (g_msie_windows && vbs_detectPossible)
  {
      pluginUndetectable = 0;
  }
  else
  {
      pluginUndetectable = 1;

  }

  // If it has a real plugins or mimetypes array, we look there for the plugin first.  Used for Netscape.

  if(navigator.plugins)
  {
  	  // First refresh the plugins so that we catch us if we were just loaded
      navigator.plugins.refresh();

      numPlugins = navigator.plugins.length;
      if (numPlugins > 1)
      {
	  	if (navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1))
	  	{
	  		// seems like we have it, let's just make sure and check the version (if specified)
	      		if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1))
	     	 	{
	     	 		// Netscape can't handle the references to navigator.plugins by number, sooo...
		  			for(i in navigator.plugins)
		  			{
		      			if ((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1))
		      			{
		      				sESDVer = js_getVerFromDescription(navigator.plugins[i].description);
				  			break;
		      			}
		  			}
	      		}
	      		else
	      		{
		  			for (i = 0; i < numPlugins; i++)
		  			{
		      			oPlugin = navigator.plugins[i];

				      	if ((oPlugin.description.indexOf(plugindescription) != -1) || (oPlugin.name.indexOf(plugindescription) != -1))
				      	{
			      			sESDVer = js_getVerFromDescription(oPlugin.description);
					  		break;
				      	}
		  			}
	      		}
	  		}


	  		return parseFloat(sESDVer);
	    }
		 // Try the MSIE Automation route...
		else if((g_msie_windows == 1) && !pluginUndetectable)
		{
			 sESDVer = vbs_getADMVersion(activeXname);
		 	 return parseFloat(sESDVer);
		}
	}

  return parseFloat(sESDVer);
}


/** @fn bESDIsAtLeastNetscape4x()
	@ingroup Exported
	@brief Helper function to determine if the current browser is NS 4.x.
	@return (bool) Is the current browser NS 4.x?
*/
function bESDIsAtLeastNetscape4x()
{
	var sBrowser = navigator.appName.toLowerCase();
	if (sBrowser.indexOf("netscape")!=-1)
	{
        var strVer = parseFloat(navigator.appVersion);
        return (strVer >= 4);
	}
	return false;
}


/** @fn bESDIsAtLeastIE4x()
	@ingroup Exported
	@brief Helper function to determine if the current browser is at least IE 4.x or higher.
	@return (bool) Is the current browser IE 4.x or greater?
*/
function bESDIsAtLeastIE4x()
{
	var fVersion=0
	if (navigator.appVersion.indexOf("MSIE")!=-1)
	{
		var strVer=navigator.appVersion.split("MSIE")
		fVersion=parseFloat(strVer[1])
	}
	return (fVersion >= 4.0);
}


/** @fn js_getVerFromDescription(plugindescription)
	@ingroup InternalFuncs
	@brief Parses the MIME type description of the NS plugin to determine the current ESD version.
	@return ESD version extracted from description
*/
function js_getVerFromDescription(plugindescription)
{
	var ss, i, val, sVer;
	ss = plugindescription.split(" ");
	for (i=0; i < ss.length; i++)
	{
		val = parseFloat(ss[i]);
		if (val)
		{
			sVer = val.toString(10);
			return sVer;
		}
	}
	return 0;
}
