// Java Version Detection - Rev 0.1
//
// This javascript file contains code to try to identify the java 
// version installed on the client system.
//
// Written by Joe Turner (joe@agavemountain.com)
//
// Copyright(c) 2009 Trane. All rights reserved.


// This function will attempt to communicate with our java class applet.
// If the java applet cannot be loaded (java is disabled in the browser or
// java isn't installed) then this function will return a null for the 
// version. 
// 
// Note: this class requires the use of a java applet (JavaDetect.class). 
function GetJavaAppletVer()
{
	var javaVersion = null;
	
	try
	{
	    var app = document.applets[0];
	    javaVersion = app.getJavaVersion();
	}
	catch(e)
	{
	    // Exception: unable to communicate with the java applet; 
		// This is quite possibly
	    javaVersion = null;
	}
	
	return javaVersion;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns 
// true if that version or greater is available
function DetectJavaVersion(reqMajorVer, reqMinorVer, reqRevision)
{
	var versionStr = GetJavaAppletVer();
	
	if (versionStr === null) 
	{
        return false;
	}
	
	// test case  
	// versionStr = "1.4.99";
	var tmpArray = versionStr.split(".");
	
	var verMajor = parseInt(tmpArray[0]);
	var verMinor = parseInt(tmpArray[1]);
	var verRev = parseInt(tmpArray[2]);

	if (verMajor > reqMajorVer)
	{
		return true;
	}
	else if (verMajor === reqMajorVer)
	{
		if (verMinor > reqMinorVer)
		{
			return true;
		}
		else if (verMinor === reqMinorVer)
		{
			if (verRev >= reqRevision)
			{
				return true;
			}
		}
	}
	
	return false;
}


