/*
 * @(#)checkPlugin.js 07.03.2005 Sebastian Ryszard Kruk;DERI
 * 
 * Copyright (c) 2003-2005,
 * Sebastian Ryszard Kruk
 * http://www.sebastiankruk.com/
 * 
 * Faculty of Electronics,Telecommunication and Informatics and Main Library
 * Gdansk University of Technology, Poland
 * http://www.eti.pg.gda.pl/
 * http://www.bg.pg.gda.pl/
 * 
 * Digital Enterprise Research Institute,
 * National University of Ireland, Galway, Ireland
 * http://www.deri.org/
 * 
 * JeromeDL is distributed under BSD license.
 * [Please note that JeromeDL is a joined project between DERI and GUT, based on the previously 
 * released Elvis-DL code (under GPL license)]
 * 
 * All rights reserved.
 * 
 * Redistribution andusein source and binary forms, with or without modification, are 
 * permitted provided that the following conditions are met:
 * 
 *    * Redistributions of source code must retain the above copyright notice, this list 
 * of conditions and the following disclaimer.
 *    *Redistributions in binary form must reproduce the above copyright notice, this list of
 * conditions and the following disclaimer in thedocumentation and/or other materials provided 
 * with the distribution.
 *     * Neither the name of Sebastian Ryszard Kruk; Digital Enterprise Research Institute, 
 * National University of Ireland, Galway, Ireland; Faculty of Electronics, Telecommunication and 
 * Informatics and Main Library Gdansk University of Technology, Poland nor the names of its 
 * contributors  may be used to endorse orpromote products derived from this software without 
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THECOPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY 
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITEDTO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAYOUTOF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 */

/**
 *
 */

var J2SE_EXISTS = null;

/**
 *
 * @param val1
 * @param val2
 * @return
 */
function /*:boolean:*/ isGreaterEqual(/*:String:*/val1, /*:String:*/val2){
	
	var aval1 = val1.split(".");
	var aval2 = val2.split(".");
	var result = true;
	
	for(var i=0; (i < aval1.length) && (i < aval2.length); i++){
		if(aval1[i] < aval2[i]){
			result = false;
			break;
		}
	}
	return result;
}

/**
 *
 * @param realy
 * @return
 */
function j2seExists(realy){
	j_j2seExists(realy);
}

/**
 *
 * @param realy
 * @return
 */
function j_j2seExists(realy){
	J2SE_EXISTS = realy;
	onLoadCheck();
}


		/*****************************************************************************************************************
		 *  DETECT NAVIGATOR AND PLATFORM
		 *****************************************************************************************************************/
		 var agent = navigator.userAgent.toLowerCase();
		 var is_ie = (agent.indexOf("msie") != -1);
		 var is_mozilla = (agent.indexOf("mozilla") != -1);
		 var is_opera = (agent.indexOf("opera") != -1);
		 var is_win = ((agent.indexOf("win") !=- 1) || (agent.indexOf("16bit") !=- 1));
									 
		/*****************************************************************************************************************
		 *	DETECT FOR FLASH
		 ****************************************************************************************************************/
		var MM_contentVersion = 6;
		var MM_FlashCanPlay = false;
		var MM_FlashCanPlay_enabled = "?";
		var MM_FlashCanPlay_version = "?";
		var MM_FlashCanPlay_sufficient = false;
		
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : false;
		if ( plugin ) {
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");
					for (var i = 0; i < words.length; ++i)
					{
				if (isNaN(parseInt(words[i])))
				continue;
				var MM_PluginVersion = words[i]; 
					}
			MM_FlashCanPlay = true;
			MM_FlashCanPlay_sufficient = MM_PluginVersion >= MM_contentVersion;
			MM_FlashCanPlay_version = MM_PluginVersion;
			MM_FlashCanPlay_enabled = true;
		}
		
		if (is_win && is_ie) {
			document.write('<SCR' + 'IPT language="VBScript"\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
			document.write('on error resume next \n');
			document.write('isFlash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n');
			document.write('			If(isFlash) Then\n');
			document.write('				MM_FlashCanPlay = TRUE\n');
			document.write('				isVersion = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))\n');
			document.write('				isChecked = TRUE\n');
			document.write('				For ver=7 To 1 Step -1\n');
			document.write('					\'-- check for ver\n');
			document.write('					If(isVersion AND isChecked) Then\n');
			document.write('						MM_FlashCanPlay_sufficient = ver+1 >= MM_ContentVersion\n');
			document.write('						MM_FlashCanPlay_version = (ver+1)\n');
			document.write('						isChecked = FALSE\n');
			document.write('						Exit For\n');
			document.write('					ElseIf(isChecked) Then \n');
			document.write('						isVersion = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ver))\n');
			document.write('						isChecked = TRUE\n');
			document.write('					End If\n');
			document.write('				Next\n');
			document.write('			End If \n');
			
			document.write('Sub j2seExists(realy)');
			document.write('	j_j2seExists(realy)');
			document.write('End Sub');
			
			document.write('</SCR' + 'IPT\> \n');
		}

		/*****************************************************************************************************************
		 *	DETECT FOR JAVA
		 *****************************************************************************************************************/
		var JRE_contentVersion = "1.4";
		var JRE_JavaCanPlay = false;
		var JRE_JavaCanPlay_enabled = navigator.javaEnabled();
		var JRE_JavaCanPlay_version = "?.?";
		var JRE_JavaCanPlay_sufficient = false;
		
		var Jplugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-java-applet"]) ? navigator.mimeTypes["application/x-java-applet"].enabledPlugin : 0;

		if ( Jplugin ) {
			JRE_JavaCanPlay = true;
			var type = navigator.mimeTypes;
			var mimere = "application/x-java-applet;version=";
			for(var i = 0; i < type.length; i++){
				var ismime = type[i].type.indexOf(mimere);
				if(ismime != -1){
					var ver_tmp = type[i].type.substr(ismime+34);
					if(isGreaterEqual(ver_tmp, JRE_contentVersion)){
						JRE_JavaCanPlay_sufficient = true;
						if(JRE_JavaCanPlay_version == "?.?" ||
						   isGreaterEqual(ver_tmp, JRE_JavaCanPlay_version)){
						   	JRE_JavaCanPlay_version = ver_tmp;
						 }	
					}
				}//if
			}//for
		}
		
		if (is_win && is_ie) {
			
			document.write('<SCR' + 'IPT language="VBScript"\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
			document.write('on error resume next \n');
			document.write('			dim jvers(11)\n');
			document.write('			dim jvers_name(11)\n');
			document.write('			jvers(0) = "11"\n');
			document.write('			jvers(1) = "12"\n');
			document.write('			jvers(2) = "13"\n');
			document.write('			jvers(3) = "131"\n');
			document.write('			jvers(4) = "14"\n');
			document.write('			jvers(5) = "141"\n');
			document.write('			jvers(6) = "141_01"\n');
			document.write('			jvers(7) = "142"\n');
			document.write('			jvers(8) = "142_01"\n');
			document.write('			jvers(9) = "142_02"\n');
			document.write('			jvers(10) = "142_03"\n');
			document.write('			jvers(11) = "15"\n');
			document.write('			jvers_name(0) = "1.1"\n');
			document.write('			jvers_name(1) = "1.2"\n');
			document.write('			jvers_name(2) = "1.3"\n');
			document.write('			jvers_name(3) = "1.3.1"\n');
			document.write('			jvers_name(4) = "1.4"\n');
			document.write('			jvers_name(5) = "1.4.1"\n');
			document.write('			jvers_name(6) = "1.4.1_01"\n');
			document.write('			jvers_name(7) = "1.4.2"\n');
			document.write('			jvers_name(8) = "1.4.2_01"\n');
			document.write('			jvers_name(9) = "1.4.2_02"\n');
			document.write('			jvers_name(10) = "1.4.2_03"\n');
			document.write('			jvers_name(11) = "1.5"\n');
			
			document.write('			JRE_MINIMAL = 4\n');

			document.write('			isJava = IsObject( CreateObject("JavaPlugin") )\n');
			document.write('			If(isJava) Then\n');
			document.write('				JRE_JavaCanPlay = TRUE\n');
			document.write('				isJVersion = IsObject(CreateObject("JavaPlugin." & jvers(9)))\n');
			document.write('				isJChecked = TRUE\n');
			document.write('				For ver=10 To 0 Step -1\n');
			document.write('					\'-- check for ver\n');
			document.write('					If(isJVersion AND isJChecked) Then\n');
			document.write('						JRE_JavaCanPlay_sufficient = ver+1 >= JRE_MINIMAL\n');
			document.write('						JRE_JavaCanPlay_version = jvers_name(ver+1)\n');
			document.write('						isJChecked = FALSE\n');
			document.write('						Exit For\n');
			document.write('					ElseIf(isJChecked) Then \n');
			document.write('						isJVersion = IsObject(CreateObject("JavaPlugin." & jvers(ver)))\n');
			document.write('						isJChecked = TRUE\n');
			document.write('					End If\n');
			document.write('				Next\n');
			document.write('			End If \n');
			
			document.write('</SCR' + 'IPT\> \n');
		
		
			
		}
		
/**
 *
 * @return
 */		
function onLoadCheck(){
	if(J2SE_EXISTS!=null){
    	try{
    		var info = document.getElementById("java_error_info");
    		info.style.visibility = 'hidden';
    		info.style.height='0px';
    		info.innerHtml = '';
    		if(J2SE_EXISTS=='1'){
        	  	var width = document.body.offsetWidth - 25;
        	  	var height = document.body.offsetHeight;
        	  	
        	  	if(width > 0 && height > 0){
	    			try{
	            	  	var applet = document.getElementById("image");
	            	  	applet.width = width - 25;
	            	  	applet.height = height - 25;
	            	  	applet.style.width = width - 25;
	            	  	applet.style.height = height -25;
	        		}catch(exception){
	        		}
	    			try{
	            	  	var applet_em = document.getElementById("image-em");
	            	  	applet_em.width = width;
	            	  	applet_em.height = height;
	            	  	applet_em.style.width = width;
	            	  	applet_em.style.height = height;
	        		}catch(exception){
	        		}
        		}
    	  	}
    		J2SE_EXISTS=null;
		}catch(exception){
			alert(exception);
		}
	}
	
}

