// $Id: webstart.js,v 1.2 2008/06/08 23:35:42 grossb Exp $
//------------------------------------------------------------------------------

/*
 * Function to determine webstart version - taken from sun site
 */
function webstartVersionCheck(versionString) {
    // Mozilla may not recognize new plugins without this refresh
    navigator.plugins.refresh(true);
    // First, determine if Web Start 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) {
		    var pluginType = navigator.mimeTypes[i].type;
			if (pluginType == "application/x-java-applet;version=" + versionString) {
                return true;
			}
		}
	}
	return true;
}

/*
 * Called to launch webstart.
 */
function webstart(webstart_url) {

	// determine if webstart is available - code taken from sun site
	var userAgent = navigator.userAgent.toLowerCase();
	// user is running windows
	if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("win") != -1){
	    document.write("<OBJECT " +
					   "codeBase=http://java.sun.com/update/1.5.0/jinstall-1_5_0_05-windows-i586.cab " +
					   "classid=clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284 height=0 width=0>");
		document.write("<PARAM name=app VALUE=" + webstart_url + ">");
		document.write("<PARAM NAME=back VALUE=true>");
		// alternate html for browsers which cannot instantiate the object
		document.write("<A href=\"http://java.sun.com/j2se/1.5.0/download.html\">Download Java WebStart</A>");
		document.write("</OBJECT>");
	}
	// user is not running windows
	else if (webstartVersionCheck("1.5")) {
	    window.location = webstart_url;
	}
	// user does not have jre installed or lacks appropriate version - direct them to sun download site
	else {
	    window.open("http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=java.com",
					"needdownload");
    }

    // outta here
    return false;
}
