var os=navigator.platform;
var browName=new String(navigator.appName);
var browVer= new String(navigator.userAgent);
var notXPInstall=0;
var NSVer=new String();
var ActiveX="true";


function CheckStatus(url,status){
if (status==0){
	rvPos=browVer.lastIndexOf("rv:");
	rvStr=browVer.substring(rvPos+3,rvPos+8);
	rvInt=rvStr.split(".");
	rvMaj=parseInt(rvInt[0]);
	if (rvMaj>=1){
	window.location.reload();}
	else{
	navigator.plugins.refresh();
	window.location.reload();}	
//document.write("You must restart your browser for the plug-in to activate.");
		//document.close();}
	}	
}

//Check that OS is Windows
if (os=="Win32"){
//Check that Browser is not MSIE or Opera
var posIE=browVer.lastIndexOf("MSIE");
var posOpera=browVer.lastIndexOf("Opera");
if ((posIE==-1)&&(posOpera==-1)){
	//Browser is Netscape or Mozilla or Gecko
	ActiveX="false";
	var posNet=browVer.lastIndexOf("Netscape");
	var netVer;
	if (posNet!=-1){
		//Browser is NETSCAPE check Netscape version
		netVer=browVer.substring(posNet);
		var checkVer=netVer.split("/");
		if (parseFloat(checkVer[1])==6.2){
			notXPInstall=0;
			NSVer="6.2";
		}
		else if (parseFloat(checkVer[1])==6.1 || parseFloat(checkVer[1])==6.0){
			notXPInstall=0;
			NSVer="6.1";
		}
		else if (parseFloat(checkVer[1])<6 && parseFloat(checkVer[1])>=4){
			notXPInstall=1;
			NSVer="4";
		}
		else if (parseFloat(checkVer[1])<4){
			notXPInstall=1;
			NSVer="3";
		}
		else {
			notXPInstall=0;
			NSVer="7";
		}
	}//posNet!=-1
	else {
	//The word "Netscape" did not appear, check the Mozilla version and the revision
		var chkMoz=browVer.split(" ");
		var mozVer=chkMoz[0].split("/");
		var mozFL=parseFloat(mozVer[1]);
		if (mozFL<5.0){
		//Netscape 4
			notXPInstall=1;
			NSVer="4";
			}
		else{
		//check the mozilla revision number for compatibility
			rvPos=browVer.lastIndexOf("rv:");
			rvStr=browVer.substring(rvPos+3,rvPos+8);
			rvInt=rvStr.split(".");
			var rvMaj=parseInt(rvInt[0]);
			var rvMid=parseInt(rvInt[1]);
			var rvMin=parseInt(rvInt[2]);
			//rv:0.9.4 is the XPInstall cut-off==Netscape 6.2
			if(rvMaj<1){
				if(rvMid<9){
					notXPInstall=1;
					NSVer="4";
				}
				else{
				//check the minor version rvMid=9
				if(rvMin<4){
					NSVer="6.1";
					notXPInstall=1;
					}
				else{
					NSVer="6.2";
					notXPInstall=0;
					}
				}// else rvMid
			}//if rvMaj
			else{
				NSVer="7";
				notXPInstall=0;
				}
		}//else is Moz>=5.0
	}//else is mozilla
    }//posIE
}//win32

function InsertEmfViewer()
{
//Check that OS is Windows
if (os=="Win32"){
if ((posIE==-1)&&(posOpera==-1)){
	//Browser is Netscape or Mozilla or Gecko
if(notXPInstall==0){
	//Use the XPInstall method to check versions and install
	var isOK=(navigator.mimeTypes["application/x-emf"]!=null);
	var plidStr="/EmfViewer.com/NPEmfView";
	var compInt=-1;
	compInt=InstallTrigger.compareVersion(plidStr,"1.0.0.0");
	var xpiLoc=new String();
	xpiLoc=PagePath+"NPEmfView.xpi";
	if ((isOK == false)||(compInt<0)){
		xpi={'EMF file viewer (Win32) for Mozilla/Netscape':xpiLoc};
		InstallTrigger.install(xpi,CheckStatus);
		}
	}
else{
	//Must download manually
	if (NSVer==4){
		var isOK=(navigator.mimeTypes["application/x-emf"].enabledPlugin!=null);
		if (isOK==false){
			var dllLoc=new String();
			dllLoc="'"+PagePath+"NPEmfView.zip'";
			ManualDownload=window.open("","ManualDownload","top=10,left=10,width=400,height=500,scrollbars=no,toolbar=no,status=no,location=no,directories=no","true");
			ManualDownload.document.write("To properly view this web page, the proper plugin needs installed.");
			ManualDownload.document.write("Your browser does not support the latest auto-download methods.");
			ManualDownload.document.write("Follow the directions below to download manually.");
			ManualDownload.document.write("<br><br>");
			ManualDownload.document.write("Step 1: Right click on the hyperlink below");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 2: Select 'Save Link As' from the menu");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 3: Navigate to the 'Plugins' sub-directory of your browser");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("IE: C:\\ProgramFiles\\Netscape\\Plugins");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 4: Click Save");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 5: Open the downloaded .zip file with WinZip or some other extractor.");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 6: Extract the DLL to the Plugins sub-directory of your browser");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Step 7: Close all windows, restart your browser");
			ManualDownload.document.write("<br><br>");
			ManualDownload.document.write("<a href="+dllLoc+">Right Click to download.</a><br><br>");
			ManualDownload.document.write("Sorry about the inconvienience, but this browser makes it difficult.");
			ManualDownload.document.write("<br>");
			ManualDownload.document.write("Another option would be to upgrade your browser to the latest version");
			ManualDownload.document.close();
		}//isOk is false
	}//is NSVer=4
}//notXPInstall
	

}//not IE or Opera
/**************************************************************
**** In this area, I will write out the Object Tags, taking into
**** account the differing browsers. Sorry, but the only way I
**** have figured out to do this is via Script
***************************************************************/
// Write object tags.
if (ActiveX=="true"){
	document.write('<OBJECT classId="clsid:B6399615-DC13-4391-A2B9-B55B198A0EB3"');
	document.write('codebase="'+PagePath+'EmfViewer.ocx#Version=1,0,0,0"');
	document.write('type="application/x-emf" name="EmfViewer" id="EmfViewer"');
	document.write('width="'+Winwidth+'" height="'+Winheight+'">');
//Insert the PARAM tags
	document.write('<PARAM name="Winwidth" value="'+Winwidth+'">');
	document.write('<PARAM name="Winheight" value="'+Winheight+'">');
	document.write('<PARAM name="FilePath" value="'+FilePath+'">');
	document.write('<PARAM name="PagePath" value="'+PagePath+'">');
//Close the object tag, body, and document
	document.write('</OBJECT>');
}
else{
// It is a netscape/mozilla browser VERY UGLY code here
// Use a case statement to write different tags depending on the
// browser in use.
	switch (NSVer){
	case "6.1":
		document.write("<OBJECT ");
		document.write('type="application/x-emf" name="EmfViewer" id="EmfViewer"');
		document.write('width="'+Winwidth+'" height="'+Winheight+'"');
	//6.1 does not handle PARAM tags properly. Try embedding in the OBJECT tag.
		document.write(' Winwidth="'+Winwidth+'"');
		document.write(' Winheight="'+Winheight+'"');
		document.write(' FilePath="'+FilePath+'"');
		document.write(' PagePath="'+PagePath+'">');
	//Close the object tag, body, and document
		document.write('</OBJECT>');
		break;
	
	case "6.2":
	// 6.2 does not handle OBJECT tags properly. Does not "get" the name
	// and does not allow dynamic sizing. Embed tag fixes this.
		document.write("<EMBED ");
		document.write('type="application/x-emf" name="EmfViewer" id="EmfViewer"');
		document.write('width="'+Winwidth+'" height="'+Winheight+'"');
		document.write(' Winwidth="'+Winwidth+'"');
		document.write(' Winheight="'+Winheight+'"');
		document.write(' FilePath="'+FilePath+'"');
		document.write(' PagePath="'+PagePath+'">');
	//Close the object tag, body, and document
		document.write('</EMBED>');
		break;
	case "3":
	// Version 3 browser don't support any of the methods of the EMFVIEWER. Just let the
	// user know to upgrade.
		document.write("Your browser does not support this plug-in. We recommend upgrading to a modern browser.");
		break;
	default:
		document.write("<OBJECT ");
		document.write('type="application/x-emf" name="EmfViewer" id="EmfViewer"');
		document.write('width="'+Winwidth+'" height="'+Winheight+'">');
	//Insert the PARAM tags
		document.write('<PARAM name="Winwidth" value="'+Winwidth+'">');
		document.write('<PARAM name="Winheight" value="'+Winheight+'">');
		document.write('<PARAM name="FilePath" value="'+FilePath+'">');
		document.write('<PARAM name="PagePath" value="'+PagePath+'">');
	//Close the object tag, body, and document
		document.write('</OBJECT>');
	
	}//End switch
}// else ActiveX==false
}//Is Win32


}
