
var webstart = 'unknown';


function testWebstart() {

	//standards-compliant browsers
	if(navigator.mimeTypes && navigator.mimeTypes.length > 1){
		webstart = webstartVersionCheck ("1.5") || webstartVersionCheck ("1.6") ;
	}
	//Microsoft Browsers
	if(webstart == 'unknown'){
		webstart = isJava5IE() || isJava6IE ();
	}
	return webstart;
}


function isJava5IE() {
	try {
		// Detect Java 5 platform
		var obj = new ActiveXObject("JavaWebStart.isInstalled.1.5.0.0");
		if (obj != null) {
			return true;
		}
	} catch (exception) {
		return false;
	}
}


function isJava6IE() {
	try {
		// Detect Java 5 platform
		var obj = new ActiveXObject("JavaWebStart.isInstalled.1.6.0.0");
		if (obj != null) {
			return true;
		}
	} catch (exception) {
		return false;
	}
}



function webstartVersionCheck(versionString) {
	//navigator.plugins.refresh(true);
	// First, determine if Webstart is available
	if (navigator.mimeTypes['application/x-java-jnlp-file']) {
		// Next, check for appropriate version family
		for (var i = 0; i < navigator.mimeTypes.length; ++i) {

			pluginType = navigator.mimeTypes[i].type;
			//document.write ("plugin: "+pluginType+"<br/>");
			if (pluginType == "application/x-java-applet;version=" + versionString) {
				return true;
			}
		}
	}
}



function launchJNLPJavaAutoInstall (jnlpUrl) {
	// Auto-Install latest Java platform; after install
	// is complete, the Java Web Start ActiveX object will
	// launch the Notepad application
	document.write("<OBJECT classid=clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284 codebase=http://java.sun.com/update/1.5.0/ jinstall-1_5-windows-i586.cab#Version=5,0,0,99 height=0 width=0>");
	document.write("<PARAM name=app value="+jnlpUrl+">");
	document.write("</OBJECT>");
}


function launchJNLPGetJava (jnlpUrl) {
	// Open new browser window to GetJava site
	window.open("http://java.com/getjava", "newWindow");
	// Spin and wait for install complete to launch app
	// Infinite loop possible here if user bail out on
	// install, a better version should use timeout
	launchTID = setInterval ('launchApp(jnlpUrl)', 100);
}


function launchApp (app) {
	x = navigator.mimeTypes['application/x-javaapplet;version=1.5'];
	if (x) {
		window.location = app;
		clearInterval(launchTID);
	}
}


function needJava () {
	if (webstart == true) {
		document.write ("<P style=\"font-size: 11pt; font-family: courier\"> java webstart 1.5 installed: "+webstart+"<br>OS: "+navigator.OS+"<br>Browser: "+navigator.org+", "+navigator.family+" v"+navigator.version+"</P>");
	} else {
    		document.write ("<a href=\"http://java.com/java/download/index.jsp?cid=jdp110920\" target=\"_blank\"><img width=\"88\" height=\"31\" border=\"0\" style=\"margin: 8px;\" alt=\"GetJava Download Button\" title=\"GetJava\" src=\"http://java.com/en/img/everywhere/getjava_sm.gif?cid=jdp110920\"></a>");
	}
}



function launchLink(jnlpUrl, title, img) {

	if (webstart == true) {
		document.write("<a href=" + jnlpUrl +"><img src="+img+" class=\"include\"/> "+title+"</a>");
	}
	else {
		if(navigator.mimeTypes) {
			document.write ("<a href=\"\" onclick=\"launchJNLPGetJava(" + jnlpUrl
				+ ")\"><img width=\"88\" height=\"31\" border=\"0\" style=\"margin: 8px;\" alt=\"GetJava Download Button\" title=\"GetJava\" src=\"http://java.com/en/img/everywhere/getjava_sm.gif?cid=jdp110920\" class=\"include\"/> "
				+ title+"</a>");
		}
		else {
			document.write ("<a href=\"\" onclick=\"launchJNLPJavaAutoInstall("+jnlpUrl+")\"><img src="+img+" class=\"include\"/> "+title+"</a>");
		}

	}

}

testWebstart();



