// JavaScript Document: gr_detect.js
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 	Author: Garth Rowe
//    Date: May 2004
// Purpose: Determines plugins running on client browser 
//   Notes: Please feel free to reuse this code
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//~~~~~~~~~~ Declare variables ~~~~~~~~~~
var isIE3Mac = false;
var pluginCount = 0
var j;
var i;
var flash_ver;
var pdf_ver;
var got_flash = false;
var got_acrobat = false;
var us_osx = false;
var p_block = false;
var scr_width;
var scr_height;
//~~~~~~~~~~~~~~~~~~    ~~~~~~~~~~~~~~~~~~


//~~~~~~~~~~ Do this ~~~~~~~~~~~~~~~~~~~~~

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1)
    && (parseInt(navigator.appVersion)==3))
    isIE3Mac = true;
	
if(!isIE3Mac){
	
	if( navigator.cookieEnabled )
		pluginCount++;
	if( navigator.javaEnabled() )
		pluginCount++	
		
	//look for IE specific plugins on Windows platform			
	if( navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Windows")!=-1)
	{				
		for(i = 8; i > 0; i--) 
		{
			pdf_ver = 0;
			try 
			{
				pdf_ver = i;
				plugin_pdf = new ActiveXObject('Pdf.PdfCtrl.' + pdf_ver);
				piVersion = pdf_ver;
				if ( pdf_ver > 0 ) 
				{
					pluginCount++;
					got_acrobat = true;
					//alert("found pdf version "+ pdf_ver);
					break;
				}								
			}
			catch(e){}
		}//end for
		
		for(i = 8; i > 0; i--) 
		{
			pdf_ver = 0;
			try 
			{
				pdf_ver = i;
				plugin_pdf = new ActiveXObject('AcroPDF.PDF.' + pdf_ver);
				piVersion = pdf_ver;
			
				if ( pdf_ver > 0 ) 
				{
					pluginCount++;
					got_acrobat = true;
					//alert("found pdf version "+ pdf_ver);
					break;
				}								
			}
			catch(e){}
		}//end for
		
		for(i = 8; i > 0; i--) 
		{
			flash_ver = 0;
			try 
			{
				flash_ver = i;
				plugin_sw = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + flash_ver);
												
				if ( flash_ver > 0 ) 
				{
					pluginCount++;
					got_flash = true;
					//alert("found flash version " + flash_ver);
					break;
				}								
			}
			catch(e){}
		}//end for		
	}//end if IE									
	else{ //check all browsers with valid plugin array
		if(navigator.plugins && navigator.plugins.length > 0){		
			for (i = 0; i < navigator.plugins.length; i++) {
				if (navigator.plugins[i].name== "Shockwave Flash"){
					got_flash = true
					pluginCount++
					//alert("found flash on the system")	
					break
				}						
			}//end for
		}//end if
						
		//navigator.userAgent.indexOf("Mac OS X")!=-1 || navigator.userAgent.indexOf("PowerPC")==-1		
		//navigator.platform.indexOf("MacPPC") !=-1
		
		if( navigator.userAgent.indexOf("Mac OS X")!=-1 ){
			got_acrobat = true
			pluginCount++
			//OS X has a built-in pdf reader not detected by this script; add one to compensate
			//alert("You are using OS X")
			us_osx = true
		}
		else{
			for (i = 0; i < navigator.plugins.length; i++) {
				if (navigator.plugins[i].name== "Adobe Acrobat" || navigator.plugins[i].filename == "PDFViewer"){
					got_acrobat = true	
					pluginCount++
					//alert("found acrobat on the system")	
					break
				}		
			}//end for 								
		}
	}//end looking for netscape / mozilla plugins	
	
	if (screen){
		scr_width = screen.width
		scr_height = screen.height				
	}
}	
//~~~~~~~~~~ Functions ~~~~~~~~~~~~~~~~~~
function popBlocked( )
{
	if(!isIE3Mac){
		win = window.open("", "newWin", "location=yes, top=360, right=360, height=5, width=5" )
		if (win == null)		
			p_block = true			
		else{
			pluginCount++
			win.close()
		}
	}
}
