//added initialization
var flashVersion = "0";

function flashCompatibility() {
// Assumes the version string returned by compatibilityTest.swf is of the form:
// PLATFORM MM,0,mm,0
// where PLATFORM is a string (mac, win, unix) followed by a space
//       MM is the major version number (currently a single digit
//       ,0, is a separator
//       mm is the minor version number
//       ,0 is a separator
// If anything varies, then "cannot detect" message will be displayed.
// Currently, we are only looking for major version >= 6 as "OK"
// Less than 6 is "need to upgrade"

//Compute length of string (for future substring uses)
	var flashVersion_len = flashVersion.length;

//Determine where the space after PLATFORM is
	var space_pos = flashVersion.indexOf(" ");

//Determine starting location of major version string
	var flash_version_string_pos = space_pos + 1;

//Get all of version string (everything after the space)
	var flash_version_string = flashVersion.substr(flash_version_string_pos, flashVersion_len - space_pos);

//Determine where ,0, separate starts
	var flash_comma_zero_comma_pos = flash_version_string.indexOf(",0,");

	if (flash_comma_zero_comma_pos == -1) {
		document.getElementById('compatibility_cannotDetect_flash').style.display = 'inline';
		document.getElementById('compatibility_install_flash').style.display = 'inline';
		return;
	}

	document.getElementById('compatibility_version').style.display = 'inline';
	
//Get Major version number
	var flash_major_version_string = flash_version_string.substr(0, flash_comma_zero_comma_pos);

	if (flash_major_version_string >= 6) {
		if (flash_major_version_string == 6) {
			document.getElementById('compatibility_flash6').style.display = 'inline';
		} else if (flash_major_version_string == 7) {
			document.getElementById('compatibility_flash7').style.display = 'inline';
		} else {
			document.getElementById('compatibility_flash8').style.display = 'inline';
		}
		document.getElementById('compatibility_passed_flash').style.display = 'inline';
	} else {
		document.getElementById('compatibility_flash5orearlier').style.display = 'inline';
		document.getElementById('compatibility_upgrade_flash').style.display = 'inline';
		return;
	}

//Get string after the 0,0 to isolate minor version number
	var flash_after_comma_zero_comma = flash_version_string.substr(flash_comma_zero_comma_pos + 3, flash_version_string.length - (flash_comma_zero_comma_pos + 3));

//Determine where minor version string ends
	var flash_final_comma_zero_pos = flash_after_comma_zero_comma.indexOf(",0");
	var flash_minor_version_string = "0";
	if (flash_final_comma_zero_pos >= 0) {
		flash_minor_version_string = flash_after_comma_zero_comma.substr(0, flash_final_comma_zero_pos);
	}
}

function compatibility() {
	//added to initialize just in case something wrote to it.
	document.getElementById('compatibility_cannotDetect_flash').style.display = 'none';
	document.getElementById('compatibility_install_flash').style.display = 'none';
	//close added
	
	document.getElementById('compatibility_run_tests').style.display = 'none';
	document.getElementById('compatibility_component').style.display = 'inline';
	document.getElementById('compatibility_detected').style.display = 'inline';
	document.getElementById('compatibility_status').style.display = 'inline';
	document.getElementById('compatibility_javascript').style.display = 'inline';
	document.getElementById('compatibility_enabled').style.display = 'inline';
	document.getElementById('compatibility_passed_javascript').style.display = 'inline';
	document.getElementById('compatibility_flashPlayer').style.display = 'inline';
	document.getElementById('compatibility_suggested_upgrade_OS').style.display = 'none';

	if (flashVersion  !=  "0") {
		flashCompatibility();
	} else {
		document.getElementById('compatibility_cannotDetect_flash').style.display = 'inline';
		//document.getElementById('compatibility_install_flash').style.display = 'inline';
	}

	document.getElementById('compatibility_webBrowser').style.display = 'inline';
	document.getElementById('compatibility_OS').style.display = 'inline';

// Most of the following code is taken from:
// http://webreference.com/tools/browser/javascript.html

	// convert all characters to lowercase to simplify testing
	var agt = navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();

	var is_mac = (agt.indexOf("mac")!=-1);

	// *** BROWSER VERSION ***

	var is_minor = parseFloat(appVer);
	var is_major = parseInt(is_minor);

	var is_opera = (agt.indexOf("opera") != -1);

	var iePos  = appVer.indexOf('msie');
	if (iePos !=-1) {
		if(is_mac) {
			var iePos = agt.indexOf('msie');
			is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
		}
		else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
		is_major = parseInt(is_minor);
	}
	// Note: On IE, start of appVersion return 3 or 4
	// which supposedly is the version of Netscape it is compatible with.
	// So we look for the real version further on in the string
	// And on Mac IE5+, we look for is_minor in the ua; since 
	// it appears to be more accurate than appVersion - 06/17/2004

	var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;

	var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
	(agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
	(agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)	 &&
	 
	((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
	var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
	 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
	 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)	 &&
	  (navigator.vendor=="Firebird"));
	var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
		 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
		 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)	 &&
        (agt.indexOf('firefox')!=-1));
//		  (navigator.vendor=="Firefox"));
	if ((is_moz)||(is_fb)||(is_fx)) {  // 032504 - dmr
	   var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
	   if(!(is_moz_ver)) {
		   is_moz_ver = agt.indexOf('rv:');
		   is_moz_ver = agt.substring(is_moz_ver+3);
		   is_paren   = is_moz_ver.indexOf(')');
		   is_moz_ver = is_moz_ver.substring(0,is_paren);
	   }
	   is_minor = is_moz_ver;
	   is_major = parseInt(is_moz_ver);
	}
	var is_fb_ver = is_moz_ver;
	var is_fx_ver = is_moz_ver;

	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
		&& (!(is_moz)) && (!is_fb) && (!is_fx));

	// Netscape6 is mozilla/5 + Netscape6/6.0!!!
	// Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
	// Changed this to use navigator.vendor/vendorSub - dmr 060502   
	// var nav6Pos = agt.indexOf('netscape6');
	// if (nav6Pos !=-1) {
	if ((navigator.vendor)&&
		((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
		(is_nav)) {
	   is_major = parseInt(navigator.vendorSub);
	   // here we need is_minor as a valid float for testing. We'll
	   // revert to the actual content before printing the result. 
	   is_minor = parseFloat(navigator.vendorSub);
	}

	var is_nav7   = (is_nav && is_major == 7);
	var is_nav7up = (is_nav && is_minor >= 7);

	var is_ie   = ((iePos!=-1) && (!is_opera));
	var is_ie3  = (is_ie && (is_major < 4));

	var is_ie4   = (is_ie && is_major == 4);
	var is_ie4up = (is_ie && is_minor >= 4);
	var is_ie5   = (is_ie && is_major == 5);
	var is_ie5up = (is_ie && is_minor >= 5);
	
	var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
	var is_ie5_5up =(is_ie && is_minor >= 5.5);				// 020128 new - abk
	
	var is_ie6   = (is_ie && is_major == 6);
	var is_ie6up = (is_ie && is_minor >= 6);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
	// or if this is the first browser window opened.  Thus the
	// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.

	var is_aol   = (agt.indexOf("aol") != -1);
	
	// Done with is_minor testing; revert to real for N6/7
	if (is_nav7up) {
	   is_minor = navigator.vendorSub;
	}

	var is_mac = (agt.indexOf("mac")!=-1);

	// *** PLATFORM ***
	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
	var is_win31 = (agt.indexOf("windows 3.1")!=-1);

	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
	
	var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));    // new 020128 - abk
	var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1)); // 020214 - dmr
	var is_winxp = ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1)); // 020214 - dmr

	var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));


//Turn on and off various span tags for report
	if (is_mac) {
		is_win = !is_mac;

		var is_macosx = (is_mac && (agt.indexOf("mac os x")!=-1))

		if (is_safari) {
			document.getElementById('compatibility_Safari').style.display = 'inline';
			document.getElementById('compatibility_passed_browser').style.display = 'inline';
		} else if (is_fx) {
			document.getElementById('compatibility_Firefox').style.display = 'inline';
			document.getElementById('compatibility_passed_browser').style.display = 'inline';
		} else if (is_opera) {
			document.getElementById('compatibility_Opera').style.display = 'inline';
			document.getElementById('compatibility_passed_browser').style.display = 'inline';
		} else {
			if (is_ie) {
				document.getElementById('compatibility_IE').style.display = 'inline';
			} else if (is_nav) {
				document.getElementById('compatibility_Navigator').style.display = 'inline';
			} else if (is_aol) {
				document.getElementById('compatibiity_AOL').style.display = 'inline';
			} else {
				document.getElementById('compatibility_cannotDetect_browser').style.display = 'inline';
			}
			document.getElementById('compatibility_getMacBrowser').style.display = 'inline';
		}

		if (is_macosx) {
			document.getElementById('compatibility_MacOSX').style.display = 'inline';
			document.getElementById('compatibility_passed_OS').style.display = 'inline';
		} else {
			document.getElementById('compatibility_MacOS').style.display = 'inline';
			document.getElementById('compatibility_upgrade_OS').style.display = 'inline';
		}
	} else {  // Windows (and everything else)
		if (is_ie) {
			document.getElementById('compatibility_IE').style.display = 'inline';
			if (is_ie6up) {
				document.getElementById('compatibility_IE6').style.display = 'inline';
				document.getElementById('compatibility_passed_browser').style.display = 'inline';
			} else if (is_ie5_5up) {
				document.getElementById('compatibility_IE55').style.display = 'inline';
				document.getElementById('compatibility_passed_browser').style.display = 'inline';
			} else if (is_ie5up) {
				document.getElementById('compatibility_IE5').style.display = 'inline';
				document.getElementById('compatibility_passed_browser').style.display = 'inline';
			} else {
				document.getElementById('compatibility_IE4').style.display = 'inline';
				document.getElementById('compatibility_upgradeIE').style.display = 'inline';
			}
		} else if (is_fx) {
			document.getElementById('compatibility_Firefox').style.display = 'inline';
			document.getElementById('compatibility_passed_browser').style.display = 'inline';
		} else if (is_opera) {
			document.getElementById('compatibility_Opera').style.display = 'inline';
			document.getElementById('compatibility_passed_browser').style.display = 'inline';
		} else if (is_nav) {
			document.getElementById('compatibility_Navigator').style.display = 'inline';
			if (is_nav7up) {
				document.getElementById('compatibility_Navigator7').style.display = 'inline';
			} else {
				document.getElementById('compatibility_Navigator6').style.display = 'inline';
			}
			document.getElementById('compatibility_upgrade_browser').style.display = 'inline';
		} else if (is_aol) {
			document.getElementById('compatibility_AOL').style.display = 'inline';
			document.getElementById('compatibility_upgrade_browser').style.display = 'inline';
		} else {
			document.getElementById('compatibility_upgrade_browser').style.display = 'inline';
		}

//Now do the Operating System cells
		if (is_win31) {
			document.getElementById('compatibility_Win31').style.display = 'inline';
			document.getElementById('compatibility_upgrade_OS').style.display = 'inline';
		} else if (is_win95) {
			document.getElementById('compatibility_Win95').style.display = 'inline';
			document.getElementById('compatibility_upgrade_OS').style.display = 'inline';
		} else if (is_winme) {
			document.getElementById('compatibility_Winme').style.display = 'inline';
			document.getElementById('compatibility_suggested_upgrade_OS').style.display = 'inline';
		} else if (is_win2k) {
			document.getElementById('compatibility_Win2k').style.display = 'inline';
			document.getElementById('compatibility_passed_OS').style.display = 'inline';
		} else if (is_winxp) {
			document.getElementById('compatibility_Winxp').style.display = 'inline';
			document.getElementById('compatibility_passed_OS').style.display = 'inline';
		} else if (is_win98) {
			document.getElementById('compatibility_Win98').style.display = 'inline';
			document.getElementById('compatibility_suggested_upgrade_OS').style.display = 'inline';
		} else if (is_winnt) {
			document.getElementById('compatibility_Winnt').style.display = 'inline';
			document.getElementById('compatibility_passed_OS').style.display = 'inline';
		} else {
			document.getElementById('compatibility_cannotDetect_OS').style.display = 'inline';
			document.getElementById('compatibility_unknown').style.display = 'inline';
		}
//What if BROWSER is NOT Detected/known?  Probably need to set flag and test it, and if set add
//			document.getElementById('compatibility_cannotDetect_browser').style.display = 'inline';
	}
	
	if (is_safari) {
	        top.resizeBy(-1, -1);
	        top.resizeBy(1, 1);
	}
}
