DEBUG = false;

// Versions and file location and name strings.
// The following version number assignments MUST coincide with the VERSION_*
// variables in the .js files under the deployment\NSPlugins folder for JAR
// file updating to work.
VERSION_MAJ=3;
VERSION_MIN=2;
VERSION_REV=1;
VERSION_BLD=4389;

// How Netscape recognizes the plugin.  See navigator object for details.
MIMETYPE = "application/x-ggw-plugin";

// The setting below MUST match the assignment made to SU_REGISTRYPATH in
// any of the .js files under the deployment\NSPlugins folder.
PLUGIN_DIRECTORY = "Graphon";

// Jar file containing plugin and other files required for the plugin.
// This file is different for Windows and Linux, and between Netscape 6
// and previous versions of Netscape.

var browser = new whatPlatform();
if (browser.win)
{
	JARFILE = "ggw-nsplugin.windows.xpi";
}
else
{
	JARFILE = "ggw-nsplugin.linux.xpi";
}

function DebugMsg( message )
{
    if ( DEBUG )
    {
        alert( message );
    }
}

function pluginUpdateNeeded(existing_version, new_version)
{
    var existing_tokens = existing_version.split(".");
    var new_tokens = new_version.split(".");

	if( existing_tokens.length == 4 && new_tokens.length == 4 )
	{
		var existing_val = new Number( existing_tokens[0] );
		var new_val = new Number( new_tokens[0] );
		if (existing_val < new_val)
		{
			DebugMsg("Version is newer  in major version.");
			return true;
		}

		existing_val = new Number( existing_tokens[1] );
		new_val = new Number( new_tokens[1] );
		if (existing_val < new_val)
		{
			DebugMsg("Version is newer  in minor version.");
			return true;
		}

		existing_val = new Number( existing_tokens[2] );
		new_val = new Number( new_tokens[2] );
		if (existing_val < new_val)
		{
			DebugMsg("Version is newer  in revision version.");
			return true;
		}

		existing_val = new Number( existing_tokens[3] );
		new_val = new Number( new_tokens[3] );
		if (existing_val < new_val)
		{
			DebugMsg("Version is newer in build version.");
			return true;
		}
	}
	else
	{
        DebugMsg("Version is not 4 numbers.");
	}


    return false;

}

function AlreadyInstalled_XPInstall()
{
    var myMimeType = navigator.mimeTypes[MIMETYPE];
    if ( myMimeType )
    {
        var browser = new whatPlatform();
        if ( browser.ff3 )
        {
            return true; // no way to check versions in ff3
        }
        existing_vi = InstallTrigger.getVersion(PLUGIN_DIRECTORY);
        DebugMsg("Current version is: " + existing_vi);
        if (existing_vi != null)
        {
            existing_vi_string = new String(existing_vi);
            new_vi_string = new String(VERSION_MAJ + "." + VERSION_MIN + "." + VERSION_REV + "." + VERSION_BLD);
            DebugMsg("New version is: " + new_vi_string );

            if ( pluginUpdateNeeded (existing_vi_string, new_vi_string) )
            {
                DebugMsg("Version is newer than installed; upgrade is in order.");
                return false;
            }
            else
            {
                DebugMsg("Version is no newer than previously installed version.");
                return true;
            }
        }
    }
    else
    {
       DebugMsg("GraphOn GO-Global:ggw Plug-in is not already installed");
       return false;
    }
}

function xpinstallCallback(url, status)
{
    if ( DEBUG )
    {
        if (status == 0)
            msg = "XPInstall Test:   PASSED\n";
        else
            msg = "XPInstall Test:   FAILED\n";

        alert(msg);
    }
}


function downloadNow_XPInstall()
{

    var browser = new whatPlatform();
    if ( browser.ff3 )
    {
		if ( AlreadyInstalled() )
		{
			document.location.href="logon.html";
		}
		else
		{
			var xpi = {'GO-Global Netscape Plugin':'ggw-nsplugin_ff3.windows.xpi'};
			InstallTrigger.install(xpi);
		}
    }
    else
    {
        if ( navigator.javaEnabled() )
        {
            if ( InstallTrigger.enabled() )
            {
                this_url = new String(location.href);
                backslash = this_url.lastIndexOf("/");
                this_urls_path = this_url.substring(0, backslash+1);
                jarUrl = this_urls_path.concat(JARFILE);

                xpi = new Object();
                xpi["GraphOn GO-Global"] = jarUrl;
                InstallTrigger.install(xpi, xpinstallCallback);
            }
            else
            {
                alert("Enable Software Installation from Preferences to install this plug-in.");
            }
        }
        else
        {
            alert("Enable Java before running this script.");
        }
    }
}

function AlreadyInstalled ( )
{
	return AlreadyInstalled_XPInstall();
}

function downloadNow ( )
{
	return downloadNow_XPInstall();
}
