// This is the JavaScript function that parses the Applet JS structure
//
//  http://java.sun.com/products/plugin/1.1.2/docs/tags.html
//


function createAppletTag (theAppletTag, theParamList) {

	var browser = new whatPlatform();
	
	this.appletTag    = "<APPLET\n";
	this.appletParams = "\n";
	
	this.embedTag     = "<EMBED\n TYPE=\"application/x-java-applet\"\n PLUGINSPAGE=\"http://Informagen.com/Applets/Plugins/index.html\"\n";

	this.objectTag    = "<OBJECT\n CLASSID=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"\n CODEBASE=\"http://java.sun.com/products/plugin/1.1/jinstall-11-win32.cab#Version=1,1,0,0\"\n";
	this.objectParams   = "<PARAM NAME=\"JAVA_TYPE\" VALUE=\"application/x-java-applet;version=1.1\">\n";	
	
	
	// Parse the applet tag parameters and construct the tag, "<XXXX ... >"
	
	// Class containing decended from "java.awt.Applet"
	
	if (theAppletTag["code"]) {
		this.appletTag  += " CODE=\""                              + theAppletTag.code + "\" \n"
		this.embedTag   += " CODE=\""                              + theAppletTag.code + "\" \n"
		this.objectParams += "<PARAM NAME=\"JAVA_CODE\" VALUE =\"" + theAppletTag.code + "\">\n"
	}


	if (theAppletTag["codebase"]) {
		this.appletTag  += " CODEBASE=\""                              + theAppletTag.codebase + "\" \n";
		this.embedTag   += " CODEBASE=\""                              + theAppletTag.codebase + "\" \n";
		this.objectParams += "<PARAM NAME=\"JAVA_CODEBASE\" VALUE =\"" + theAppletTag.codebase + "\">\n";
	}




	// Location of JAR files(s)
	
	if ( theAppletTag["archive"]) {
	
		if (browser.ns && theAppletTag["nos"])
			this.appletTag  += " ARCHIVE=\""+ theAppletTag.nos + "\" \n"
		else
			this.appletTag  += " ARCHIVE=\""+ theAppletTag.archive + "\" \n"
			
		this.embedTag   += " ARCHIVE=\"" + theAppletTag.archive + "\" \n"
		this.objectParams += "<PARAM NAME=\"JAVA_ARCHIVE\" VALUE=\"" + theAppletTag.archive + "\">\n";
	}


	if (theAppletTag["width"]) {
		this.appletTag += " WIDTH=\"" + theAppletTag.width + "\"\n";
		this.embedTag  += " WIDTH=\"" + theAppletTag.width + "\"\n";
		this.objectTag += " WIDTH=\"" + theAppletTag.width + "\"\n";
	}	
	
	if (theAppletTag["height"]) {
		this.appletTag += " HEIGHT=\"" + theAppletTag.height + "\"\n"
		this.embedTag  += " HEIGHT=\"" + theAppletTag.height + "\"\n"
		this.objectTag += " HEIGHT=\"" + theAppletTag.height + "\"\n"
	}
	

	// Optional tags -----------------------------------------------

	if ( theAppletTag["title"] ) {
		this.appletTag += " TITLE=\"" + theAppletTag.title + "\"\n";
		this.embedTag  += " TITLE=\"" + theAppletTag.title + "\"\n";
	}	

	
	if (theAppletTag["name"]) {
		this.appletTag  += " NAME=\"" + theAppletTag.name + "\"\n";
		this.embedTag   += " NAME=\"" + theAppletTag.name + "\"\n";
	}
	
	
	if ( theAppletTag["alt"]) {
		this.appletTag += " ALT=\"" + theAppletTag.alt + "\"\n";
		this.embedTag  += " ALT=\"" + theAppletTag.alt + "\"\n";
	}

		
	if ( theAppletTag["align"]){
		this.appletTag += " ALIGN=\"" + theAppletTag.align + "\"\n";
		this.embedTag  += " ALIGN=\"" + theAppletTag.align + "\"\n";
	}
	
	if ( theAppletTag["vspace"] ) {
		this.appletTag += " VSPACE=\"" + theAppletTag.vspace + "\"\n";
		this.embedTag  += " VSPACE=\"" + theAppletTag.vspace + "\"\n";
	}	
	
	if ( theAppletTag["hspace"] ) {
		this.appletTag += " HSPACE=\"" + theAppletTag.hspace + "\"\n";
		this.embedTag  += " HSPACE=\"" + theAppletTag.hspace + "\"\n";
	}	



	// Close the APPLET, or OBJECT tag

	this.appletTag += ">\n\n";
	this.objectTag += ">\n\n";


	// Add the "CABBASE" parameter is we've been passed a cab file

	if (browser.msie && theAppletTag["cab"])
		this.appletParams += "<PARAM NAME=\"CABBASE\" VALUE=\"" + theAppletTag["cab"] + "\">\n";

	

	// Parse out the applet data parameters

	
	if (theParamList != null) {			
		for(i=0; i<theParamList.length; i=i+2) {
			n = theParamList[i];
			v = theParamList[i+1]
			this.appletParams += "<PARAM NAME=\"" + n + "\" VALUE=\"" + v + "\">\n";
			this.embedTag     += n + "=\"" + v + "\"\n";
			this.objectParams += "<PARAM NAME=\"" + n + "\" VALUE=\"" + v + "\">\n";
		}
	}


	

	
	// Add the balancing APPLET, EMBED, or OBJECT tag
	

	this.appletParams += "\n</APPLET>\n";
	
	this.embedTag += ">\n";
	this.embedTag += "</EMBED>\n";
	
	this.objectParams += "</OBJECT>\n";

	
	
	// Write out the involking HTML to the document

	printHTML(this, browser);

}


//------------------------------------------------------------------------------------------
/*
**  Write to the appropriate applet tag and parameters to the HTML stream.
**
**  Handle the following conditions
**
**    - Macintosh Netscape 4 or better with the MRJ Plugin, use <EMBED> tag.
**    - Macintosh MSIE 4 or better, use <APPLET> tag.
**    - Windows Netscape 4 or better, use <APPLET> tag.
**    - Windows MSIE v4 or better, use <OBJECT> tag, if no CAB.
**    - Windows MSIE v4 or better, use <APPLET> tag, if there is a CAB.
**
**    - Tell Macintosh Netscape 4 or better users to install the MRJ Plugin.
**
**    - Upgrade to Netscape 4 or better (Window, Macintosh or UNIX).
**    - Upgrade to Internet Explorer 4 or better (Window or Macintosh).
**
**    - Report that applets are not support for all other platforms.
**
*/

function printHTML(jreTag, browser) {


	if ( browser.macSafari ) { 
	
		document.write(jreTag.appletTag);			
		document.write(jreTag.appletParams);
	   
	} else if ( browser.mac && browser.ns4up && browser.mrjPlugin ) {    
	
		document.write(jreTag.embedTag);	
					
	} else if ( browser.mac && browser.msie4up ) {
	
		document.write(jreTag.appletTag);			
		document.write(jreTag.appletParams);
						
	} else if ( browser.win && browser.ns4up ) {
	
		document.write(jreTag.appletTag);			
		document.write(jreTag.appletParams);
				
	} else if ( browser.win && browser.msie4up ) {
	
		document.write(jreTag.appletTag);			
		document.write(jreTag.appletParams);
		
	} else {
	
		document.write("<CENTER>\n");
				
		
		if ( browser.mac && browser.ns4up && !browser.mrjPlugin ) {
		
			document.write("Please download and install the MRJ Java Plugin. ");
			document.write("<A HREF=\"http://informagen.com/Applets/Plugins/index.html\">Click here.</A>");
			
		} else if (browser.ns && !browser.ns4up) {
		
			document.write("Please upgrade to the latest version of Netscape. ");
			document.write("<A HREF=\"http://home.netscape.com\">Click here.</A>");
			
		} else if (browser.msie && !browser.msie4up) {
		
			document.write("Please upgrade to the latest version of Internet Explorer. ");
			
			if ( browser.mac )
				document.write("<A HREF=\"http://www.microsoft.com/mac/ie/\">Click here.</A>");
			
			if ( browser.win )
				document.write("<A HREF=\"http://www.microsoft.com/windows/IE/\">Click here.</A>");
			
		} else {
		
			document.write(jreTag.appletTag);			
			document.write(jreTag.appletParams);
		
			//document.write("JDK 1.1 applets are not supported on this platform.\n");
		}
		
		document.write("</CENTER>\n");
	}
	
	document.close();
}


//------------------------------------------------------------------------------------------



function whatPlatform() {

   // Browser name string, major version, and agent string

	var name = navigator.appName;
	var ver = parseInt(navigator.appVersion);
	var agent = navigator.userAgent;
  

	// Microsoft Internet Explorer and version

	this.msie     = (agent.indexOf("MSIE") != -1);
	this.msie4up  = (this.msie && (ver >= 4));  


	// Netscape Navigator and version
	
	this.ns = (name.indexOf("Netscape") != -1);
	this.ns4up = (this.ns && (ver >= 4));


	// Operating system, test both Netscape agent or MSIE agent strings.

	this.win95 = ((agent.indexOf("Win95")!=-1) || (agent.indexOf("Windows 95")!=-1));
	this.win98 = ((agent.indexOf("Win98")!=-1) || (agent.indexOf("Windows 98")!=-1));
	this.winnt = ((agent.indexOf("WinNT")!=-1) || (agent.indexOf("Windows NT")!=-1));
	
	this.win = this.win95 || this.win98 || this.winnt;
		
	this.mac   = (agent.indexOf("Mac") != -1);
	this.macSafari = (agent.indexOf("Safari") != -1);
	this.sun   = (agent.indexOf("SunOS") != -1);


	// Look for the MRJ Plugin in Macintosh Netscape
	
	this.mrjPlugin = false;
	
	if ( this.mac && this.ns4up )
		this.mrjPlugin = navigator.plugins["MRJ Java Plugin"] ? true : false;
	
}

//------------------------------------------------------------------------------------------


function reportPlatform() {	
	
	var browser = new whatPlatform();

	// Useful in debugging and development
	
	document.write("<PRE>\n");
	document.write("JavaScript reports that you are using:\n");
	document.write("----------------------------------------------\n");
	document.write("     appName: " + navigator.appName + "\n");
	document.write("  appVersion: " + navigator.appVersion + "\n");
	document.write("   userAgent: " + navigator.userAgent + "\n");
	document.write("  --------------------------------------------\n");
	document.write("  Internet Explorer: " + browser.msie      + "\n");
	document.write("            IE >=v4: " + browser.msie4up   + "\n");
	document.write(" Netscape Navigator: " + browser.ns        + "\n");
	document.write("            NS >=v4: " + browser.ns4up     + "\n");
	document.write("            Windows: " + browser.win       + "\n");
	document.write("         Windows 95: " + browser.win95     + "\n");
	document.write("         Windows 98: " + browser.win98     + "\n");
	document.write("         Windows NT: " + browser.winnt     + "\n");
	document.write("          Macintosh: " + browser.mac       + "\n");
	document.write("              SunOS: " + browser.sun       + "\n");
	document.write("         MRJ Plugin: " + browser.mrjPlugin + "\n");
	document.write("</PRE>\n");
 	document.close();
   
                    
}    
