var jar_cache_files    = "wp.jar"  + ",basic_ui.jar" + ",text_ui.jar" + ",utilities.jar" + ",filesystem.jar" + ",msgHandlers.jar";
var jar_cache_versions = "2.0.0.6" + ",2.0.0.3"      + ",2.0.0.3"     + ",2.0.0.4"       + ",2.0.0.4"        + ",2.0.0.1";
var _info = navigator.userAgent;
var _ns = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
if(_info.indexOf("Opera")>=0){
   _ie=false;
   _ns=true;
}
else if(_ie==false){
  _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 /*&& java.lang.System.getProperty("os.version").indexOf("3.5") < 0*/) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0)));
}

var jarBase='.';
function setJarBase(base){
   jarBase=base;
}

var useLanguage=false;
var language='';
var country='';
var variant='';
function setLanguage(l, c, v){
   if(l!=null){
     language=l.toString();
     if(c!=null) country=c.toString();
     if(v!=null) variant=v.toString();
     useLanguage=true;
   }
}

var useCookie=false;
var cookie='';
function setCookie(){
   if(document.cookie!=null && document.cookie.length>0){
     cookie=document.cookie;
     useCookie=true;
   }
}

var useHost=false;
var host='';
function setHost(text){
   if(text!=null){
     host=text.toString();
     useHost=true;
   }
}

var useUser=false;
var user='';
function setUser(text){
   if(text!=null){
     user=text.toString();
     useUser=true;
   }
}

var usePwd=false;
var pwd='';
function setPwd(text){
   if(text!=null){
     pwd=text.toString();
     usePwd=true;
   }
}

var useExit=false;
var exit='';
function setExit(text){
   if(text!=null){
     exit=text.toString();
     useExit=true;
   }
}

var usePasv=false;
var pasv=false;
function setPasv(text){
   if(text!=null){
     pasv=text.toString();
     usePasv=true;
   }
}

function writePlugin(width, height, rWidth, rHeight){

   var w=width.toString();
   var h=height.toString();
   var nsw=w;
   var nsh=h;
   if(rWidth!=null) w=rWidth.toString();
   if(rHeight!=null) h=rHeight.toString();

   if (_ie == true){
      document.writeln(
        '<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"' +
        ' WIDTH="' +w+ '" HEIGHT="' +h+ '">');
      document.writeln('<PARAM NAME=CODE VALUE="edu.xtec.jquadern.WPApplet">');
      document.writeln('<PARAM NAME=CODEBASE VALUE="' +jarBase+ '">');
   	document.writeln('<PARAM NAME=ARCHIVE VALUE="wpApplet.jar">');
      writeCacheInfo(true);
      document.writeln('<PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.3.1">');
      document.writeln('<PARAM NAME="scriptable" VALUE="false">');
      writeParams(true);
      writeDownloadPageInfo();
      document.writeln('</OBJECT>');
   }
   else if (_ns == true){
      document.write(
        '<EMBED type="application/x-java-applet;version=1.3"'+
        ' CODE="edu.xtec.jquadern.WPApplet" CODEBASE="' +jarBase+ '" ARCHIVE="wpApplet.jar"'+
        ' WIDTH="' +nsw+ '" HEIGHT="' +nsh +'" ');
      writeCacheInfo(false);
      writeParams(false);
      document.writeln(
        ' scriptable=false'+
        ' pluginspage="http://www.xtec.cat/recursos/clic/jclic/instal_plugin.htm">');
      document.writeln('<NOEMBED>');
      writeDownloadPageInfo();
      document.writeln('</NOEMBED>');     
   }
   else{
     document.write('<APPLET CODE="edu.xtec.jquadern.WPApplet" CODEBASE="' +jarBase+ '"');
     document.write(' ARCHIVE="wpApplet.jar,'+ jar_cache_files +'"');
     document.writeln(' WIDTH="' +nsw+ '" HEIGHT="' +nsh+ '">');
     document.writeln('<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">');
     document.writeln('<PARAM NAME="scriptable" VALUE="false">');
     writeParams(true);
     document.writeln('</APPLET>');
  }
}

function writeCacheInfo(p){
  if(p){
    document.writeln('<PARAM NAME="cache_option" VALUE ="Plugin">');
    document.writeln('<PARAM NAME="cache_archive" VALUE ="' +jar_cache_files+ '">');
    document.writeln('<PARAM NAME="cache_version" VALUE ="' +jar_cache_versions+ '">');
  }else{
    document.write(' cache_option="Plugin"');
    document.write(' cache_archive="' +jar_cache_files+ '"');
    document.write(' cache_version="' +jar_cache_versions+ '"');
  }
}

function writeDownloadPageInfo(){
    document.writeln(
    '<FONT FACE="Verdana,Arial,Helvetica" COLOR="white">'+
    '<B>Aquesta aplicació necessita el plug-in Java 1.3.1</B><BR>&nbsp;<BR>'+
    '<A HREF="http://www.xtec.cat/recursos/clic/jclic/instal_plugin.htm"><IMG SRC="boto_plugin.gif" WIDTH="200" HEIGHT="40" BORDER="0" ALT="instal.lar el plugin"></A><BR>'+
    '</FONT>');
}

function writeParams(p){  
  if(useLanguage){
    if(p){
      document.writeln('<PARAM NAME="language" VALUE="' +language+ '">');
      document.writeln('<PARAM NAME="country" VALUE="' +country+ '">');
      document.writeln('<PARAM NAME="variant" VALUE="' +variant+ '">');
    }
    else document.write(' language="' +language+ '" country="' +country+ '" variant="' +variant+ '" ');
  }
  if(useCookie){
    if(p) document.writeln('<PARAM NAME="cookie" VALUE="' +cookie+ '">');
    else document.write(' cookie="' +cookie+ '" ');
  }
  if(useUser){
    if(p) document.writeln('<PARAM NAME="user" VALUE="' +user+ '">');
    else document.write(' user="' +user+ '" ');
  }
  if(useHost){
    if(p) document.writeln('<PARAM NAME="host" VALUE="' +host+ '">');
    else document.write(' host="' +host+ '" ');
  }
  if(usePwd){
    if(p) document.writeln('<PARAM NAME="password" VALUE="' +pwd+ '">');
    else document.write(' password="' +pwd+ '" ');
  }
  if(useExit){
    if(p) document.writeln('<PARAM NAME="exit" VALUE="' +exit+ '">');
    else document.write(' exit="' +exit+ '" ');
  }
  if(usePasv){
    if(p) document.writeln('<PARAM NAME="pasv" VALUE="' +pasv+ '">');
    else document.write(' pasv="' +pasv+ '" ');
  }
}

