/*
 * Copyright (c)  2008 Sun Microsystems, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Sun Microsystems nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * deployJava.js
 *
 * This file is part of the Deployment Toolkit.  It provides functions for web
 * pages to detect the presence of a JRE, install the latest JRE, and easily run
 * applets or Web Start programs.  Usage guide may be found at http://<TBD>/.
 * 
 * The "live" copy of this file may be found at 
 * http://java.com/js/deployJava.js.  
 * You are encouraged to link directly to the live copy of the file.
 *
 * @version @(#)deployJava.js	1.15 09/02/05
 */

var deployJava = {
    debug: false,

    myInterval: null,
    preInstallJREList: null,
    returnPage: null,
    brand: null,
    locale: null,
    installType: null,
    
    EAInstallEnabled: false,
    EarlyAccessURL: null,
    
    // GetJava page
    getJavaURL: 'http://java.sun.com/webapps/getjava/BrowserRedirect?host=java.com',
    
    // Apple redirect page
    appleRedirectPage: 'http://www.apple.com/support/downloads/',

    // mime-type of the DeployToolkit plugin object
    oldMimeType: 'application/npruntime-scriptable-plugin;DeploymentToolkit',
    mimeType: 'application/java-deployment-toolkit',

    // location of the Java Web Start launch button graphic
    launchButtonPNG: 'http://java.sun.com/products/jfc/tsc/articles/swing2d/webstart.png',


    /**
     * Returns an array of currently-installed JRE version strings.  
     * Version strings are of the form #.#[.#[_#]], with the function returning
     * as much version information as it can determine, from just family 
     * versions ("1.4.2", "1.5") through the full version ("1.5.0_06").
     *
     * Detection is done on a best-effort basis.  Under some circumstances 
     * only the highest installed JRE version will be detected, and 
     * JREs older than 1.4.2 will not always be detected.
     */
    getJREs: function() {
        var list = new Array();
        if (deployJava.isPluginInstalled()) {
            var plugin =  deployJava.getPlugin();
            for (var i = 0; i < plugin.jvms.getLength(); i++) {
                list[i] = plugin.jvms.get(i).version;
            }
        } else {
            var browser = deployJava.getBrowser();
        
            if (browser == 'MSIE') {
                if (deployJava.testUsingActiveX('1.8.0')) {
                    list[0] = '1.8.0';
                } else if (deployJava.testUsingActiveX('1.7.0')) {
                    list[0] = '1.7.0';
                } else if (deployJava.testUsingActiveX('1.6.0')) {
                    list[0] = '1.6.0';
                } else if (deployJava.testUsingActiveX('1.5.0')) {
                    list[0] = '1.5.0';
                } else if (deployJava.testUsingActiveX('1.4.2')) {
                    list[0] = '1.4.2';
                } else if (deployJava.testForMSVM()) {
                    list[0] = '1.1';
                }
            }
            else if (browser == 'Netscape Family') {
                if (deployJava.testUsingMimeTypes('1.8')) {
                    list[0] = '1.8.0';
                } else if (deployJava.testUsingMimeTypes('1.7')) {
                    list[0] = '1.7.0';
                } else if (deployJava.testUsingMimeTypes('1.6')) {
                    list[0] = '1.6.0';
                } else if (deployJava.testUsingMimeTypes('1.5')) {
                    list[0] = '1.5.0';
                } else if (deployJava.testUsingMimeTypes('1.4.2')) {
                    list[0] = '1.4.2';
                }
            } else if (browser == 'Safari') {
                if (deployJava.testUsingPluginsArray('1.8.0')) {
                    list[0] = '1.8.0';
                } else if (deployJava.testUsingPluginsArray('1.7.0')) {
                    list[0] = '1.7.0';
                } else if (deployJava.testUsingPluginsArray('1.6.0')) {
                    list[0] = '1.6.0';
                } else if (deployJava.testUsingPluginsArray('1.5.0')) {
                    list[0] = '1.5.0';
                } else if (deployJava.testUsingPluginsArray('1.4.2')) {
                    list[0] = '1.4.2';
                }
            }
        }
            
        if (deployJava.debug) {
            for (var i = 0; i < list.length; ++i) {
                alert('We claim to have detected Java SE ' + list[i]);
            }
        }
    
        return list;
    },
    
    /**
     * Triggers a JRE installation.  The exact effect of triggering an 
     * installation varies based on platform, browser, and if the 
     * Deployment Toolkit plugin is installed.
     *
     * The requestVersion string is of the form #[.#[.#[_#]]][+|*], 
     * which includes strings such as "1.4", "1.5.0*", and "1.6.0_02+".  
     * A star (*) means "any version starting within this family" and 
     * a plus (+) means "any version greater or equal to this".  
     * "1.5.0*" * matches 1.5.0_06 but not 1.6.0_01, whereas 
     * "1.5.0+" matches both.
     *
     * If the Deployment Toolkit plugin is not present, this will just call 
     * deployJava.installLatestJRE(). 
     */
    installJRE: function(requestVersion) {
        var ret = false;
        if (deployJava.isPluginInstalled()) {
            if (deployJava.getPlugin().installJRE(requestVersion)) {
                deployJava.refresh();
                if (deployJava.returnPage != null) {
                    document.location = deployJava.returnPage;
                }
                return true;
            } else {
                return false;
            }
        } else {
            return deployJava.installLatestJRE();
        }
    },


    /**
     * Triggers a JRE installation.  The exact effect of triggering an 
     * installation varies based on platform, browser, and if the 
     * Deployment Toolkit plugin is installed.
     *
     * In the simplest case, the browser window will be redirected to the 
     * java.com JRE installation page, and (if possible) a redirect back to 
     * the current URL upon successful installation.  The return redirect is 
     * not always possible, as the JRE installation may require the browser to 
     * be restarted.
     *
     * In the best case (when the Deployment Toolkit plugin is present), this
     * function will immediately cause a progress dialog to be displayed 
     * as the JRE is downloaded and installed.
     */
    installLatestJRE: function() {
        if (deployJava.isPluginInstalled()) {
            if (deployJava.getPlugin().installLatestJRE()) {
                deployJava.refresh();
                if (deployJava.returnPage != null) {
                    document.location = deployJava.returnPage;
                }
                return true;
            } else {
                return false;
            }
        } else {
            var browser = deployJava.getBrowser();
            var platform = navigator.platform.toLowerCase();
            if ((deployJava.EAInstallEnabled == 'true') && 
                (platform.indexOf('win') != -1) && 
                (deployJava.EarlyAccessURL != null)) {

                deployJava.preInstallJREList = deployJava.getJREs();
                if (deployJava.returnPage != null) {
                    deployJava.myInterval = 
                        setInterval("deployJava.poll()", 3000);
                }

                location.href = deployJava.EarlyAccessURL;

                // we have to return false although there may be an install
                // in progress now, when complete it may go to return page
                return false;
            } else {
                if (browser == 'MSIE') {
                    return deployJava.IEInstall();
                } else if ((browser == 'Netscape Family') && 
                           (platform.indexOf('win32') != -1)) {
                    return deployJava.FFInstall();
                } else {
                    location.href = deployJava.getJavaURL + 
                        ((deployJava.returnPage != null) ?
                        ('&returnPage=' + deployJava.returnPage) : '') + 
                        ((deployJava.locale != null) ?
                        ('&locale=' + deployJava.locale) : '') +
                        ((deployJava.brand != null) ? 
                         ('&brand=' + deployJava.brand) : '');
                }
                // we have to return false although there may be an install
                // in progress now, when complete it may go to return page
                return false;
            }
        }
    },


    /**
     * Ensures that an appropriate JRE is installed and then runs an applet.
     * minimumVersion is of the form #[.#[.#[_#]]], and is the minimum 
     * JRE version necessary to run this applet.  minimumVersion is optional, 
     * defaulting to the value "1.1" (which matches any JRE).  
     * If an equal or greater JRE is detected, runApplet() will call 
     * writeAppletTag(attributes, parameters) to output the applet tag, 
     * otherwise it will call installJRE(minimumVersion + '+').
     *
     * After installJRE() is called, the script will attempt to detect that the 
     * JRE installation has completed and begin running the applet, but there
     * are circumstances (such as when the JRE installation requires a browser
     * restart) when this cannot be fulfilled.
     *
     * As with writeAppletTag(), this function should only be called prior to 
     * the web page being completely rendered.  Note that version wildcards 
     * (star (*) and plus (+)) are not supported, and including them in the 
     * minimumVersion will result in an error message.
     */
    runApplet: function(attributes, parameters, minimumVersion) {
        if (minimumVersion == 'undefined' || minimumVersion == null) {
            minimumVersion = '1.1';
        }

        var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";

        var matchData = minimumVersion.match(regex);

        if (deployJava.returnPage == null) {
            // if there is an install, come back here and run the applet
            deployJava.returnPage = document.location;
        }

        if (matchData != null) {
            var browser = deployJava.getBrowser();
            if ((browser != '?') && (browser != 'Safari')) {
                if (deployJava.versionCheck(minimumVersion + '+')) {
                    deployJava.writeAppletTag(attributes, parameters);
                } else if (deployJava.installJRE(minimumVersion + '+')) {
                    // after successfull install we need to refresh page to pick
                    // pick up new plugin
                    deployJava.refresh();
                    location.href = document.location;
                    deployJava.writeAppletTag(attributes, parameters);
                }
            } else {
                // for unknown or Safari - just try to show applet
                deployJava.writeAppletTag(attributes, parameters);
            }
        } else {
            if (deployJava.debug) {
                alert('Invalid minimumVersion argument to runApplet():' + 
                      minimumVersion);
            }
        }
    },

    
    /**
     * Outputs an applet tag with the specified attributes and parameters, where
     * both attributes and parameters are associative arrays.  Each key/value 
     * pair in attributes becomes an attribute of the applet tag itself, while
     * key/value pairs in parameters become <PARAM> tags.  No version checking 
     * or other special behaviors are performed; the tag is simply written to 
     * the page using document.writeln().
     *
     * As document.writeln() is generally only safe to use while the page is 
     * being rendered, you should never call this function after the page 
     * has been completed.
     */
    writeAppletTag: function(attributes, parameters) {
        var s = '<' + 'applet ';
        for (var attribute in attributes) {
            s += (' ' + attribute + '="' + attributes[attribute] + '"');
        }
        s += '>';
        document.write(s);
    
        if (parameters != 'undefined' && parameters != null) {
            var codebaseParam = false;
            for (var parameter in parameters) {
                if (parameter == 'codebase_lookup') {
                    codebaseParam = true;
                }
                s = '<param name="' + parameter + '" value="' + 
                    parameters[parameter] + '">';
                document.write(s);
            }
            if (!codebaseParam) {
              document.write('<param name="codebase_lookup" value="false">');
            }
        }
        document.write('<' + '/' + 'applet' + '>');
    },
    
    
     /**
      * Returns true if there is a matching JRE version currently installed 
      * (among those detected by getJREs()).  The versionPattern string is 
      * of the form #[.#[.#[_#]]][+|*], which includes strings such as "1.4", 
      * "1.5.0*", and "1.6.0_02+".  
      * A star (*) means "any version within this family" and a plus (+) means 
      * "any version greater or equal to the specified version".  "1.5.0*"
      * matches 1.5.0_06 but not 1.6.0_01, whereas "1.5.0+" matches both.
      *
      * If the versionPattern does not include all four version components 
      * but does not end with a star or plus, it will be treated as if it 
      * ended with a star.  "1.5" is exactly equivalent to "1.5*", and will 
      * match any version number beginning with "1.5".
      *
      * If getJREs() is unable to detect the precise version number, a match 
      * could be ambiguous.  For example if getJREs() detects "1.5", there is 
      * no way to know whether the JRE matches "1.5.0_06+".  versionCheck() 
      * compares only as much of the version information as could be detected, 
      * so versionCheck("1.5.0_06+") would return true in in this case.
      *
      * Invalid versionPattern will result in a JavaScript error alert.  
      * versionPatterns which are valid but do not match any existing JRE 
      * release (e.g. "32.65+") will always return false.
      */
    versionCheck: function(versionPattern)
    {
        var index = 0;
        var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?(\\*|\\+)?$";

        var matchData = versionPattern.match(regex);

        if (matchData != null) {
            var familyMatch = true;

            var patternArray = new Array();

            for (var i = 1; i < matchData.length; ++i) {
                // browser dependency here.
                // Fx sets 'undefined', IE sets '' string for unmatched groups
                if ((typeof matchData[i] == 'string') && (matchData[i] != '')) {
                    patternArray[index] = matchData[i];
                    index++;
                }
            }

            if (patternArray[patternArray.length-1] == '+') {
                familyMatch = false;
                patternArray.length--;
            } else {
                if (patternArray[patternArray.length-1] == '*') {
                    patternArray.length--;
                }
            }

            var list = deployJava.getJREs();       
            for (var i = 0; i < list.length; ++i) {
                if (deployJava.compareVersionToPattern(list[i], patternArray, 
                                                       familyMatch)) {
                    return true;
                }
            }
  
            return false;
        } else {
            alert('Invalid versionPattern passed to versionCheck: ' + 
                  versionPattern);
            return false;
        }
    },


    /**
     * Returns true if an installation of Java Web Start of the specified 
     * minimumVersion can be detected.  minimumVersion is optional, and 
     * if not specified, '1.4.2' will be used. 
     * (Versions earlier than 1.4.2 may not be detected.)
     */
    isWebStartInstalled: function(minimumVersion) {

        var browser = deployJava.getBrowser();
        if ((browser == '?') || (browser == 'Safari')) {
            // we really don't know - better to try to use it than reinstall
            return true;
        }

        if (minimumVersion == 'undefined' || minimumVersion == null) {
            minimumVersion = '1.4.2';
        }

        var retval = false;
        var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";
        var matchData = minimumVersion.match(regex);

        if (matchData != null) {
            retval = deployJava.versionCheck(minimumVersion + '+');
        } else {
            if (deployJava.debug) {
                alert('Invalid minimumVersion argument to isWebStartInstalled(): ' + minimumVersion);
            }
            retval = deployJava.versionCheck('1.4.2+');
        }
        return retval;
    },
  
  
    /**
     * Outputs a launch button for the specified JNLP URL.  When clicked, the 
     * button will ensure that an appropriate JRE is installed and then launch 
     * the JNLP application.  minimumVersion is of the form #[.#[.#[_#]]], and 
     * is the minimum JRE version necessary to run this JNLP application.  
     * minimumVersion is optional, and if it is not specified, '1.4.2' 
     * will be used.
     * If an appropriate JRE or Web Start installation is detected, 
     * the JNLP application will be launched, otherwise installLatestJRE() 
     * will be called.
     *
     * After installLatestJRE() is called, the script will attempt to detect 
     * that the JRE installation has completed and launch the JNLP application,
     * but there are circumstances (such as when the JRE installation 
     * requires a browser restart) when this cannot be fulfilled.
     */
    createWebStartLaunchButton: function(jnlp, minimumVersion) { 

        if (deployJava.returnPage == null) {
            // if there is an install, come back and run the jnlp file
            deployJava.returnPage = jnlp;
        }

        var url = 'javascript:' +
                  'if (!deployJava.isWebStartInstalled(&quot;' + 
                      minimumVersion + '&quot;)) {' + 
                      'if (deployJava.installLatestJRE()) {' + 
                        'if (deployJava.launch(&quot;' + jnlp + '&quot;)) {}' +
                      '}' +
                  '} else {' +
                      'if (deployJava.launch(&quot;' + jnlp + '&quot;)) {}' +
                  '}';

        document.write('<' + 'a href="' + url + 
                       '" onMouseOver="window.status=\'\'; ' +
                       'return true;"><' + 'img ' +
                       'src="' + deployJava.launchButtonPNG + '" ' + 
                       'border="0" /><' + '/' + 'a' + '>');
    },


    /**
     * Launch a JNLP application, (using the plugin if available)
     */
    launch: function(jnlp) {
        if (deployJava.isPluginInstalled()) {
            return deployJava.getPlugin().launch(jnlp);
        } else {
            document.location=jnlp;
            return true;
        }
    },

    
    /*
     * returns true if the ActiveX or XPI plugin is installed
     */
    isPluginInstalled: function() {
        var plugin = deployJava.getPlugin();
        if (plugin && plugin.jvms) {
            return true;
        } else {
            return false;
        }
    },
    
    /* 
     * returns true if the plugin is installed and AutoUpdate is enabled
     */
    isAutoUpdateEnabled: function() {
        if (deployJava.isPluginInstalled()) {
            return deployJava.getPlugin().isAutoUpdateEnabled();
        }
        return false;
    },

    /* 
     * sets AutoUpdate on if plugin is installed
     */
    setAutoUpdateEnabled: function() { 
        if (deployJava.isPluginInstalled()) { 
            return deployJava.getPlugin().setAutoUpdateEnabled(); 
        }
        return false;
    },

    /*
     * sets the preferred install type : null, online, kernel
     */
    setInstallerType: function(type) {
        deployJava.installType = type;
        if (deployJava.isPluginInstalled()) {
            return deployJava.getPlugin().setInstallerType(type);
        }
        return false;
    },

    /*
     * sets additional package list - to be used by kernel installer
     */
    setAdditionalPackages: function(packageList) {
        if (deployJava.isPluginInstalled()) {
            return deployJava.getPlugin().setAdditionalPackages(
                                                     packageList);
        }
        return false;
    },

    /*
     * sets preference to install Early Access versions if available
     */
    setEarlyAccess: function(enabled) {
        deployJava.EAInstallEnabled = enabled;
    },

    /*
     * Determines if the next generation plugin (Plugin II) is default
     */
    isPlugin2: function() {
        if (deployJava.isPluginInstalled()) {
            try {
                return deployJava.getPlugin().isPlugin2();
            } catch (err) {
                // older plugin w/o isPlugin2() function - just fall through
            }
        }
        return false;
    },
       

    getPlugin: function() {
        deployJava.refresh();
        var ret = document.getElementById('deployJavaPlugin');
        return ret;
    },

    compareVersionToPattern: function(version, patternArray, familyMatch) {
        var regex = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$";
        var matchData = version.match(regex);  

        if (matchData != null) { 
            var index = 0;
            var result = new Array();

            for (var i = 1; i < matchData.length; ++i) {
                if ((typeof matchData[i] == 'string') && (matchData[i] != ''))
                {
                    result[index] = matchData[i];
                    index++;
                }
            }

            var l = Math.min(result.length, patternArray.length);

            if (familyMatch) {
                for (var i = 0; i < l; ++i) {
                    if (result[i] != patternArray[i]) return false;
                }

                return true;
            } else {
                for (var i = 0; i < l; ++i) {
                    if (result[i] < patternArray[i]) {
                        return false;
                    } else if (result[i] > patternArray[i]) {
                        return true;
                    }
                }
                
                return true;
            }
        } else {
            return false;
        }
    },

  
    getBrowser: function() {
        var browser = navigator.userAgent.toLowerCase();
    
        if (deployJava.debug) {
            alert('userAgent -> ' + browser);
        }
    
        if ((navigator.vendor) && 
            (navigator.vendor.toLowerCase().indexOf('apple') != -1) &&
            (browser.indexOf('safari') != -1)) {
            if (deployJava.debug) {
                alert('We claim to have detected "Safari".');
            }
            return 'Safari';
        } else if (browser.indexOf('msie') != -1) {
            if (deployJava.debug) {
                alert('We claim to have detected "IE".');
            }
            return 'MSIE';
        } else if ((browser.indexOf('mozilla') != -1) || 
                   (browser.indexOf('firefox') != -1)) {
            if (deployJava.debug) {
                alert('We claim to have detected a Netscape family browser.');
            }
            return 'Netscape Family';
        } else {
            if (deployJava.debug) {
                alert('We claim to have failed to detect a browser.');
            }
            return '?';
        }
    },
    
    
    testUsingActiveX: function(version) {
        var objectName = 'JavaWebStart.isInstalled.' + version + '.0';
    
        if (!ActiveXObject) {
            if (deployJava.debug) {
              alert ('Browser claims to be IE, but no ActiveXObject object?');
            }
            return false;
        }
    
        try {
            return (new ActiveXObject(objectName) != null);
        } catch (exception) {
            return false;
        }
    },
    

    testForMSVM: function() {
        var clsid = '{08B0E5C0-4FCB-11CF-AAA5-00401C608500}';

        if (typeof oClientCaps != 'undefined') {
            var v = oClientCaps.getComponentVersion(clsid, "ComponentID");
            if ((v == '') || (v == '5,0,5000,0')) {
                return false;
            } else {
                return true;
            } 
        } else {
            return false;
        }
    },

    
    testUsingMimeTypes: function(version) {
        if (!navigator.mimeTypes) {
            if (deployJava.debug) {
                alert ('Browser claims to be Netscape family, but no mimeTypes[] array?');
            }
            return false;
        }
    
        for (var i = 0; i < navigator.mimeTypes.length; ++i) {
            s = navigator.mimeTypes[i].type;
            var m = s.match(/^application\/x-java-applet\x3Bversion=(1\.8|1\.7|1\.6|1\.5|1\.4\.2)$/);
            if (m != null) {
                if (deployJava.compareVersions(m[1], version)) {
                    return true;   
                }
            }
        }
        return false;
    },
    
    
    testUsingPluginsArray: function(version) {
        if ((!navigator.plugins) || (!navigator.plugins.length)) {
            if (deployJava.debug) {
                alert ('Browser claims to be Safari, but no plugins[] array?');
            }
            return false;
        }

        for (var i = 0; i < navigator.plugins.length; ++i) {
            s = navigator.plugins[i].description;
    
            if (s.search(/^Java Switchable Plug-in/) != -1) {
                return true;
            }
    
            m = s.match(/^Java (1\.4\.2|1\.5|1\.6|1\.7).* Plug-in/);
            if (m != null) {
                if (deployJava.compareVersions(m[1], version)) return true; 
            }
        }
        return false;
    },
    
    IEInstall: function() {
    
        location.href = deployJava.getJavaURL + 
            ((deployJava.returnPage != null) ?
            ('&returnPage=' + deployJava.returnPage) : '') +
            ((deployJava.locale != null) ?
            ('&locale=' + deployJava.locale) : '') +
            ((deployJava.brand != null) ? ('&brand=' + deployJava.brand) : '') +
            ((deployJava.installType != null) ? 
             ('&type=' + deployJava.installType) : '');

         // should not actually get here
         return false;
    },
    
    done: function (name, result) {
    },
    
    FFInstall: function() {

        location.href = deployJava.getJavaURL + 
            ((deployJava.returnPage != null) ?
            ('&returnPage=' + deployJava.returnPage) : '') +
            ((deployJava.locale != null) ?
            ('&locale=' + deployJava.locale) : '') +
            ((deployJava.brand != null) ? ('&brand=' + deployJava.brand) : '') +
            ((deployJava.installType != null) ? 
                ('&type=' + deployJava.installType) : '');

         // should not actually get here
         return false;
    },

    // return true if 'installed' (considered as a JRE version string) is
    // greater than or equal to 'required' (again, a JRE version string).
    compareVersions: function(installed, required) {

        var a = installed.split('.');
        var b = required.split('.');
    
        for (var i = 0; i < a.length; ++i) {
            a[i] = Number(a[i]);
        }
        for (var i = 0; i < b.length; ++i) {
            b[i] = Number(b[i]);
        }
        if (a.length == 2) {
            a[2] = 0;      
        }
    
        if (a[0] > b[0]) return true;
        if (a[0] < b[0]) return false;
    
        if (a[1] > b[1]) return true;
        if (a[1] < b[1]) return false;
    
        if (a[2] > b[2]) return true;
        if (a[2] < b[2]) return false;
    
        return true;
    },
    
    
    enableAlerts: function() {
        deployJava.debug = true;
    },

    poll: function() {

        deployJava.refresh();
        var postInstallJREList = deployJava.getJREs();           

        if ((deployJava.preInstallJREList.length == 0) && 
            (postInstallJREList.length != 0)) {
            clearInterval(deployJava.myInterval);
            if (deployJava.returnPage != null) {
                location.href = deployJava.returnPage;
            };
        }

        if ((deployJava.preInstallJREList.length != 0) && 
            (postInstallJREList.length != 0) &&
            (deployJava.preInstallJREList[0] != postInstallJREList[0])) {
            clearInterval(deployJava.myInterval);
            if (deployJava.returnPage != null) {
                location.href = deployJava.returnPage;
            }
        }

    },
    
    writePluginTag: function() {
        var browser = deployJava.getBrowser();
        if (browser == 'MSIE') {
            document.write('<' + 
                'object classid="clsid:CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA" ' +
                'id="deployJavaPlugin" width="0" height="0">' +
                '<' + '/' + 'object' + '>');
        } else if (browser == 'Netscape Family') {
            deployJava.writeEmbedTag();
        }
    },

    refresh: function() {
        navigator.plugins.refresh(false);

        var browser = deployJava.getBrowser();
        if (browser == 'Netscape Family') {
            var plugin = document.getElementById('deployJavaPlugin');
            // only do this again if no plugin
            if (plugin == null) {
                deployJava.writeEmbedTag();
            }
        }
     },

    writeEmbedTag: function() {
        var written = false;
        if (navigator.mimeTypes != null) {
            for (var i=0; i < navigator.mimeTypes.length; i++) {
                if (navigator.mimeTypes[i].type == deployJava.mimeType) {
                    if (navigator.mimeTypes[i].enabledPlugin) {
                        document.write('<' +
                            'embed id="deployJavaPlugin" type="' +
                            deployJava.mimeType + '" hidden="true" />');
                        written = true;
                    }
                }
            }
            // if we ddn't find new mimeType, look for old mimeType
            if (!written) for (var i=0; i < navigator.mimeTypes.length; i++) {
                if (navigator.mimeTypes[i].type == deployJava.oldMimeType) {
                    if (navigator.mimeTypes[i].enabledPlugin) {
                        document.write('<' +
                            'embed id="deployJavaPlugin" type="' +
                            deployJava.oldMimeType + '" hidden="true" />');
                    }
                }
            }
        }
    },

    do_initialize: function() {
        deployJava.writePluginTag();
        if (deployJava.locale == null) {
            var loc = null;

            if (loc == null) try {
                loc = navigator.userLanguage;
            } catch (err) { }

            if (loc == null) try {
                loc = navigator.systemLanguage;
            } catch (err) { }
    
            if (loc == null) try {
                loc = navigator.language;
            } catch (err) { }
    
            if (loc != null) {
                loc.replace("-","_")
                deployJava.locale = loc;
            }
        }
    }
      
};
deployJava.do_initialize();

// variable declaration;
var java_available=false;
var java_plugin_version;
var java_plugin_valid=false;
var java_version;
var java_vendor;
var java_valid=false;
var java_enabled = navigator.javaEnabled();

var javaws150Installed;

var isIE = false; 
if (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
	isIE = true;
}
var isVBScript = false;
var isWindows = false;
	
var net_passed = "Failed";
var jvm = "N/A";
var jvmvalid = "Failed";
var diagresult = "Failed";
connectionSpeed = 0;    // The variable where connection speed information
                        // will be stored when it is available.
var os_version;
var os_valid = "Failed";
var browser_version;
var browser_valid = "Failed";
var screen_valid = "Failed";
var color_valid = "Failed";
var cpu_valid = "Failed";
var cpu_class = "Not detected";
var jvm_version;
var jvm_valid = "Failed";

var installed_memory=77777; // some outrageous , non-zero value
var memory_valid = "Failed";
var memory_detected = "Failed";

function addLoadEvent(func) {
  var oldonload = window.onload;
  	//alert(window.onload.name);
  if (typeof window.onload != 'function') {
//  if (window.onload == null) {
      window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function idGet(id) {
	if (typeof(document.getElementById) != "undefined") {
		return document.getElementById(id);
	} else {
		return document.all[id];
	}
}


function getMemorySize()
{
    try
    {
        installed_memory = self.WebStart.getInstalledMemorySize();
		if (installed_memory<256 && installed_memory>250) 
		{
        		installed_memory = 256 ; 
		}
		if (installed_memory >= 320)
			memory_valid = "Passed";
			memory_detected = "Passed";
	    }
    catch(err)
    {
		//alert("Error while trying to detect installed memory size.");
    }
}

function drawCSImageTag( fileLocation, fileSize, imgTagProperties ) {

        // This function draws the image tag required to run this process.
        // It needs to be passed:
        //     1.  (String)   The location of the file to be loaded
        //     2.  (Integer)  The size of the image file in bytes
        //     3.  (String)   The tag properties to be included in the <img> tag
        // Place a call to this function inside the <body> of your file
        // in place of a static <img> tag.

        start = (new Date()).getTime();

        // Record Start time of <img> load.
        loc = fileLocation + '?t=' + escape(start);

        // Append the Start time to the image url
        // to ensure the image is not in disk cache.
        document.write('<img src="' + loc + '" ' + imgTagProperties + ' onload="connectionSpeed=computeConnectionSpeed(' + start + ',' + fileSize + ');ShowSpeed();">');

        // Write out the <img> tag.

        return;
}

function computeConnectionSpeed( start, fileSize ) {

        // This function returns the speed in kbps of the user's connection,
        // based upon the loading of a single image.  It is called via onload
        // by the image drawn by drawCSImageTag() and is not meant to be called
        // in any other way.  You shouldn't ever need to call it explicitly.

        end = (new Date()).getTime();
        connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
        return connectSpeed;
}

function SetJVM() {

		//alert(//window.status=
		//"java_available = "+java_available+
		//"\njava_enabled = "+java_enabled+
		//"\njava_valid(>=1.5) = "+java_valid+
		//"\njava_plugin_valid(>=1.5) = "+java_plugin_valid+
		//"\njava_version = "+java_version+
		//"\njava_plugin_version = "+java_plugin_version);
		
	if ( java_version != undefined && java_version != null ) {
		jvm_version = java_version;
	} else if ( java_plugin_version != undefined && java_plugin_version != null) {
		jvm_version = java_plugin_version;
	} else {
		jvm_version = "Not detected";
	}
	if ( java_valid || java_plugin_valid ) {
	//if ( (java_valid || java_plugin_valid) && java_enabled ) {
		jvm_valid = true;
	}
}

function ShowSpeed() {

    //call the getBrowserAndOS method
    getBrowserAndOS();

    //call the SetSpeedCpu method
    SetSpeedCpu();
 	
	return;
}

function DiagTestResult() {
	//alert(jvm_valid);
    if ( jvm_valid == "Failed" || net_passed == "Failed" || os_valid == "Failed" || browser_valid == "Failed" || screen_valid == "Failed" || color_valid == "Failed" || memory_valid == "Failed") {
        diagresult = "Failed";
    }
    else {
        diagresult = "Passed";
    }
    return;
}

function SetSpeedCpu() {
//checks if Net Speed and CPU are valid?

    if (connectionSpeed == null)
    {
     connectionSpeed = "Not Tested -- 0";
     net_passed = "Failed";
    }
    else
    {
     if (connectionSpeed > 40)
     {
       net_passed = "Passed";
     }
     else
     {
       net_passed = "Failed";
     }
    }

    if(window.navigator.cpuClass != "undefined" && window.navigator.cpuClass != null) 
    {
 		cpu_class = window.navigator.cpuClass;
    } else {
    	cpu_class = "Not detected";
    }		

	// we don't care about this anymore	
	cpu_valid = "Passed";
	
 return;
}

function getBrowserAndOS() {

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);

	var is_firefox = (agt.indexOf('firefox') != -1);
	var is_safari = (agt.indexOf('safari') != -1);
	var is_konqueror = (agt.indexOf('konqueror') != -1);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
    var is_ie8    = (is_ie && (is_major == 4) && (agt.indexOf("msie 8.")!=-1) );

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1);

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));
    var is_winxp = ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows nt 5.2")!=-1));
    var is_vista = ((agt.indexOf("windows nt 6.0")!=-1));
    var is_win7  = ((agt.indexOf("windows nt 6.1")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_macOSX    = (agt.indexOf("mac os x")!=-1);
    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

	var is_linux = (agt.indexOf("linux") != -1);
    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd || is_linux);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

	if (is_win)
	{
		isWindows = true;
		if (is_win95)
		{
			os_version = "Windows 95";
			os_valid = "Passed";
		}
		else if (is_win31)
		{
			os_version = "Windows 3.1";
			os_valid = "Failed";
		}
		else if (is_winme)
		{
			os_version = "Windows ME";
			os_valid = "Passed";
		}
		else if (is_winxp)
		{
			os_version = "Windows XP";
			os_valid = "Passed";
		}
		else if (is_vista)
		{
			os_version = "Windows Vista";
			os_valid = "Passed";
		}
                else if (is_win7)
                {
                        os_version = "Windows 7";
                        os_valid = "Passed";
                }
		else if (is_win2k)
		{
			os_version = "Windows 2000";
			os_valid = "Passed";
		}
		else if (is_win98)
		{
			os_version = "Windows 98";
			os_valid = "Passed";
		}
		else if (is_winnt)
		{
			os_version = "Windows NT";
			os_valid = "Failed";
		}
	}
	else if (is_macOSX)
	{
		os_version = "Mac OS X";
		os_valid = "Passed";
		java_valid = "Passed";
		jvm_valid = true;
	}
	else if (is_mac)
	{
		os_version = "Mac OS";
		os_valid = "Passed";
	} else if (is_linux)
	{
		os_version = "Linux";
		os_valid = "Passed";
	} else if (is_sun)
	{
		os_version = "SunOS or Solaris";
		os_valid = "Passed";
	} else if (is_freebsd)
	{
		os_version = "FreeBSD";
		os_valid = "Passed";
        } else if (is_bsd)
        {
                os_version = "BSD";
                os_valid = "Passed";
        }
	else
	{
		os_version = "Not detected";
		os_valid = "Passed";
	}


	if (is_ie)
	{
                if (is_ie8)
                {
                        browser_version = "Internet Explorer 8";
                        browser_valid = "Passed";
                }
		else if (is_ie7)
		{
			browser_version = "Internet Explorer 7";
            		browser_valid = "Passed";
		}
		else if (is_ie6up)
		{
			browser_version = "Internet Explorer 6+";
			browser_valid = "Passed";
		}
		else if (is_ie6)
		{
			browser_version = "Internet Explorer 6";
			browser_valid = "Passed";
		}
		else if (is_ie5_5up)
		{
			browser_version = "Internet Explorer 5.5";
			browser_valid = "Passed";
		}
		else if (is_ie5)
		{
			browser_version = "Internet Explorer 5";
			browser_valid = "Passed";
		}
		else if (is_ie4up)
		{
			browser_version = "Internet Explorer 4+";
			browser_valid = "Failed";
		}
		else if (is_ie4)
		{
			browser_version = "Internet Explorer 4";
			browser_valid = "Failed";
		}
		else if (is_ie3)
		{
			browser_version = "Internet Explorer 3";
			browser_valid = "Failed";
		}
	}
	else if (is_firefox) 
		{
			browser_version = "Mozilla Firefox";
			browser_valid = "Passed";		
		}
		else if (is_safari)
		{
			browser_version = "Safari";
			browser_valid = "Passed";
		} 
		else if (is_konqueror)
		{
			browser_version = "Konqueror";
			browser_valid = "Passed";
		}
		else
		{
//			browser_version = "<a href=\"\" id=browser onclick=\"javascript:alert('"+navigator.userAgent+"');\">Not detected</a>";
//			browser_version = "<a href=\"\" id=browser onclick=\"javascript:alert('"+navigator.userAgent.substring(0,100)+"');\">Not detected</a>";
			browser_version = navigator.userAgent;
			browser_valid = "Passed";
		}


if (window.screen.width > 799 &&
	window.screen.height > 599)
	{
		screen_valid = "Passed";
	}
else
	{
		screen_valid = "Failed";
	}



if (window.screen.colorDepth > 15)
	{
		color_valid = "Passed";
	}
else
	{
		color_valid = "Failed";
	}


var ie=(document.all);

//-->
//MSB - New Code END
}

function BrowserDispatch() {
	if (isWindows) 
	{
		if (isIE)
		{
			//alert("Add code to handle IE on Windows");
			document.write('\
<OBJECT NAME="WebStart" classid=clsid:165B3239-2565-49DB-8A82-F28631CE44ED CODEBASE="../webstart.cab#version=1,0,0,7">\
</OBJECT>\
		');
			getMemorySize();
		    if (installed_memory == 77777) // the initial value - which means the ActiveX query has failed
			{
document.location.replace('noactivex.jsp');
				return; 
			}
		} else {
			installed_memory = 320; memory_valid = "Passed";
			//alert("Add code to handle non-IE on Windows");
		}		
	} else {
		installed_memory = 320; memory_valid = "Passed";
		//alert("Add code to handle non-Windows platforms");
	} 
 
    //call the DiagTestResult method
    DiagTestResult();

    if(diagresult == "Passed") {
        document.location = "diag_pass.jsp?speed=" + connectionSpeed + "&jvm_version=" + jvm_version + "&osver=" + os_version + "&bver=" + browser_version + "&wsw=" + window.screen.width + "&wsh=" + window.screen.height + "&wsc=" + window.screen.colorDepth + "&cpu=" + cpu_class + "&spv=" + net_passed + "&jvv=" + jvm_valid + "&osv=" + os_valid + "&bvv=" + browser_valid + "&scv=" + screen_valid + "&wsv=" + color_valid + "&cpv=" + cpu_valid + "&memory="+installed_memory+"&memory_detected="+memory_detected;
    }
    else {
        document.location = "diag_fail.jsp?speed=" + connectionSpeed + "&jvm_version=" + jvm_version + "&osver=" + os_version + "&bver=" + browser_version + "&wsw=" + window.screen.width + "&wsh=" + window.screen.height + "&wsc=" + window.screen.colorDepth + "&cpu=" + cpu_class + "&spv=" + net_passed + "&jvv=" + jvm_valid + "&osv=" + os_valid + "&bvv=" + browser_valid + "&scv=" + screen_valid + "&wsv=" + color_valid + "&cpv=" + cpu_valid + "&memory="+installed_memory+"&memory_valid="+memory_valid+"&memory_detected="+memory_detected;
    }
}


// *** JAVA DETECTION ***
// 1st method , looking through available plug-ins
	if (navigator.mimeTypes && navigator.mimeTypes.length)
	if (typeof(navigator.mimeTypes['application/x-java-vm']) != "undefined")
		java_available = true;
	if (navigator.plugins) {
		aux_version = '0.0';
		for (var i=0; i < navigator.plugins.length; i++) {
			// older/Windows Firefox plugins have this type of signature: "Java Plug-in 1.6.0_05 for Netscape Navigator (DLL Helper)"
			if (navigator.plugins[i].description && (navigator.plugins[i].description.indexOf("Java Plug-in") >= 0)) {
				java_available = true;
				java_plugin_version = navigator.plugins[i].description.substring(navigator.plugins[i].description.lastIndexOf("Plug-in ") + 8, navigator.plugins[i].description.lastIndexOf(" for"));
				//alert(java_plugin_version);
				if (java_plugin_version > aux_version) {
					aux_version = java_plugin_version;
				}
			}
			java_plugin_version = aux_version;
			// newer/non-Windows Firefox plug-ins have a slightly changed signature: "Java(TM) Plug-in 1.6.0_03"
                        if (navigator.plugins[i].description && (navigator.plugins[i].description.indexOf("Java(TM) Plug-in") >= 0)) {
                                java_available = true;
                                java_plugin_version = navigator.plugins[i].description.substring(navigator.plugins[i].description.lastIndexOf("Plug-in ") + 8);
                                //alert(java_plugin_version);
                                if (java_plugin_version > aux_version) {
                                        aux_version = java_plugin_version;
                                }
                        }
                        java_plugin_version = aux_version;
		}
		if (!isNaN(parseFloat(java_plugin_version)) && parseFloat(java_plugin_version) >= 1.5) {
			java_plugin_valid = true;
		} else {
			java_plugin_version = 'Not detected';
		}
	}

// 2nd method - launch the applet directly	
document.write('\
		<applet id="jvdetect" name="jvdetect" alt="Java isn\'t installed or doesn\'t work" border="0" code="jvdetect.class" codebase=".." height="1" width="1"></applet>\
');

// 3rd method - some IE applets
document.write('\
        <object id="jvdetectIE" name="jvdetectIE" alt="Test JRE Applet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="1" height="1">\
            <param name="type" value="application/x-java-applet" />\
            <param name="codebase" value=".." />\
            <param name="code" value="jvdetect.class" />\
        </object>\
');

addLoadEvent (function() {
		var ua = navigator.userAgent;
		var msie = (ua) ? ua.indexOf("MSIE ") : -1;
		var element = idGet("jvdetect");
                var elementIE = idGet("jvdetectIE");
		var show_alert = false;
		
		//if (show_alert) alert(
		//"msie=" + msie + "\n" + 
		//"elementIE=" + elementIE + "\n" + 
		//"elementIE.getJavaVersion()=" + elementIE.getJavaVersion() + "\n" + 
		//"elementIE.getJavaVersion=" + elementIE.getJavaVersion + "\n" +
		//"element=" + element + "\n" + 
		//"element.getJavaVersion()=" + element.getJavaVersion() + "\n" + 
		//"element.getJavaVersion=" + element.getJavaVersion + "\n" +
		//"");
		
    try 
    {
	var list=new Array();
	list = deployJava.getJREs();
	//if (show_alert) alert("'" + list[list.length-1] + "'");
	if (list[list.length-1]=="undefined" || list[list.length-1]==null)
	{
	    if (show_alert) alert("throwing exception");
	    throw "Err";
	}
	java_version = list[list.length - 1];
    	if((parseFloat(java_version) != NaN || parseInt(java_version) != NaN) && (java_version>="1.5.0"))
	    java_valid = true;
        elementIE.style.display = "none";
	java_available = true;
	if (show_alert) alert("detected Java via new procedure");
    } 
    catch (e) 
    {
        try 
	{
	    if (show_alert) alert("1");
	    if (msie!=-1 && elementIE != null)
	    {
		//IE detected
		try
		{
		    if (show_alert) alert("2");
            	    if (msie!=-1 && elementIE != null && elementIE.getJavaVersion != "undefined" && elementIE.getJavaVersion != null) 
    		    {
			try
			{
			    if (show_alert) alert("deployJava.getJREs() failed ... continuing the old detection way .. IE detected .. getJavaVersion");
                	    java_version = elementIE.getJavaVersion;
                	    java_vendor = elementIE.getVendor();
                	    java_valid = elementIE.isValid();
    			    if((parseFloat(java_version) != NaN || parseInt(java_version) != NaN) && (java_version>="1.5.0"))
				java_valid = true;
                	    elementIE.style.display = "none";
			    java_available = true;
			}
			catch (e)
			{
            		    alert("An exception occurred in the script (1.1). Error name: " + e.name + ". Error message: " + e.message);
			}
            	    } 
		}
		catch (e)
		{
		    try
		    {
			if (show_alert) alert("2.1");
            		if (msie!=-1 && elementIE != null && elementIE.getJavaVersion() != "undefined" && elementIE.getJavaVersion() != null) 
    			{
		    	    if (show_alert) alert("deployJava.getJREs() failed ... continuing the old detection way .. IE detected .. getJavaVersion()");
                	    java_version = elementIE.getJavaVersion();
                	    java_vendor = elementIE.getVendor();
                	    java_valid = elementIE.isValid();
    			    if((parseFloat(java_version) != NaN || parseInt(java_version) != NaN) && (java_version>="1.5.0"))
				java_valid = true;
            		    elementIE.style.display = "none";
			    java_available = true;
            		} 
		    }
		    catch (e) 
	    	    {
            		alert("An exception occurred in the script (1.2). Error name: " + e.name + ". Error message: " + e.message);
            	    }
		}
	    }
	    else
	    {
		//IE not detected
		if (show_alert) alert("3");
		try
		{
        	    if (element.getJavaVersion != "undefined" && element.getJavaVersion != null) 
		    {
			try
			{
			    if (show_alert) alert("deployJava.getJREs() failed ... continuing the old detection way .. IE NOT detected .. getJavaVersion");
                	    java_version = element.getJavaVersion;
                	    java_vendor = element.getVendor();
                	    java_valid = element.isValid();
    			    if((parseFloat(java_version) != NaN || parseInt(java_version) != NaN) && (java_version>="1.5.0"))
				java_valid = true; // Konqueror reported KJAS default java version :-?
                	    element.style.display = "none";
			    java_available = true;
			}
			catch (e)
			{
            		    alert("An exception occurred in the script (2.1). Error name: " + e.name + ". Error message: " + e.message);
			}
            	    } 
		}
		catch (e)
		{
		    try
		    {
        		if (element.getJavaVersion() != "undefined" && element.getJavaVersion() != null) 
			{
			    if (show_alert) alert("deployJava.getJREs() failed ... continuing the old detection way .. IE NOT detected .. getJavaVersion()");
                	    java_version = element.getJavaVersion();
                	    java_vendor = element.getVendor();
                	    java_valid = element.isValid();
    			    if((parseFloat(java_version) != NaN || parseInt(java_version) != NaN) && (java_version>="1.5.0"))
				java_valid = true; // Konqueror reported KJAS default java version :-?
                	    element.style.display = "none";
			    java_available = true;
			}
            	    } 
		    catch (e) 
	    	    {
            		alert("An exception occurred in the script (2.2). Error name: " + e.name + ". Error message: " + e.message);
        	    }
		}
	    }
        } 
	catch (e) 
	{
            alert("An exception occurred in the script (3). Error name: " + e.name + ". Error message: " + e.message);
        }
    }

    if (show_alert) alert(//window.status=
    "java_available = "+java_available+
    "\njava_enabled = "+java_enabled+
    "\njava_valid(>=1.5) = "+java_valid+
    "\njava_plugin_valid(>=1.5) = "+java_plugin_valid+
    "\njava_version = "+java_version+
    "\njava_plugin_version = "+java_plugin_version);
	
    setTimeout('SetJVM()',500);
    setTimeout('BrowserDispatch()',1000);
		
});


