// UnlimitedFTP script file.  Simply include this file as a script in your own personal page.
// <script language="javascript" src="uftpscript.js"></script> is the only code you will need
// to add to your page.  Just make sure that uftpscript.js is in the same directory as you page.

// Use these Javascript variables to control the applet parameters

var numkeys 			= 5; // The number of keys you have
var keys= new Array(numkeys);

// Enter you keys here in the following form, starting with key[0], key[1], key[2], etc...
 
keys[0]				= "4B8413FA641DB3B1B0BBD0D4D56FFE04E608A3"; 

// Un-comment the folowing lines to add additional keys

keys[1]				= "D3BA40CF56A240697173C612A2819163A0AA93";
keys[2]				= "D33D96E1F29818C8F073EEE21E1B7DA6081293";
keys[3]				= "6B0F99A9FD51AF95387B410F1AC89652C84C73";
keys[4]				= "3B1A1773D418921846D3C23F706F6940C18F3B"; 



var forcePlugin = false;	//  force IE to load with Sun's Java Plugin

// Connection related values
		
var server 			= "";
var port 			= "21";
var user 			= "";
var pass 			= "";
var autoconnect			= "";
var passive 			= "true";
var connecttimeout		= "";
var sotimeout			= "";

var characterEncoding 		= "";

// Proxy related settings for IE only

var autodetectproxy		= "";
var socksproxy			= "";
var socksProxyHost		= "";
var socksProxyPort		= "";
var ftpproxy			= "";
var ftpProxyHost		= "";
var ftpProxyPort		= "";

//get current time and lock the user to a new dir on the ftp server
currentTime = new Date();
var timestr = "dem"+currentTime.getMonth()+1+""+currentTime.getDate()+""+currentTime.getHours()+""+currentTime.getMinutes();
var createdirectoryonconnect	= timestr;
var lockinitialdir		= "true";

// Functionallity related values

var ascbin			= "";
var remotedir 			= "";
var localdir 			= "";
var helplocation	    	= "uftplite_documentation.html";

// Values that effect the color of the client

var background 			= "";	 
var buttonTextColorOnMouseOver	= "";	
var buttonTextColor		= "";
var buttonColorOnMouseOver	= "";
var buttonbackground		= "";
var headerTextColor		= "";
var headerBackgroundColor	= "";
var drivesForegroundColor 	= "";
var drivesBackgroundColor 	= "";
var ascBinTextColor 		= "";

// values that effect the interface layout of the client

var language 			= "";
var width			= "560";
var height			= "440";


// some customizable error pages

var rejectPermissionURL = "rejectPerms.html";
var errNavWin 		= "errNavWin.html";
var errIEWin 		= "errIEWin.html";
var errIEWinVM		= "errIEWinVM.html";
var errNavUnix		= "errNavUnix.html";
var errIEMac		= "errIEMac.html";
var errNavMac		= "errNavMac.html";
var errOperaWin		= "errOperaWin.html";

//*************************************************************************************** //
// ********** DO NOT EDIT BELOW THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING!  ********* //
//*************************************************************************************** //
var n;

var agt=navigator.userAgent.toLowerCase();

// detect browser version
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// *** BROWSER TYPE ***
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
  && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
  && (agt.indexOf('webtv')==-1));

var is_opera = (agt.indexOf('opera')!=-1);
var is_safari = (agt.indexOf('safari')!=-1);
var is_konqueror = (agt.indexOf('konqueror')!=-1);
var is_opera6up = (is_opera && (is_major >= 6));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6up = (is_nav && (is_major >= 6));
var is_firefox =  (agt.indexOf("firefox") != -1);
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);

// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac   = (agt.indexOf("mac")!=-1);
var is_sun   = (agt.indexOf("sunos")!=-1);
var is_irix  = (agt.indexOf("irix") !=-1);    
var is_hpux  = (agt.indexOf("hp-ux")!=-1);
var is_aix   = (agt.indexOf("aix") !=-1);     
var is_linux = (agt.indexOf("inux")!=-1);
var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
var is_unixware = (agt.indexOf("unix_system_v")!=-1);
var is_mpras    = (agt.indexOf("ncr")!=-1);
var is_reliant  = (agt.indexOf("reliantunix")!=-1);
var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
  (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
  (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
var is_sinix = (agt.indexOf("sinix")!=-1);
var is_freebsd = (agt.indexOf("freebsd")!=-1);
var is_bsd = (agt.indexOf("bsd")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
  is_sco ||is_unixware || is_mpras || is_reliant ||
  is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);
	
function isMacClassic() {
  return (is_mac && !isMacX());
}

function isMacX() {
  if (isMacJaguar()) return true;
  if (agt.indexOf("omniweb") != -1) return true;
  for (var i = 0; i < navigator.plugins.length; i++) {
    if (navigator.plugins[i].name.indexOf("OJI") > -1) return true;
    if (navigator.plugins[i].name.indexOf("Default Plugin Carbon.cfm") > -1) return true;
  }
  return false;
}

function isMacJaguar() {
  return (is_mac && javaPlugin()); // we know java plugin means 10.2 or higher
}

function appletWillRun() {
  if (is_ie4 || is_ie5up || (is_nav4up && is_minor >= 4.08) || is_opera6up || is_konqueror || isMacJaguar())
    return true;
  return false;
}
	

function javaPlugin() {
		
  if (is_safari || is_opera6up || is_konqueror || is_firefox) return true;   // we know safari and opera use java plugin
  for (var i = 0; i < navigator.plugins.length; i++) {
    if (navigator.plugins[i].name.indexOf("Java Plug-in") > -1) return true;
    if (navigator.plugins[i].name.indexOf("Java Embedding Plug") > -1) return true;
  }
  return false;
}

function mrj()  {
  if (isMacX()) return true;
  for (var i = 0; i < navigator.plugins.length; i++) {
    if (navigator.plugins[i].name.indexOf("MRJ") > -1) return true;
  }
  return false;
}



// Set the jar path here

var jar = "unlimitedftplite.jar";
var classname = "unlimited.ftp.UnlimitedFTPLite";
	
var netmac=0;			// netmac = 0 means it is either Mac/IE or non-Mac or Mac Jaguar 
if (is_nav && is_minor < 6 && !isMacJaguar()) {	
  if (javaPlugin() || mrj()) {
    var netmac=1;	// netmac = 1 means this is Mac/Netscape and Netscape is older than 4.76
  } else if (isMacClassic() && !mrj()) {
    var netmac=2;	// this is Mac/Netscape earlier than 4.76 w/o MRJ Plugin
  }
}

if (netmac == 0) {  // This is non-Mac or Mac with IE 
  if ((!navigator.javaEnabled()) && !is_mac && (navigator.appName=="Netscape") && (parseInt(navigator.appVersion)>=5)){
    document.write("<p><b>Error Java Disabled!</b></p>");
    document.write("<p>To enable Java in Netscape 6:</p>");
    document.write("<p>- Go to Edit - Preferences<br>- Click on Advanced<br>- Check \"Enable Java\"<br>- Reload this page</p>");
  }

  if (appletWillRun()) {
    if (is_ie && !isMacJaguar() && forcePlugin)
      document.write("<OBJECT name=UnlimitedFTP classid='clsid:8AD9C840-044E-11D1-B3E9-00805F499D93' height="+height+" width="+width+"'>");
    else
      document.write("<APPLET name=UnlimitedFTP code="+classname+".class height="+height+" archive="+jar+" width="+width+" MAYSCRIPT VIEWASTEXT>");
    document.write("<param name='archive' value='"+jar+"'>");
    document.write("<param name='code' value='"+classname+".class'>");
    document.write("<PARAM NAME='type' VALUE='application/x-java-applet;version=1.3'>");
    document.write("<PARAM NAME='server' VALUE='"+server+"'>");
    document.write("<PARAM NAME='port' VALUE='"+port+"'>");
    document.write("<PARAM NAME='pass' VALUE='"+pass+"'>");
    document.write("<PARAM NAME='user' VALUE='"+user+"'>");
    document.write("<PARAM NAME='autoconnect' VALUE='"+autoconnect+"'>");
    document.write("<PARAM NAME='ascbin' VALUE='"+ascbin+"'>");
    document.write("<PARAM NAME='passive' VALUE='"+passive+"'>");
    document.write("<PARAM NAME='remotedir' VALUE='"+remotedir+"'>");
    document.write("<PARAM NAME='localdir' VALUE='"+localdir+"'>");
    document.write("<PARAM NAME='background' VALUE='"+background+"'>");
    document.write("<PARAM NAME='buttonTextColorOnMouseOver' VALUE='"+buttonTextColorOnMouseOver+"'>");
    document.write("<PARAM NAME='buttonTextColor' VALUE='"+buttonTextColor+"'>");
    document.write("<PARAM NAME='buttonColorOnMouseOver' VALUE='"+buttonColorOnMouseOver+"'>");
    document.write("<PARAM NAME='headerTextColor' VALUE='"+headerTextColor+"'>");
    document.write("<PARAM NAME='headerBackgroundColor' VALUE='"+headerBackgroundColor+"'>");
    document.write("<PARAM NAME='drivesForegroundColor' VALUE='"+drivesForegroundColor+"'>");
    document.write("<PARAM NAME='drivesBackgroundColor' VALUE='"+drivesBackgroundColor+"'>");
    document.write("<PARAM NAME='ascBinTextColor' VALUE='"+ascBinTextColor+"'>");
    document.write("<PARAM NAME='buttonbackground' VALUE='"+buttonbackground+"'>");
    document.write("<PARAM NAME='language' VALUE='"+language+"'>");
    document.write("<PARAM NAME='helplocation' VALUE='"+helplocation+"'>");
    document.write("<PARAM NAME='errIEWinVM' VALUE='"+errIEWinVM+"'>");
    document.write("<PARAM NAME='rejectPermissionURL' VALUE='"+rejectPermissionURL+"'>");
    document.write("<PARAM NAME='autodetectproxy' VALUE='"+autodetectproxy+"'>");
    document.write("<PARAM NAME='socksproxy' VALUE='"+socksproxy+"'>");
    document.write("<PARAM NAME='socksProxyHost' VALUE='"+socksProxyHost+"'>");
    document.write("<PARAM NAME='socksProxyPort' VALUE='"+socksProxyPort+"'>");
    document.write("<PARAM NAME='ftpproxy' VALUE='"+ftpproxy+"'>");
    document.write("<PARAM NAME='ftpProxyHost' VALUE='"+ftpProxyHost+"'>");
    document.write("<PARAM NAME='ftpProxyPort' VALUE='"+ftpProxyPort+"'>");
    document.write("<PARAM NAME='sotimeout' VALUE='"+sotimeout+"'>");
    document.write("<PARAM NAME='connecttimeout' VALUE='"+connecttimeout+"'>");
    document.write("<PARAM NAME='characterEncoding' VALUE='"+characterEncoding+"'>");
    for (n=0; n < numkeys; n++)
      document.write("<PARAM NAME='key"+(n+1)+"' VALUE='"+keys[n]+"'>");
										
    //if Java is disabled show an error message
    document.write("<center><table width='90%' border='1' bordercolor='#000000'>");
    document.write("<tr>");
    document.write("<td bgcolor='#336633'>");
    document.write("<div align='center'><font color='#FFFFFF'>Java is Disabled!</font></div>");
    document.write("</td>");
    document.write("</tr>");
    document.write("<tr>");
    document.write("<td>");
    document.write("<table width='100%' border='0' cellpadding='0' cellspacing='20'>");
    document.write("<tr>");
    document.write("<td width='3%'><img src='error.gif' width='61' height='61'></td>");
    document.write("<td width='97%'>");
    document.write("<p>You must enable Java in your browser in order to upload files.</p>");
    if (document.all) {
      document.write("<p><b>To enable Java in Internet Explorer:</b></p>");
      if (is_win)
        document.write("<p>- Go to Tools - Internet Options<br>- Click on the Security Tag<br>- Select Medium Security Level for Internet Zone<br>- Reload this page</p>");
      else if (is_mac)
        document.write("<p>- Go to Edit - Preferences<br>- Click on Java<br>- Check \"Enable Java (Apple MRJ)\"<br>- Reload this page</p>");
    }
    else if (document.layers) {
      document.write("<p><b>To enable Java in Netscape Navigator 4.X:</b></p>");
      document.write("<p>- Go to Edit - Preferences<br>- Click on Advanced<br>- Check \"Enable Java\"<br>- Reload this page</p>");
    }
    else if (is_opera) {
      document.write("<p><b>To enable Java in Opera:</b></p>");
      document.write("<p>- Go to File - Preferences<br>- Click on Multimedia<br>- Check \"Enable Java\"<br>- Reload this page</p>");
    }
    document.write("</td>");
    document.write("</tr>");
    document.write("</table>");
    document.write("</td>");
    document.write("</tr>");
    document.write("</table></center>");
    //end of error message

    document.write("</APPLET>");

  } else if (!appletWillRun()) {
    if (is_nav && is_win)  {
      window.location.href=errNavWin;
    }
    else if (is_ie && is_win) {
      window.location.href=errIEWin;
    }
    else if (is_nav && is_unix) {
      window.location.href=errNavUnix;
    }
    else if (is_ie && is_mac) {
      window.location.href=errIEMac;
    }
    else if (is_opera) {
      window.location.href=errOperaWin;
    }
  }
}  // end non-Mac code
else if (netmac==1){ //It's Netscape use the embed tag instead!
  if (is_mac)
    document.writeln("<EMBED  TYPE = 'application/x-java-vm' name='UnlimitedFTP' PLUGINSPAGE = 'http://www.mozilla.org/oji/' BORDER='0' code='"+classname+".class' height='"+height+"' width='"+width+"' archive='"+jar+"' ");
  else
    document.writeln("<EMBED TYPE = 'application/x-java-applet;version=1.3' name='UnlimitedFTP' PLUGINSPAGE = 'http://java.sun.com/getjava/' BORDER='0' java_CODE='"+classname+"' height='"+height+"' width='"+width+"' java_CODEBASE = . java_ARCHIVE='"+jar+"' ");
  document.writeln("");
  document.writeln("server='"+server+"'");
  document.writeln("port='"+port+"'");
  document.writeln("pass='"+pass+"'");
  document.writeln("user='"+user+"'");
  document.writeln("autoconnect='"+autoconnect+"'");
  document.writeln("ascbin='"+ascbin+"'");
  document.writeln("passive='"+passive+"'");
  document.writeln("remotedir='"+remotedir+"'");
  document.writeln("localdir='"+localdir+"'");
  document.writeln("background='"+background+"'");
  document.writeln("buttonTextColorOnMouseOver='"+buttonTextColorOnMouseOver+"'");
  document.writeln("buttonTextColor='"+buttonTextColor+"'");
  document.writeln("buttonColorOnMouseOver='"+buttonColorOnMouseOver+"'");
  document.writeln("headerTextColor='"+headerTextColor+"'");
  document.writeln("headerBackgroundColor='"+headerBackgroundColor+"'");
  document.writeln("drivesForegroundColor='"+drivesForegroundColor+"'");
  document.writeln("drivesBackgroundColor='"+drivesBackgroundColor+"'");
  document.writeln("ascBinTextColor='"+ascBinTextColor+"'");
  document.writeln("buttonbackground='"+buttonbackground+"'");
  document.writeln("language='"+language+"'");
  document.writeln("helplocation='"+helplocation+"'");
  document.writeln("errIEWinVM='"+errIEWinVM+"'");
  document.writeln("rejectPermissionURL='"+rejectPermissionURL+"'");
  document.writeln("autodetectproxy='"+autodetectproxy+"'");
  document.writeln("socksproxy='"+socksproxy+"'");
  document.writeln("socksProxyHost='"+socksProxyHost+"'");
  document.writeln("socksProxyPort='"+socksProxyPort+"'");
  document.writeln("ftpproxy='"+ftpproxy+"'");
  document.writeln("ftpProxyHost='"+ftpProxyHost+"'");
  document.writeln("ftpProxyPort='"+ftpProxyPort+"'");
  document.writeln("sotimeout='"+sotimeout+"'");
  document.writeln("connecttimeout='"+connecttimeout+"'");
  document.writeln("characterEncoding='"+characterEncoding+"'");
  for (n=0; n < numkeys; n++)
    document.write("key"+(n+1)+"='"+keys[n]+"'");
  document.writeln(">");
}
else if (netmac==2) {//Netscape doesn't have the MRJ Plugin.
  window.location.href=errNavMac;
}

