//N4C2.JS is used in PE, FIND-NCB, and MORPHER!
// debug #'s in use thru #4

// must match protexpl/version.js (used to detect bad installations)
var shared_version = "1.923 Alpha";

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
NP = navigator.plugins;
var chii;
var chimeVersionCookieName = "chi_ver";
var chimeVersion = "";

var compatible_browser_list =
"<center><big><b>Compatible Browsers</b></big></center>\
Protein Explorer-Compatible Browsers in <big><font color='red'>Windows</font></big>: \
<ul> \
<li>Recommended: Netscape Communicator 4.7X with Chime 2.0.3 or later. \
<li>Netscape Navigator 4.08 with Chime 2.0.3 or later. \
<p> \
<li>Internet Explorer Version 5.5, Update Version SP2 with Chime 2.6 SP3 \
or later. \
</ul> \
Protein Explorer-Compatible Browsers in <big><font color='red'>Macintosh</font></big>: \
<ul> \
<li>Recommended: Netscape Communicator 4.7X with Chime 2.0a or later. \
<li>Netscape Navigator 4.08 with Chime 2.0a or later. \
<li> (Not Internet Explorer.)\
</ul> \
How to use PE with <big><a href='needplat.htm'>linux and other platforms</a></big>.\
<p>Incompatible Browsers: \
<ul> \
<li>Windows: Internet Explorer versions before 5.5 SP2. \
<li>Macintosh: Internet Explorer. \
<li>Netscape version 6. \
<li>Netscape Navigator versions before 4.08. \
<li>Mozilla (www.mozilla.org - same problems as Netscape 6). \
</ul> \
Untested Browsers: \
<ul> \
<li>Internet Explorer version 6. \
<li>Opera. \
</ul> \
<center><big><b>Version Checking</b></big></center>\
The version reported at the top of this page should be correct. \
However, if you want to verify this independently, here is how \
to determine the version of your browser: \
<ul> \
<li>Netscape: open the Help menu at the very top, and click on \"About \
Netscape\" or \"About Communicator\". \
<li>Internet Explorer: open the Help menu at the very top, and click on \"About \
Internet Explorer\". Pay attention to both the Version and the Update Versions. \
</ul> \
Determining the version of the Chime installed in your browser: \
<ul> \
 \
<li>Netscape: open the Help menu at the very top, and click on \"About \
Plug-ins\". Scroll down until you find Chime. If Chime is not in the list \
of plug-ins, it is not installed in <i>this</i> browser. (It might be installed \
in another browser or another version of this browser on your system.) \
 \
<li>Internet Explorer: If you are on-line, click on \
<a href='http://www.umass.edu/microbio/chime/atp.pdb'>ATP</a>. \
If the window does not turn black and show the ATP molecule, \
see <a href='troubles.htm'>Troubleshooting</a>. \
Otherwise, click on MDL at the lower right, then on the menu \
that pops up, click on \"About...\". If you are off-line and have \
any PDB file (with a filename ending <b>.pdb</b>) on your disk, \
open the File menu at the very top, click Open, and use the Browse \
button to view the molecule. Then follow the previous instructions. \
 \
</ul> \
If you are having problems despite having a compatible browser and \
Chime, please see \
<a href='troubles.htm'>Troubleshooting</a>. \
";

// DETECT BROWSER TYPE AND VERSION
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function get_IE_version()
{
	var vi = navigator.appVersion.indexOf('MSIE ') + 5;
	var iev = parseFloat(navigator.appVersion.substring(vi));
//	alert("n4c2.js get_IE_version() returns " + iev);
	return iev;
}
function get_IE_SP() // ";SP2;Q306121;Q312461;"
{
	var isp = navigator.appMinorVersion.indexOf("SP");
	if (isp == -1)
		return null;
	var iesp = parseFloat(navigator.appMinorVersion.substring(isp + 2));
//	alert("n4c2.js get_IE_SP() returns " + iesp);
	return iesp;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 

//pp modified by em
var thisBrowser = "unknown";
var isNetscape = false;
var isIE = false;

if (navigator.appName=='Netscape') // not "Navigator"!
{
	thisBrowser = "ns";
	isNetscape = true;		
}
else if (navigator.appName=='Microsoft Internet Explorer')
{
	thisBrowser = "ie";
	isIE = true;		
}

var browserVersion;
if (isNetscape)
	browserVersion = parseFloat(navigator.appVersion);
if (isIE)
	browserVersion = get_IE_version();
var IE_SP;
if (isIE)
	IE_SP = get_IE_SP();

//alert("n4c2 #4:\n" +
//	"thisBrowser = " + thisBrowser + "\n" +
//	"isIE = " + isIE + "\n" +
//	"isNetscape = " + isNetscape + "\n" +
//	"browserVersion = " + browserVersion + "\n" +
//	"IE_SP = " + IE_SP + "\n");

/*
alert("n4c2.js debug#1:\n" +
	"navigator.appCodeName " + navigator.appCodeName + "\n" +
	"navigator.appName " + navigator.appName + "\n" +
	"navigator.appVersion " + navigator.appVersion + "\n" +
	"navigator.appMinorVersion " + navigator.appMinorVersion + "\n" +
	"navigator.browserLanguage " + navigator.browserLanguage + "\n" +
	"navigator.cookieEnabled " + navigator.cookieEnabled + "\n" +
	"navigator.javaEnabled() " + navigator.javaEnabled() + "\n" +
	"navigator.cpuClass " + navigator.cpuClass + "\n" +
	"navigator.language " + navigator.language + "\n" +
	"navigator.onLine " + navigator.onLine + "\n" +
	"navigator.platform " + navigator.platform + "\n" +
	"navigator.systemLanguage " + navigator.systemLanguage + "\n" +
	"navigator.userAgent " + navigator.userAgent + "\n" +
	"navigator.userLanguage " + navigator.Language + "\n" +
	"navigator.userProfile " + navigator.Profile + "\n");
*/

// IE appVersion = "4.0 (compatible; MSIE 5.5; Windows 98; T312461)"
// IE appMinorVersion = ";SP2;Q306121;Q312461;"
// IE About reports "Update Versions:; SP2; Q306121; Q312461;
// NS appVersion = "4.77 [en] (Win98; U)"
// NS appMinorVersion = "undefined"
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
// any_navigator() is no longer used in PE, but is here for FIND-NCB, MORPHER!
function any_navigator()
{
	return (top.isNetscape);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 

function navv408()
{
	if (!top.isNetscape)
		return false;
//pp
	if (4.08 <= browserVersion)
		return true;
	return false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function navv406()
{
	if (!top.isNetscape)
		return false;
	if (4.06 <= browserVersion)
		return true;
	return false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function navv404()
{
	if (!top.isNetscape)
		return false;
	if (4.04 <= browserVersion)
		return true;
	return false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function navv6()
{
	if (!top.isNetscape)
		return false;
	if (browserVersion > 4.999)
		return true;
	return false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function findNP(match)
{
	var nplen = NP.length;
	var piname;

	for (i = 0; i < nplen; i++)
	{
		piname = NP[i].name.toLowerCase();
	
		if (piname.indexOf(match) != -1)
			return(i);
	}
	return (-1);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function any_chime()
{
	chii = findNP("chemscape chime");

	if (chii == -1)
		return false;
	return true;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function chiv2()
{
	// chii = CHIme Index in plugin array
	if (!any_chime())
		return false;

//	alert(NP[chii].name);

	// WARN ABOUT MAC CHIME 2.0 TIMING BUG
	if (navigator.appVersion.toLowerCase().indexOf("mac") != -1)
		if (NP[chii].name.indexOf("2\.0a") == -1 &&
			NP[chii].name.indexOf("2\.0") != -1)
			alert("You should upgrade your Chime from\n" +
			"www.mdlchime.com -\n" +
			"Macintosh version 2.0 has a timing bug\n" +
			"and does some things extremely slowly.");

	var chok = false;
	var maybe = false; // user must confirm
	
	// OK IF 2.X
	var i = NP[chii].name.indexOf(" 2\."); // 2.0 or 2.6; note leading space!
	if (i != -1) // version 2.x
		chok = true;

	// IF 2.X BETA, MAYBE OK
	if (NP[chii].name.toLowerCase().indexOf("beta") != -1)
		maybe = true;

	// IF NOT 2.X, IF >2.6, GIVE IT A TRY (V3?)
	if (!chok)
	{
		if (parseFloat(chime_version()) > 2.6)
		{
			chok = true;
			maybe = true;
		}
	}
	if (maybe)
		chime_maybe();

	return (chok);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Returns version number of Chime (Netscape only)
function chime_version()
{
	// chii = CHIme Index in plugin array
	if (!any_chime())
		return "";

//	alert(NP[chii].name);

// Assume "Chemscape Chime N.NN"
	var cv = NP[chii].name.substring(16);

//	alert("|" + cv + "|");
	return cv;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function chime_maybe()
{
	chimeVersion = chime_version();
//	alert("debug #2 n4c2.js: chimeVersion = " + chimeVersion);
	var cvc = getCookie(chimeVersionCookieName);
	if (chimeVersion == cvc)
		return; // user has set cookie to stop warning.

	var m = "The Chime version with this browser,\n\"" +
		NP[chii].name +
		"\"\nis unexpected and may not work properly.\n" +
		"Cancel if you never want this warning again.";

	if (confirm(m))
		return;

	if (!confirm("You will never again be warned about this\n" +
		"version of Chime if you press OK.\n" +
		"OK only if you have verified that it works!\n" +
		"Cancel to be warned in your next PE session."))
			return;

	// Set cookie to avoid annoying user with warning.
	putCookie_year(chimeVersionCookieName, chimeVersion);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
// chime_version_ok() is called only after a suitable browser is verified.
function chime_version_ok()
{
	var valTestChime;
	var configuration;

	if (isIE) // IE top.isIE is undefined
	{
		valTestChime = GetCookieChime("ChimeIE");
//		alert("n4c2.js debug #3: ChimeIE cookie = " + valTestChime);
		if (valTestChime=="no")
		{
			// Chime has just been tested but is absent.
			killCookie("Chime"); // Probably not necessary since browser has
			// to be restarted after Chime installed or upgraded.
			return "no";
		}
		else 
		{
			if (valTestChime.indexOf("yes") != -1)
			{
				//See if the browser has changed since the last Chimetest.
				configuration = navigator.appVersion + navigator.appMinorVersion;
				configuration = escape(configuration.replace(';',''));
				if (valTestChime.indexOf(configuration) != -1)	 //Start PE !
					return "yes";
				else
				{
					killCookie("Chime"); // sets cookie to "ciao".
					return "test";
				}
			} //The chime plug-in hasn't yet been tested or browser has changed
			return "test";
		}
	}
	else
	{
		if (!chiv2())  // Netscape: Chime 2 must be installed
			return "no";
		// NOTE: checks for chime 2.0.3 are processed in s2c2.js and mirrors.htm!
		// No need to insist on 2.0.3 yet here.
		else return "yes";
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 

