// Decide whether to EMBED JSyn Plugin for Navigator.
// Author: Phil Burk 1999
// Modifications:
//   4/6/01 - PLB added sniffer for iCab and check for Java enabled
//   5/7/01 - PLB sniff for Netscape 6 (aka Mozilla 5.0) on Mac
//   1/29/03 - PLB check for Netscape V>4 and assume it is using Sun Java
	
// Is it a type of Netscape browser?
var app = navigator.appName.toLowerCase();
var is_netscape = (app.indexOf("netscape") != -1 );

// Is it iCab for Macintosh masquerading as a Netscape browser?
var agt = navigator.userAgent.toLowerCase();
var is_icab = (agt.indexOf("icab") != -1);

// Is it a Macintosh?
var platform = navigator.platform.toLowerCase();
var is_mac = (agt.indexOf("mac") != -1);

var appversion = parseFloat(navigator.appVersion); 
    
var is_mac_netscape6 = is_mac && (appversion >= 5.0);

if( !navigator.javaEnabled() )
{
	document.writeln("<P><B>Java is NOT enabled for your browser.");
	document.writeln("You cannot run JSyn without Java!</B><P>");
}
// Mac Netscape 6 uses MRJ and PC Netscape uses real Java!
else if( is_netscape && !is_icab && (appversion < 5.0) )
{
// If we are running an old Netscape browser then we should use the Netscape Plugin.
// Has the plugin been installed?
// Check for name that we used on both Mac and PC.
	var jsynPcPlugin = navigator.plugins["SoftSynth JSyn"];
	var jsynMacPlugin = navigator.plugins["npJSyn"];
	if( (jsynMacPlugin == undefined) && (jsynPcPlugin == undefined))
	{
		document.writeln("<p><b>ERROR:</b> The JSyn plugin could not be found!");
		document.writeln("You can download the free JSyn plugin from ");
		document.writeln('<A HREF="http://www.softsynth.com/jsyn/plugins">here</A>.<P>');
	}
	else
	{
	// check property on global navigator object to see if plugin window already open
	// If open, don't open it again because Netscape may hang if
	// the garbage collector is running, or if threads call the plugin
	// while we are EMBEDding plugin.
		jsynPluginWindow = navigator.jsynPluginWindow;
		if (jsynPluginWindow)
		{
			document.writeln("Using already open JSyn Plugin Window.<P>");
		}
		else
		{
	// not open so we had better open it now
			navigator.jsynPluginWindow = window.open("embed_jsyn_plugin.html",
				"SharedJSynWindow",
				"toolbar=no,resizable=yes,scrollbars=yes,height=240,width=520");
			document.writeln("Opened Plugin Window for JSyn.<P>");
		}
	}
}
else
{
// For Internet Explorer or iCab or NS6, don't try to EMBED the Netscape Plugin because IE may crash.
	document.writeln("This Applet requires the JSyn plugin.");
	document.writeln("If the Applet fails to run, you can download the free JSyn plugin from ");
	document.writeln('<A HREF="http://www.softsynth.com/jsyn/plugins">here</A>.<P>');
}
