/*************************************************************/
/*  Switcher JavaScript.  This script is used in conjunction */
/*  with JDK1.1+ Java Applets.  The script decides how to    */
/*  run the applet based on the type of browser:             */
/*  * If the browser is IE 3, the applet cannot be run.      */
/*  * If the browser is Netscape 3 - 4.04 on a PC, the       */
/*        script attemps to run the applet using the Java    */
/*        Plugin.                                            */
/*  * If the browser is Netscape 4.x on a Mac, the script    */
/*        attempts to run the applet using the MRJ Plugin    */
/*        for Netscape and MRJ.                              */
/*  * Otherwise, the script attemps to run the applet using  */
/*        a standard applet tage and the browser's built-in  */
/*        Java support.                                      */
/*                                                           */
/*  To make use of this script, you need to call it from the */
/*  appropriate index.html page.  View the other 1.1 applets */
/*  for the template.  You need to change five values inside */
/*  of the HTML file:                                        */
/*                                                           */
/*    AppClass - this specifies the name of the class        */
/*       var AppClass = "Conversions.class";                 */
/*    AppWidth - this specifies the applet's width           */
/*       var AppWidth = "400";                               */
/*    AppHeight - this specifies the applet's height         */
/*       var AppHeight = "145";                              */
/*    OtherTags - this specifies other values that would     */
/*       normally be included inside the <applet> tag, such  */
/*       as ARCHIVE.                                         */
/*       var OtherTags = "ARCHIVE=SomeArchive.jar";          */
/*    Params - this specifies applet parameters              */
/*       var Params = "<param name=paramname value=paramvalue>";*/
/*    EmbedStyleParams - this specifies the applet parameters*/
/*       again, but in a syntax that can be used in the      */
/*       EMBED tag.  These are the same parameters specified */
/*       in the Params variable.                             */
/*       var EmbedStyleParams = "paramename = \"paramvalue\"";*/
/*************************************************************/

    var browser = navigator.appName;
    var platform= navigator.platform;
    var version = parseFloat(navigator.appVersion);
    var agt = navigator.userAgent;

// var isXP = (agt.indexOf("NT 5") != -1);  old. just for XP+2K   
   var isXP = (agt.indexOf("Windows") != -1); // all PC's

    var printinstructions = "<br clear=\"left\"><CENTER>";
    // Absolute URL:  http://www.shodor.org/interactivate/howto.html#print
    printinstructions += "<a href=\"../../howto.html#print\" target=\"_new\">";
    printinstructions += "Printing Instructions</a></CENTER>";
    
   var isSafari = ((agt.indexOf("5") != -1) &&
                  (agt.indexOf("Mac") != -1) &&
                  (agt.indexOf("OS X") != -1) &&
                  (agt.indexOf("Safari") != -1));
             
    var useJars = isSafari || (platform != "MacPPC" && platform != "Mac68k")
                  || (agt.indexOf("OS X") != -1);
//    useJars=false;

//    document.write("agt = " + agt + "<br>");
//    document.write("platform = " + platform + "<br>");
//    document.write("version = " + version + "<br>");
//    document.write("browser = " + browser + "<br>");

    if (version < 4) {
        // platform will be defined incorrectly; let's just guess it's Win32.
        platform = "Win32";
    }

    if (useJars) { // Hopefully someday we can migrate exclusively to jar files.
    	
    	// NOTE: Codebase will always be "." here.  Ignore OtherTags variable.
    	// Ideally there should be a "Codebase" parameter.  Fix later if an issue.
    	
    	var dirName = AppClass.substring(0, AppClass.indexOf("/"));
    	var classFileName = AppClass.substring(AppClass.indexOf("/")+1, AppClass.indexOf(".")); 
	document.write("<applet code=\""+dirName+"."+classFileName+".class\" ");
        document.write("codebase=\".\" archive=\"../orgclasses.jar,"+dirName+".jar\" ");
	document.write("name=\""+classFileName+"\" id=\""+classFileName+"\" ");
        document.write("width=\""+AppWidth+"\" height=\""+AppHeight+"\" >");
        document.write("" + Params);
        document.write("Java is disabled in your browser.  Please enable it to run this applet.");
        document.write("</applet>");

       document.write(printinstructions);
      	if (isXP) {
            document.write("<P><BLOCKQUOTE><BLOCKQUOTE>If you experience "
                     + "difficulties running this applet in your browser, "
                                         + "please <a href=\"../java/java_xp.html\">"
                                         + "click here</a> for "
                     + "helpful advice.</BLOCKQUOTE></BLOCKQUOTE>");
	       }
	       if (isSafari) {
            document.write("<P><BLOCKQUOTE><BLOCKQUOTE>If you experience "
                     + "difficulties running this applet in your browser, "
                                         + "please <a href=\"../java/java_safari.html\">"
                                         + "click here</a> for "
                     + "helpful advice.</BLOCKQUOTE></BLOCKQUOTE>");
	       } 
  	
    }
    // Use Sun Java Plugin
    else if (browser == "Netscape" 
            && version < 4.05 
            && platform != "MacPPC"
            && platform != "Mac68k") {
        //document.write("using sun java plugin older mac embed tag");
        document.write("<EMBED "
                       + "TYPE=\"application/x-java-applet\" "
                       + "NAME=\"Java Applet\" "
                       + "PLUGINSPAGE=\"../java/win_plugin.html\""
                       + "BORDER=\"5\" " 
                       + "WIDTH=\""+AppWidth+"\" " 
                       + "HEIGHT=\""+AppHeight+"\" "
                       + "CODE=\""+AppClass+"\" "
                       + OtherTags + " "
                       + EmbedStyleParams + ">");
       document.write(printinstructions);
    }

    // Use Netscape Plugin for MRJ
    else if (browser == "Netscape" 
             && version >= 4 
             && version < 6 
             && (platform == "MacPPC" || platform == "Mac68k") && !isSafari) {
//        document.write("using mrj plugin");
        // Determine if they have the plugin installed.
        var vmInstalled = navigator.mimeTypes["application/x-java-vm"]
        if (vmInstalled) {
//            document.write("VM INSTALLED!!  Embed tag.");
            var appTag = "EMBED "
                           + "TYPE=\"application/x-java-vm\" "
                           + "NAME=\"Java Applet\" "
                           + "PLUGINSPAGE=\"../java/plugin.html\""
                           + "BORDER=\"5\" "
                           + "WIDTH=\""+AppWidth+"\" " 
                           + "HEIGHT=\""+AppHeight+"\" "
                           + "CODE=\""+AppClass+"\" "+OtherTags+ " "
                           + EmbedStyleParams;

    //           document.write("IS Mac/NN");
               document.write("<" + appTag + ">");
               document.write(printinstructions);
        }
        else {
            document.write("To correctly display this activity, <BR>you need "
                           + "to install some software.<br>");
            document.write("Click <A href=\"../java/plugin.html\">"
                           + "here</a> to learn how.<p>");
        }
    }
    // Regular tag -- the default
    else {
//        alert("using regular tag");
        document.write("<APPLET CODE=" + AppClass + " width=" + AppWidth
                       + " height=" + AppHeight + " " + OtherTags + ">");
        document.write("" + Params);
        document.write("Java is disabled in your browser.  Please enable "
                       + "it to run this applet.")
        document.write("</APPLET>")

        document.write(printinstructions);

        if (browser == "Microsoft Internet Explorer" 
                && version < 5 
                && (platform=="MacPPC" || platform=="Mac68k")) {
            document.write("<P><BLOCKQUOTE><BLOCKQUOTE>If you experience "
                     + "difficulties running this applet in your browser, "
					 + "please <a href=\"../java/ie4_mac.html\">"
					 + "click here</a> for "
                     + "helpful advice.</BLOCKQUOTE></BLOCKQUOTE>");
        }
  }















