/**
 * File: AppletTag.js
 *
 * Copyright 2004 by GraphOn Corporation
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of GraphOn Corporation ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with GraphOn.
 *
 * @author Jean-Claude Cote
 *     603.225.3525
 *     Jean-Claude@macadamian.com
 *     4/03/2001
 *
 * @version 1.00
 *
 * This is the JavaScript function that parses the Applet JS structure
 * It outputs the appropriate HTML tags for the applet.
 * 1) Singed applet on Windows and Linux:
 *    Applet tag with archives ggw.netscapesigned.jar & ggwres.jar
 *    and cabinets ggw.mssigned.cab & ggsres.cab
 * 2) Signed applet on Mac:
 *    Applet tag with archives ggw.sunsigned.jar & ggwres.jar
 */


/**
* Creates the <applet> tag using the parameters in the javalogonsigned.html page.
*/
function createAppletTag( theAppletTag, theParamList )
{
	var browser = new whatPlatform();
	
	this.appletTag    = "<APPLET\n";
	this.appletParams = "\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"
	}


	// Location of JAR files(s)
	
	if( theAppletTag["archive"] )
	{
		if( browser.mac )
		{
			this.appletTag  += " ARCHIVE=\"" + theAppletTag.archive + "\" \n"
		}
		else if( browser.sun && browser.ie )
		{
			this.appletTag  += " ARCHIVE=\"" + theAppletTag.archive + "\" \n"
		}
		else
		{ 
			if( browser.ns && theAppletTag["nos"] )
			{
				this.appletTag  += " ARCHIVE=\""+ theAppletTag.nos + "\" \n"
			}
			else
			{
				this.appletTag  += " ARCHIVE=\""+ theAppletTag.archive + "\" \n"
			}
		}
	}


	if( theAppletTag["width"] )
	{
		this.appletTag += " WIDTH=\"" + theAppletTag.width + "\"\n";
	}	
	
	if( theAppletTag["height"] )
	{
		this.appletTag += " HEIGHT=\"" + theAppletTag.height + "\"\n"
	}
	

	// Optional tags -----------------------------------------------

	if( theAppletTag["title"] )
	{
		this.appletTag += " TITLE=\"" + theAppletTag.title + "\"\n";
	}	

	
	if( theAppletTag["name"] )
	{
		this.appletTag  += " NAME=\"" + theAppletTag.name + "\"\n";
	}
	
	
	if( theAppletTag["alt"] )
	{
		this.appletTag += " ALT=\"" + theAppletTag.alt + "\"\n";
	}

		
	if( theAppletTag["align"] )
	{
		this.appletTag += " ALIGN=\"" + theAppletTag.align + "\"\n";
	}
	
	if( theAppletTag["vspace"] )
	{
		this.appletTag += " VSPACE=\"" + theAppletTag.vspace + "\"\n";
	}	
	
	if( theAppletTag["hspace"] )
	{
		this.appletTag += " HSPACE=\"" + theAppletTag.hspace + "\"\n";
	}	



	// Close the APPLET, or OBJECT tag

	this.appletTag += ">\n\n";

	if( theAppletTag.cabcount == 1 )
	{
		// 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";
		}
	}
	else if( theAppletTag.cabcount > 1 )
	{
		// Add the "CABINETS" parameter is we've been passed cab files

		if( browser.msie && theAppletTag["cab"] )
		{
			this.appletParams += "<PARAM NAME=\"CABINETS\" 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";
		}
	}

	
	// Add the balancing APPLET, EMBED, or OBJECT tag
	
	this.appletParams += "\n</APPLET>\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 8.6 and 9 MSIE 5.1 or better, use <APPLET> tag.
*    - Windows Netscape 7.1 or better, use <APPLET> tag.
*    - Windows MSIE v6.0 or better, use <APPLET> tag, if there is a CAB.
*
*/
function printHTML( jreTag, browser )
{
	if( browser.mac && browser.ns4up )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );
			alert( jreTag.appletParams );
		}
	}
	else if( browser.mac && browser.msie4up )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );
			alert( jreTag.appletParams );
		}
	}
	else if( browser.win && browser.ns4up )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );
			alert( jreTag.appletParams );
		}
				
	}
	else if( browser.win && browser.msie4up )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );			
			alert( jreTag.appletParams );
		}
	}
	else if( browser.linux )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );			
			alert( jreTag.appletParams );
		}
	}
	else if( browser.sun )
	{
		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert(jreTag.appletTag );			
			alert(jreTag.appletParams );
		}
	}
	else
	{
		document.write("<CENTER>\n");

		document.write("GGXP is not supported on this platform.\n");

		document.write("</CENTER>\n");

		reportPlatform();

		document.write( jreTag.appletTag );			
		document.write( jreTag.appletParams );
		if( debug )
		{
			alert( jreTag.appletTag );			
			alert( jreTag.appletParams );
		}

	}

	document.close();
}


/**
* Print out debugging information.
*/
function reportPlatform()
{	
	var browser = new whatPlatform();

	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("            NS >=v6: " + browser.ns6up     + "\n");
	document.write("                FF3: " + browser.ff3       + "\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("              Linux: " + browser.linux     + "\n");
	document.write("                OS2: " + browser.os2       + "\n");
	document.write("         MRJ Plugin: " + browser.mrjPlugin + "\n");
	document.write("</PRE>\n");
 	document.close();
}    
