// globals for All Pages
// browser
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isIE5 = (navigator.appVersion.indexOf("5.") != -1) ? true : false;
var isIE6 = (navigator.appVersion.indexOf("6.") != -1) ? true : false;
var isNS  = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
var isMoz = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

// platform 
var isWin = (navigator.appVersion.indexOf("Win") != -1) ? true : false;
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;

// Flash boolean
var isFlashinstalled = false;
// -->

// Write out VB Functions
document.write('<SCR' + 'IPT LANGUAGE="VBScript"\>   \n');


// detect presence of ActiveX controls
document.write(' on error resume next  \n');
document.write(' Dim  pdf405 \n');
document.write(' Dim  pdf50  \n');
document.write(' Dim  PDFViewer \n');

document.write(' MediaPlayer = IsObject(CreateObject("MediaPlayer.MediaPlayer.1"))    \n'); //acrobat 5.0 for MacOS9
document.write(' \'MsgBox MediaPlayer \n');

document.write(' Function detectFlashPC(lVersion)  \n');
document.write('   on error resume next  \n');
document.write('   Dim i, obj : obj = null \n ');
document.write('   flashVersion = 4                \n ');
document.write('    For i = lVersion To 4 Step - 1  \n');
document.write('	  Set obj = CreateObject("ShockwaveFlash.ShockwaveFlash." & i )   \n');
document.write('      If IsObject(obj) Then \n');
document.write('			 flashVersion = i \n');
document.write('			 Set obj = nothing \n');
document.write('			 Exit For \n');
document.write('	  End IF		 \n');	
document.write('    Next \n');
document.write('    detectFlashPC = flashVersion \n ');
document.write(' End Function ');
document.write('</SCR' + 'IPT\>     \n'); // break up end tag so it doesn't end our script

// -------------------------   Start  Detection function  -------------------------------

function detectFlash( lVersionToDetect, src, h, w, objectID, sRedirectPage ){
	// Things we are looking for
	var flashVersion = 1;
	var bRedirect = false;
		
	// for redirection
	if( ( sRedirectPage.length > 0 ) && ( sRedirectPage != 'undefined') ){ bRedirect = true;}
		
	flashVersion = getFlashVersion( lVersionToDetect );
		
	if(flashVersion > 3){
		isFlashinstalled = true;
	}
											
	// now we should have the version to detect for
	// if a mac with less than IE 5, can't do anything, user disgretion
	if((isIE && !isIE5) && isMac){
		var go = confirm(" You have a Mac with IE 4.x.  Do you have the flash plugin? Click Ok to continue to Flash Site, or cancel to get html version.");

		// download page
		if(!go)
			if(bRedirect)
				location.replace (sRedirectPage);
				
	}
	
	// now check everything else:		
	if ((!isFlashinstalled ) || (flashVersion  < lVersionToDetect)){
		var bgetFlash = confirm("Flash "+ lVersionToDetect + " or greater was not detected on your machine.  Please click Ok to download, or cancel to get html version. ");
		if (bgetFlash){
			getBrowserPlugin('flashplayer');	
		} else {
			// goto HTML Version, and pop up something on them
			getBrowserPlugin('flashplayer');
			if(bRedirect) 
				location.replace (sRedirectPage); 
		}
	}
	
	
	// all checks went through, render Flash Object
	if(src.length > 0 && src != 'undefined')
		renderFlashObject(src, h, w, objectID);
		
} // end of flash detectiion function

// ----------------------------------------------	//

function detectFlashNetscape(){
	var lVersion;
	if (navigator.plugins["Shockwave Flash 2.0"] 	// yes>> then is Flash 2 
		|| navigator.plugins["Shockwave Flash"]){		// or flash 3+ installed?
			isFlashinstalled = true;
			// set convenient references to flash 2 and the plugin description
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			// a flash plugin-description looks like this: Shockwave Flash 4.0 r5
			// so we can get the major version by grabbing the character before the period
			// note that we don't bother with minor version detection. do that in your movie with $version
			lVersion = parseInt(flashDescription.substr(flashDescription.indexOf(".")-2, 2));


	}
	return lVersion;
} // end fo function

// ----------------------------------------------	//	

function getFlashVersion(lVersion){
	// Detect Flash Version for NetScape
	if ((isMoz || isNS) || (isMac && (isIE5 || isIE6))){// does navigator.plugins exist?
		return detectFlashNetscape();
	}
	// end of detecting flash for Netscrape
	
	// detection script for IE/Windows			
	if(((isIE) || (isIE5)) && isWin && !isNS ){ // don't write vbscript tags on anything but ie win
		return detectFlashPC(lVersion);
	}
} // end of function

// ----------------------------------------------	//	

function renderFlashObject(src, h, w, objectid){
	// function will render Flash Object
	document.open();
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '); 
	document.write('	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" \n');
	document.write('	width="'+ w +'" height="'+ h + '" \n');
	document.write('	id="'+ objectid +'" name="'+ objectid +'">     \n'); // end of object Tag
	document.write('	<param name="quality" value="high">\n');
	document.write('	<param name="movie" value="'+ src + '">\n');
	document.write('	<param name="menu" value="false">\n');
	document.write('	<EMBED src="'+ src +'"       \n');
	document.write('		quality=high Menu=false  \n');
	document.write('		width="'+ w +'" height="'+ h +'"\n');
	document.write('		type="application/x-shockwave-flash" \n');
	document.write('		PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">\n');
	document.write('</embed></object>\n');
	document.close();
}

function getOS(){
	var agt=navigator.userAgent.toLowerCase();
	var os = "";
	var win = (agt.indexOf("win")!=-1);
	// windows 95 OS
	this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
	if (this.win95) os="Windows 95";
	// windows 98 OS
	this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	if (this.win98) os="Windows 98";
	// windows NT
	this.winNT = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	if (this.winNT) os="Windows NT/XP";
	// windows 2000
	this.win2000 = ((agt.indexOf("windows nt 5.0")!=-1));
	if (this.win2000) os="Windows 2000";

	this.win32 = ( this.win95 || this.winnt || this.win98 || this.win2000 ||
                   ((this.major >= 4) && (navigator.platform == "Win32")) ||
                   (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1) );

	// macintosh
	this.mac = ((agt.indexOf("mac")!=-1)||(agt.indexOf("Mac")!=-1));
	//alert(this.mac);
	if (this.mac) os="Macintosh";

	return os;
}

// --------------------------------------------------------------- //

function checkCookies(){
	if (document.cookie != null){
		document.cookie = "name=value";  // cookies enabled?
		if (document.cookie == "") {
			return "Please turn on cookies.";
		} else { 
			return "Cookies are accepted.";
		}
	}
} // end of cookie checker

// --------------------------------------------------------------- //

function checkAcrobat( __os ){
//	alert( __os );
	if( acrobat.installed )
		return "Version "+ acrobat.version + "";
	else
		return "Unknown.";	
}


// --------------------------------------------------------------- //

function checkMediaPlugin(sOs){
	var bPlayerInstalled = false;

	if (sOs.indexOf("Windows") != -1) {
		if(navigator.plugins.length > 0) {
			for (var i=0; i< navigator.plugins.length; i++){
				if (navigator.plugins[i].name.indexOf("Windows Media") != -1){
					bPlayerInstalled = true;
				}
			}
		} else {	
		  // need to get this going	with IE PC
		  bPlayerInstalled = MediaPlayer;
		}
		
		
		if(bPlayerInstalled == true){ //Detecting Real Basic 8/RealOne in IE5+ in Windows NT, 98, 2000
			return "Media Player installed.";
		} else {
			return "Not installed or cannot detect";
		}
	}//end of Windows check
	
	else if (sOs.indexOf("Macintosh") != -1) {
		if(isIE) {//IN Mac IE 5 + can't detect Real using Active X Or Javascript
			return "Can't detect on Mac with IE 4 and 5";
		}
		else if(navigator.plugins.length != null) {
			for (var i=0; i< navigator.plugins.length; i++){
				if( navigator.plugins[i].name.indexOf("Windows Media") != -1 )
					return "Media Player installed.";
			}	
			
			// send back not installed
			return "Not installed or cannot detect";			
		}
	}// end of Macintosh block
}

		
// -------------------------   End  Detection  -------------------------------
  

