/* CLASE PARA COMPROBAR LA CONFIGURACION DEL CLIENTE PARA LA EJECUCION CORRECTA DEL APPLET */
var ie_appminVersion = "4";
var ieBrowser_minVersion="6.0";
var ie_downloadUrl="http://www.microsoft.com/windows/ie/ie6/downloads/critical/ie6sp1/default.mspx";
var ffox_appminVersion="5";
var ffox_browserName="Mozilla Firefox";
var ffoxBrowser_minVersion="2.0.0.3";
var ffox_downloadUrl="http://www.mozilla-europe.org/es/products/firefox/";
var jre_minVersion="1.4.2";
var jre_downloadUrl="";


function JavaRequirements() {
    this.browserName="";
    this.browserVersion="";
    this.browserNeedsUpdate=false;
    this.ie_downloadUrl=ie_downloadUrl;
    this.ffox_downloadUrl=ffox_downloadUrl;
    this.javaEnabled=false;
    this.activeXEnabled=true;
    this.javaVersion="";
    this.javaNeedsUpdate=false;
    this.javaDownloadUrl="";
    this.comments="";

}

function WriteApplet(url){
    var object='<OBJECT id="myApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "1" HEIGHT = "1" codebase="' + url + '/test/plugins/j2re-1_4_2-windows-i586.exe#Version=1,4,2,0">';
            object += '<PARAM NAME="code" VALUE = "org.me.plugin.DetectPluginApplet.class">';
            object += '<PARAM NAME="cache_archive" VALUE="' + url + '/test/Ld.jar">';
            object += '<PARAM NAME="cache_version" VALUE="1.0.0.0">';
            object += '<param name="mayscript" value="true">';
            object += '<PARAM NAME="scriptable" VALUE="true">';
            object += '<COMMENT><EMBED type="application/x-java-applet;version=1.4.2" width="1" ';
            object += ' height="1" align="baseline" code="org.me.plugin.DetectPluginApplet.class" cache_archive="' + url + '/test/Ld.jar" cache_version="1.0.0.0" ';
            object += ' pluginspage="' + url + '/test/plugins.html" MAYSCRIPT = "true" scriptable="true" >';
            object += '<NOEMBED>No Java 2 SDK, Standard Edition v 1.4.2 support for APPLET!!</NOEMBED></EMBED></COMMENT></OBJECT>';
            document.writeln(object);
}

function CheckJavaRequirements(){

    var JReq = new JavaRequirements;
    JReq.browserName=navigator.appName;

    var agt=navigator.userAgent.toLowerCase();
    //alert(agt);
    
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
       
    var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_ffox = (is_nav && (is_major == ffox_appminVersion)); 
   
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (is_major == ie_appminVersion));

    var version="";
    if (is_ie){
        var ie_version=Trim(agt.substring(agt.indexOf("msie")+4,agt.indexOf(";",agt.indexOf("msie"))));
        var is_ieValidVersion=(ie_version >= ieBrowser_minVersion);
        version=ie_version;
    }
    else if (is_ffox){
        var ffox_version=Trim(agt.substring(agt.indexOf("firefox/")+8,agt.length));
        var is_ffoxValidVersion=(ffox_version >= ffoxBrowser_minVersion);
        version=ffox_version;
        JReq.browserName=ffox_browserName;
    }
    else if (is_nav){
        version=agt;
    }
 
    JReq.browserVersion=version;
    
    JReq.browserNeedsUpdate=((is_nav && !is_ffoxValidVersion) || (is_ie && !is_ieValidVersion));
   
    var javaVersionDetected="";
    
        // we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
        if(is_nav) {     
        
            // Refresh 'navigator.plugins' to get newly installed plugins.
            // Use 'navigator.plugins.refresh(false)' to refresh plugins 
            // without refreshing open documents (browser windows)
            if(navigator.plugins) { 
                    navigator.plugins.refresh(false);
            }

            // check for Java plugin in installed plugins
            if(navigator.mimeTypes) {
                JReq.javaEnabled=(navigator.mimeTypes['application/x-java-jnlp-file']!=undefined);
            }

        if (JReq.javaEnabled) {
                javaVersionDetected=java.lang.System.getProperty("java.version");
            } 
           
      
        } else if (is_ie) {
        
            var jVersion="";
            var shell;

            JReq.javaEnabled=true;

            try {
                // Create WSH(WindowsScriptHost) shell, available on Windows only
                shell = new ActiveXObject("WScript.Shell");

                if (shell != null) {
                    // Read JRE version from Window Registry
                    try {
                        //alert('tengo activex');
                        jVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Web Start\\CurrentVersion");
                    } catch(e) {
                        // handle exceptions raised by 'shell.regRead(...)' here
                        // so that the outer try-catch block would receive only
                        // exceptions raised by 'shell = new ActiveXObject(...)'
                    }
                } 
            } catch(e) {
                // Creating ActiveX controls thru script is disabled 
                // in InternetExplorer security options 

                // To enable it: 
                // a. Go to the 'Tools --> Internet Options' menu
                // b. Select the 'Security' tab
                // c. Select zone (Internet/Intranet)
                // d. Click the 'Custom Level..' button which will display the
                // 'Security Settings' window.
                // e. Enable the option 'Initialize and script ActiveX controls not marked as safe'
                
                JReq.activeXEnabled=false;
                //alert('no activeX');
            };
            if (jVersion==""){
                var mapplet = document.getElementById("myApplet");
                if (mapplet == null){
                    alert('empieza');
                     setTimeout("void(0)",5000);
                     alert('termina');
                }
                //alert('tengo el applet');
                mapplet = document.getElementById("myApplet");
                if (mapplet != null){
                    try {
                        jVersion=mapplet.getJavaVersion();
                    } catch(e) {
                        //El applet puede que no se haya iniciado aun pq este ejecutando la instalación del JRE
                        //Esperamos 5 segundos por si no le ha dado tiempo a iniciarse y reintentamos
                        setTimeout("void(0)",5000);
                        try{
                            jVersion=mapplet.getJavaVersion();
                        } catch(e){
                        }
                    }
                }
            }
           javaVersionDetected=jVersion; 
        } 
        

    JReq.javaVersion=javaVersionDetected;
    JReq.javaNeedsUpdate=(javaVersionDetected < jre_minVersion);
    //alert('JavaVersionDetected: ' + javaVersionDetected);
    //alert('jre-minVersion: ' + jre_minVersion);
    return JReq;
}
function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}
function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}
function Trim(s){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(s));
}


