// Java Document

var num_examples = 0;
var example_num = 0;
var launchTID = "";

function changeExample() {
	//if browser does not support the image object, exit.
	if (!document.images) return;
	
	document.images.example.src = eval("example" + example_num + ".src");
	example_num ++;
	
	if (example_num >= num_examples) example_num = 0;
	
	setTimeout("changeExample()", 5000);
}



function checkInstallForm (form)
{
	var fullname = document.forms[0].fullname;
	var email = document.forms[0].email;
	var willpurchase = document.forms[0].agree;
	
	if (fullname.value == "") {
		alert( "Please enter your full name." );
		fullname.focus();
		return false;
	}
	
	if (email.value == "") {
		alert( "Please enter your email address." );
		email.focus();
		return false;
	}
  
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
		alert( "Please enter a valid email address." );
		email.focus();
		return false;
	}
	
	if (willpurchase.checked == false) {
		alert( "You must agree to purchase JADS if you decide to use it." );
		return false;
	}

	return true ;
}

var detect = navigator.userAgent.toLowerCase();
var windowsIE = (checkPlatform("msie") && checkPlatform("win"));

function checkPlatform(string) {
    place = detect.indexOf(string) + 1;
    return place;
}

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) {
            pluginType = navigator.mimeTypes[i].type;
            if (pluginType == "application/x-java-applet;version=" + versionString) {
                return true;
            }
         }
     }
 }
 
function launchJNLPWhenReady(app) {
    if (webstartVersionCheck("1.5")) {
        window.location = app;
		clearInterval(launchTID);
    }
}


function launchJNLP(jnlpLocation) {

	if (windowsIE) {
		document.write("<p>JADS web launcher has detected you are using Internet Explorer within Microsoft Windows. ");
		document.write("An ActiveX component will now be used to ensure Java is installed and launch Jads when ready. ");
		document.write("You may have to approve the execution of the ActiveX component.</p>");
		
		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='" + jnlpLocation + "'>");
		document.write("<PARAM NAME=back VALUE=false>");
		document.write("</OBJECT>");
		
		document.write("<p>To manually launch JADS click <a href='" + jnlpLocation + "'>here</a>.</p>");				
	 }
	 
	if (navigator.mimeTypes && navigator.mimeTypes.length) {
		
		document.write("<p>JADS web launcher has detected you are using a Mozilla compatable browser.</p>");
		
		webstartAvailable = navigator.mimeTypes['application/x-java-jnlp-file'];
		
		if (webstartVersionCheck("1.5")) {
			document.write("<p>Your Java runtime environment is suitable for launching JADS. (1.5+)</p>");
			document.write("<p>Launching JADS, please wait...</p>");				
		}
		else {
			document.write("<p>JADS web launcher has detected you do not have the correct version of Java installed.</p>");
			document.write("<p>Please click <a href='http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=java.com'>here</a> and follow the steps to install Java software for your system. ");	
			document.write("JADS will be launched automatically when installation of JAVA is complete.</p>");	
		}
		launchTID = setInterval('launchJNLPWhenReady("' + jnlpLocation + '");', 1000);	
	}
}
	


	

