/*console
	var myUp = new JBatch( { el: 'upclient' } );
	myUp.Insert();
*/
function Uploader( optObj ){
	var self = this;
	UC = this;
	self.options={
		protocol: false,			// reqd HTTP of FTP auto switch from http to https
		mode: false,				// sets ftp default upload mode Active or Passive
		process: false,				// reqd what backend process to use
		optsel: false,				// div to insert an options form
		user: false,				// sets user name -- reqd ftp 
		password: false,			// password for login -- reqd ftp
		host: false,				// host to upload file -- reqd ftp
		basepath: false,			// directory to upload files -- ftp only
		messagefile: false,			// ftp only html file presented once loaded
		el: false,  				// reqd element where client is inserted
		UpOptsEl: false, 			// reqd where to insert the uploader options form
		log : false,  				// if defined function called as loading progresses
		InsertComplete : false, 	// if defined is called once applet is loaded
		UploadComplete : false,		// if defined is called once Upload completes
		LogEachFileUpLoad: false,	// if defined calls log( filename ) for every file uploaded
		LogEachAddRemove : false	// if defined callse log( ) eachtime the qty of files changes
	};
	
	for (var p in optObj) { self.options[p] = optObj[p]; }
	
	if( optObj.protocol == 'WEB' ){ 
		if( window.PluginDetect ){  // check if java installed and get version
			var jv = PluginDetect.getVersion('java', '/_sd/js/getJavaInfo.jar');
			
			if( ! jv ){
				this.options.LogEachFileUpLoad = true;
				this.client = new JSMultiup( optObj );
				}else{
				this.client = new JBatch( optObj );
				}
			}else{  // no plugin detection just blindly load java
			this.client = new JBatch( optObj ); 
			}
		}
	if( optObj.protocol == 'bWEB' ){  //bWEB forces browser based javascript file upload			
		this.options.LogEachFileUpLoad = true;
		this.client = new JSMultiup( optObj ); 
		}
		
	if( optObj.protocol == 'FTP' ){ this.client = new ThinFile( optObj ); }
	if( ! this.client ){ return( false ); }
	
	this.Log = this.options.log;
	this.Insert = this.client.Insert;
	this.Begin = this.client.Begin;
	this.Passwd = this.client.Passwd;
	this.Url = this.client.Url;
	this.Mode = this.client.Mode;
	this.Remove= this.client.Remove;
	this.InsertComplete = self.options.InsertComplete;
	this.UploadComplete = self.options.UploadComplete;
	this.FilesAttached = function(){ return( self.client.filesAttached ); }
	this.JavaExists=function(){ if( ! navigator.javaEnabled() ){ window.location = '../sd/html/NoJava.htm'; } }
	
	
}

function JBatch( optObj ){
	var self = this;
	
	self.options={};
	/*	el: false,  			// reqd element where client is inserted
		log : false,  			// if defined function called as loading progresses
		afterInsert : false, 	// if defined is called once applet is loaded
		optsel: false, 		// where to insert the uploader options form
	}; */
	
	for (var p in optObj) { self.options[p] = optObj[p]; }
	
	
	this.filesAttached=0;
	this.insertComplete=false;
	this.uploadComplete=false;
	this.backend = document.location.protocol + '//' + document.location.host + "/_sd/php/WebUp.php";
	this.backendpost = document.location.protocol + '//' + document.location.host + "/_sd/php/WebUpPost.php";
	this.codebase = "/_sd/JBatch";
	this.insert = '';
	this.upcount = 0;
	
	this.Insert = function(){
	
		self.el = document.getElementById( self.options.el );
		var awide = self.el.offsetWidth;
		var ahigh = self.el.offsetHeight;
		
		var _info = navigator.userAgent;
		var _ns = false;
		var _ns6 = 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 = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || (_info.indexOf("IRIX") > 0)));
		_ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));

		
		self.insert = '';
		
		if (_ie == true ) {
  			self.insert = '<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ' +
				  				 'WIDTH="' + awide + '" ' +
				  				 'HEIGHT="' + ahigh + '" ' +
  								 'NAME="fileupload" ID="fileupload" '  +
  								 'codebase="' + document.location.protocol + '://java.sun.com/update/1.4.2/jinstall-1_4-windows-i586.cab#Version=1,4,0,0">';
			}
		else if (_ns == true && _ns6 == false) { 
				  // BEGIN: Update parameters below for NETSCAPE 3.x and 4.x support.
				  self.insert = '<EMBED ' +
				  				 'type="application/x-java-applet;version=1.4" ' + "\n" +
								 'JAVA_CODEBASE="' + self.codebase + '" ' + "\n" +
				  				 'CODE="spinnerdog.upload.client.SDApplet.class" ' + "\n" +
								 'ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/batchui.jar,lib/jsapi.jar,lib/sd.jar" ' + "\n" +
				  				 'NAME="fileupload" ' + "\n" +
				  				 'WIDTH="' + awide + '" ' + "\n" +
				  				 'HEIGHT="' + ahigh + '" ' + "\n" +
				  				 'url="' + self.backend + '" ' + "\n" +
				  				 'paramfile="uploadfile" ' + "\n" +
				  				 'param1="todo" ' + "\n" +
				  				 'value1="upload" ' + "\n" +
				  				 'param2="errorheader" ' + "\n" +
				  				 'value2="custommessage" ' + "\n" +
				  				 'param3="relativefilename" ' + "\n" +
				  				 'folderdepth="-1" ' + "\n" +
								 'retry="10" ' + "\n" +
				  				 'transferui="jfileupload.transfer.client.edesign.BatchTransferUI" ' + "\n" +
				  				 'transferuiresources="' + self.codebase + '/i18n_pane" ' + "\n" +
				  				 'resources="' +  self.codebase + '/i18n_bar" ' + "\n" +
				  				 'resetprogressbar="true" ' + "\n" +
				  				 'mode="http" ' + "\n" +
				  				 'scriptable=true ' + "\n" +
				  				 'mayscript=true ' + "\n" +
				  				 'relativefilename="true" ' + "\n" +
								 'post="' + self.backendpost + '" ' + "\n" +
								 'postparameters="extra" ' + "\n" +
				  				 'pluginspage="http://java.sun.com/products/plugin/index.html#download"><NOEMBED>';
  // END
		}
		else {
  			self.insert = '<APPLET CODE="spinnerdog.upload.client.SDApplet.class" JAVA_CODEBASE="' + self.codebase + '" ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/batchui.jar,lib/jsapi.jar,lib/sd.jar" ' +
  							 'WIDTH="' + awide + '" ' + "\n" +
  							 'HEIGHT="' + ahigh + '" ' + "\n" +
  							 'NAME="fileupload" ID="fileupload" MAYSCRIPT>';
				}
		// BEGIN: Update parameters below for INTERNET EXPLORER, FIREFOX, SAFARI, OPERA, MOZILLA, NETSCAPE 6+ support.
					self.insert += '<PARAM NAME=CODE VALUE="spinnerdog.upload.client.SDApplet.class">' + "\n" +
										'<PARAM NAME=CODEBASE VALUE="' + self.codebase + '">' + "\n" +
										'<PARAM NAME=ARCHIVE VALUE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/batchui.jar,lib/jsapi.jar,lib/sd.jar">' + "\n" +
										'<PARAM NAME=NAME VALUE="fileupload">' + "\n" +
										'<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">' + "\n" +
										'<PARAM NAME="scriptable" VALUE="true">' + "\n" +
										'<PARAM NAME="mayscript" VALUE="true">' + "\n" +
										'<PARAM NAME="url" VALUE="' + self.backend + '">' + "\n" +
										'<PARAM NAME="paramfile" VALUE="uploadfile">' + "\n" +
										'<PARAM NAME="param1" VALUE="todo">' + "\n" +
										'<PARAM NAME="value1" VALUE="upload">' + "\n" +
										'<PARAM NAME="param2" VALUE="errorheader">' + "\n" +
										'<PARAM NAME="value2" VALUE="custommessage">' + "\n" +
										'<PARAM NAME="param3" VALUE="relativefilename">' + "\n" +
										'<PARAM NAME="value3" VALUE="true">' + "\n" +
										'<PARAM NAME="folderdepth" VALUE="-1">' + "\n" +
										'<PARAM NAME="retry" VALUE="10">' + "\n" +
										'<PARAM NAME="transferui" VALUE="jfileupload.transfer.client.edesign.BatchTransferUI">' + "\n" +
										'<PARAM NAME="transferuiresources" VALUE="' + self.codebase + '/i18n_pane">' + "\n" +
										'<PARAM NAME="resources" VALUE="' + self.codebase + '/i18n_bar">' + "\n" +
										'<PARAM NAME="resetprogressbar" VALUE="true">' + "\n" +
										'<PARAM NAME="mode" VALUE="http">' + "\n" +
										'<PARAM NAME="post" VALUE="' + self.backendpost + '">' + "\n" +
										'<PARAM NAME="postparameters" VALUE="extra">' + "\n" +
										'<PARAM NAME="param2" VALUE="relativefilename">' + "\n" +
										'<PARAM NAME="value2" VALUE="true">';
					
					
					if( ! ( OAT.Browser.isMac && OAT.Browser.isWebKit ) ){
						self.insert += "\n" + '<PARAM NAME="forcejs" VALUE="false">' + "\n";
						}
					
					if (_ie == true ) {
			  			self.insert += '</OBJECT>';
						}
					else if (_ns == true && _ns6 == false) {
			  		self.insert += '</NOEMBED></EMBED>';
						}
					else {
			  		self.insert += '</APPLET>';
						}	
		 
		// insert the opts form
		if( self.options.optsel ){ 
			var el = document.getElementById( self.options.optsel );
			if( el ){
				el.innerHTML = '<form name="sdUploaderOpts">There are no options for HTTP uploads. <input type="hidden" name="Protocol" value="HTTP" /></form>';
			}
		}	
		
		self.el.innerHTML = self.insert;
		
	}
	
	this.Passwd = function(){
		
		var u = SDForm.Settings.getElementsByTagName( 'Upload' )[0];
		if( ! u ){ return; }
		var pass = u.getAttribute( 'Pass' );
	
		if( pass.match( /:/ ) ){
		    var frm = pass.replace( /:.*$/, '' );
		    var ele = pass.replace( /^.*:/, '' );
		    pass = document.forms[ frm ].elements[ ele ].value;
		    pass = pass.replace(/^\s+|\s+$/g, "");
		    pass = pass.replace( /@/, '%40' );
			pass = pass.replace( /^.*</, '');
  			pass = pass.replace( />.*$/, '' );
		  	}
		  	
		return( pass );
	
	}
	
	this.Url = function(){ return(  this.backend ); }
	this.Mode = function(){ return( '' );	}
	this.Begin = function( OrdNo ){
		UC.client.upcount = 0;
		
		document.fileupload.putParameter( 'jno', OrdNo );
		document.fileupload.putParameter( 'sdproc', self.options.process );
		document.fileupload.putParameter( 'filesAttached', self.filesAttached );

		document.fileupload.startUpload();
	}
	
	this.Remove=function(){ if( self.el ){ self.el.innerHTML = ''; } }
	
}

function JSAppletInitialized(version){ UC.client.insertComplete = true;if( UC.InsertComplete ){ UC.InsertComplete(); } }	
function JSTransferTriggered(filelist){ return; for( var i = 0; i <= filelist.length; ++i ){ console.log( filelist.name ); } }
function JSTransferStarted(filename, filesize){ }
function JSTransferCompleted(filename){ UC.client.upcount += 1; if( UC.Log && UC.options.LogEachFileUpLoad){  UC.Log( "sent " + filename + ' ' + UC.client.upcount + ' of ' + UC.client.filesAttached +  '<br>' ); } }
function JSTransferCancelled(){ }
function JSTransferFailed(errormsg){ UC.Log( "Error: " + errormsg + '<br>' ); }
function JSCompressStarted(filename, filesize){ }
function JSCompressCompleted(zipfilename, zipfilesize){ }
function JSCompressCancelled(){ }
function JSCompressFailed(errormsg){}
function JSSplitTriggered(filename, size, chunksize, amount){ }
function JSSplitStarted(chunkid, chunksize){}
function JSSplitCompleted(chunkid){ }
function JSSplitFailed(chunkid, errormsg){ }
function JSFilterStarting(filename){ }
function JSFilterStarted(filename){ }
function JSFilterCompleted(filteredfilename){ }
function JSFilterFailed(errormsg){ }
function JSChecksumStarted(type){ }
function JSChecksumCompleted(checksum){ }
function JSSelectionInfo( amount, size )
{
	amount > 0 ? UC.client.filesAttached = parseInt( amount ) : UC.client.filesAttached = 0;
	if( UC.Log && UC.LogEachAddRemove ){ UC.Log( "Files Selected=" + amount + " Size=" + size + '<br>' );   }
}

function JSTransferDone( filelist )
{ 
	if( UC.client.upcount === UC.client.filesAttached ){
		UC.Log( 'Uploading Complete' );
		UC.UploadComplete();
	}else{
		var dif = (UC.client.filesAttached - UC.client.upcount);
		UC.UploadComplete( dif + ' of ' + UC.client.filesAttached + ' files failed to upload.  This is usually caused by network errors.  Please click the refresh button try again and if the problem persists have your network admin investigate.' );
	}
	return;
} 


function JSMultiup(optObj){
	var self=this;
	self.options = {
		FormDivHeight: '40px'
		};
	this.backend = document.location.protocol + '//' + document.location.host + "/_sd/php/WebUp.php";
	
	for (var p in optObj) { self.options[p] = optObj[p]; }
	this.el = $( self.options.el );
	
	
	// Sferragne: Create a  status to the form so we prevent double submits.
	this.uploading = 0; 
	///////////////////////
	
	this.mkinput = function mkinput(n,v){
		var inp = OAT.Dom.create( 'input' ); 
		inp.type = 'hidden';
		inp.value = v;
		inp.name= n;
		return( inp );
	}
			
	this.AddFiForm = function(){
		
		var fif = {};
		fif.frm = OAT.Dom.create( 'form' );
		if( OAT.Browser.isIE ){
			fif.frm.getAttributeNode("enctype").value = "multipart/form-data";
			fif.frm.getAttributeNode("method").value = "POST";
		}else{
			fif.frm.method='POST';
			fif.frm.enctype='multipart/form-data';
		}
		
		fif.frm.action =this.backend;
		fif.frm.isempty = function(){ return true };
		
		fif.fi = OAT.Dom.create( 'input', '' ); 
		fif.fi.type = 'file';
		fif.fi.name = 'uploadfile';
		OAT.Dom.append( [ fif.frm, fif.fi ] );
		
		fif.fi.onchange=function(){
			
			//Validation
			for( var i=0;i<self.Files.length - 1;++i){
				if( self.Files[i].fi.value == this.value ){
					alert( 'A file named ' + this.value + ' has already been selected.' );
					this.value = '';
					return;
					}
				}
				
			//Validation
			if( self.options.max ){
				if( self.files.length >= self.options.max + 1 ){
					alert( 'Cant add file.  A maximum of ' + self.options.max + ' can be attached.' );
					this.value = '';
					return;
					}
				}
			
				this.le = OAT.Dom.create( 'div', '', 'multiup_fe' );
				var rmclick = OAT.Dom.create( 'span', '', 'multiup_rmfile' );
				rmclick.innerHTML = '&nbsp';
				this.label=OAT.Dom.create('span','','multiup_label');
				this.filename = this.value.replace( /^.*\\/, '' );
				
				OAT.Dom.append( [ this.le, rmclick, OAT.Dom.text( this.filename ), this.label  ] );
				OAT.Dom.append( [ self.ListDiv, this.le ] );
				
				rmclick.onclick=function(){ 
						var fn = this.nextSibling.textContent ? this.nextSibling.textContent : this.nextSibling.nodeValue;
						for( var i = 0; i < self.Files.length; ++i ){
							if( self.Files[i].fi.value.match( fn ) ){
								self.Files.splice( i, 1 );
								break;
								}
							}
						OAT.Dom.unlink( this.parentNode );
						}
				
			OAT.Dom.hide( this.form );
			self.filesAttached = self.Files.length;
			self.AddFiForm();
			}
		
		OAT.Dom.append( [ self.FormDiv, fif.frm ] );
		fif.unlist = function(){ OAT.Dom.unlink( this.fi.le ); }
		self.Files.push( fif );
		}
	
	this.RmFile = function(index){
		self.Files[index].unlist();
		if( self.Files[index].frame ){ OAT.Dom.unlink( self.Files[index].frame ); }
		self.Files.splice( index, 1 );
		self.filesAttached = self.Files.length;
		}

	this.Insert=function(){
		self.Files = new Array();
		self.filesAttached = 0;
		var elwh = OAT.Dom.getWH( self.el );
		self.ListDiv = OAT.Dom.create( 'div', { height: ( elwh[1] - 40 ) + 'px' }, 'multiup_listdiv' );
		self.FormDiv = OAT.Dom.create( 'div', { height: self.options.FormDivHeight }, 'multiup_formdiv' );
		OAT.Dom.append( [ self.el, self.ListDiv, self.FormDiv] );
		self.AddFiForm();
		if( !UC.client.insertComplete ){ UC.client.insertComplete = true;if( UC.InsertComplete ){ UC.InsertComplete(); } }
		}
		
	this.Remove=function(){
		self.el.innerHTML = '';
		}
	
	this.sendNextFile=function(){
		
		if( this.Files.length > 1 ){
			this.uploading = true;
			this.Files[0].fi.label.innerHTML = '<img src="/_sd/images/indicator_snake.gif" />';
			if( UC.Log && UC.options.LogEachFileUpLoad){ UC.client.upcount += 1; UC.Log( "Uploading " + self.Files[0].fi.filename + ' ' + UC.client.upcount + ' of ' + UC.client.filesAttached +  ' ' ); }
			this.Files[0].frm.submit();
			}
		else{
			this.uploading = false;
			UC.Log( 'Uploading Complete' );
			UC.UploadComplete();
		}
			
		}
		
	this.xferComplete=function(){
		this.uploading = false;
		if( UC.Log && UC.options.LogEachFileUpLoad){  UC.Log(  self.Files[0].fi.filename + " complete.</br>"  ); }
		this.RmFile( 0 );
		this.sendNextFile();
		}
		
	this.Begin = function( OrdNo ){
		
			
		for( var i=0; i < self.Files.length-1; ++i ){
		
			//Create IFrame 
			try {
				self.Files[i].frame = document.createElement('<iframe style="display:none" name="target_if_' +i+ '">');
				} catch (ex) {
				self.Files[i].frame = OAT.Dom.create( 'iframe', { display: 'none' } );
				}
			
			self.Files[i].frame.name = "target_if_"+i;
			self.Files[i].frame.id = "target_if_"+i;
			
			//Add to the body
			OAT.Dom.append( [ document.body, self.Files[i].frame ] );
			
			self.Files[i].frm.target = "target_if_"+i;
			var f = self.Files[i].frm;
			f.appendChild( self.mkinput( 'jno', OrdNo ) );
			f.appendChild( self.mkinput( 'sdproc', self.options.process ) );
			f.appendChild( self.mkinput( 'filesAttached', self.filesAttached ) );
			f.appendChild( self.mkinput( 'todo', 'upload' ) );
			f.appendChild( self.mkinput( 'respondwith', 'UC.client.xferComplete();' ) );
			}
		self.upcount = 0;
		self.sendNextFile();
		}
	
	
}


function ThinFile( optObj ){
	var self = this;

	self.options={
		el: false,  				// reqd element where client is inserted
		password: false,			// reqd for FTP can contain FormName:FieldName
		log : false,  				// if defined function called as loading progresses
		afterInsert : false, 		// if defined is called once applet is loaded
		messageUrl : false,			// html file that is displayed once applet is loaded
		UpOptsEl: false, 			// where to insert the uploader options form
		XMLSettingsDoc: false		// reqd pointer to XML config settings
	};
	
	for (var p in optObj) { self.options[p] = optObj[p]; }
	this.el = document.getElementById( self.options.el );
	this.filesAttached=0;
	this.insertComplete=false;
	this.uploadComplete=false;
	
	this.Insert=function(){
		self.el = document.getElementById( self.options.el );
		var awide = self.el.offsetWidth;
		var ahigh = self.el.offsetHeight;
		var _info = navigator.userAgent;
  		var ie = (_info.indexOf("MSIE") > 0);
  		var win = (_info.indexOf("Win") > 0);
  		var WebUrl = document.location;
  		var propsfile = document.location.protocol + "//" + document.location.host  + '/_sd/ThinFile/thinupload.properties';
  		var messagefile = self.options.messagefile ? document.location + self.options.messagefile : '';
  		self.insert = '';
  		 
  		if(win){

			if(ie){
	           self.insert = '<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ' +
	            				'width= "' + awide + '" height= "' + ahigh + '" id="rup"' +
	            				'codebase=' + document.location.protocol + '"//java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#version=1,4,1">' +
	            				'<param name="cache_archive" value="/_sd/ThinFile/ThinFTPUpload.jar">' +
	            				'<param name="code" value="com.thinfile.upload.ThinFTPUpload">' +
	           					'<param name="props_file" value="' + propsfile + '">' +
	            				'<param name="name" value="Spinnerdog FTP Upload">' +
	            				'<param name="MAYSCRIPT" value="true">'+
	            				'<param name="message" value="' + messagefile + '">' +
								'<param name="cache_version" value="1.02.22.02">' +
	            				'<param name="cache_option" value="Plugin">' +
	            				'</object>'; 
	            
	        }
			else {
	            
		        self.insert = '<object type="application/x-java-applet;version=1.4.1"' +
		          				'width= "' + awide + '" height= "' + ahigh + '" id="rup" name="rup" >' +
	            				'<param name="cache_archive" value="/_sd/ThinFile/ThinFTPUpload.jar">' +
	            				'<param name="code" value="com.thinfile.upload.ThinFTPUpload">' +
	            				'<param name="props_file" value="' + propsfile + '">' +
	            				'<param name="name" value="Spinnerdog FTP Upload">' +
	            				'<param name="MAYSCRIPT" value="true">' +
	            				'<param name="message" value="' + messagefile + '">' +
								'<param name="cache_version" value="1.02.22.02">' +
	            				'</object>';
			    }

			}
			else {
				/* mac and linux */
					self.insert = '<applet ' +
							   '   			archive  = "/_sd/ThinFile/ThinFTPUpload.jar"' +
							   '   			code     = "com.thinfile.upload.ThinFTPUpload"' +
							   '   			name     = "Thin FTP Upload"' +
							   '   			hspace   = "0"' +
							   '   			vspace   = "0"' +
							   '   			width = "' + awide + '"' +
							   '  			height = "' + ahigh + '"' +
							   '				mayscript="true" ' +
							   '	   		align = "middle" id="rup" name="rup">' +
		    				   '<param name="props_file" value="' + propsfile + '">' + 
							   '<param name="message" value="' + messagefile + '">' +
							   '<param name="cache_version" value="1.02.22.02">' +
		    				   '</applet>';
			}
				
		if( self.options.optsel ){ 
			var el = document.getElementById( self.options.optsel );
			if( el ){
				el.innerHTML = '<form name="sdUploaderOpts"> Ftp Mode: <select name="Mode"><option>Passive</option><option>Active</option></select><input type="hidden" name="Protocol" value="FTP" /></form>';
			}
		}
		self.el.innerHTML = self.insert;
 		 
	}
	
	
	this.Passwd=function(){
		
		if( self.options.password.match( /:/ ) ){
		    var frm = self.options.password.replace( /:.*$/, '' );
		    var ele = self.options.password.replace( /^.*:/, '' );
		    var pass = document.forms[ frm ].elements[ ele ].value;
		    pass = pass.replace(/^\s+|\s+$/g, "");
		    pass = pass.replace( /@/, '%40' );
			pass = pass.replace( /^.*</, '');
  			pass = pass.replace( />.*$/, '' );
			return( pass );
		  	}
		  	
	return( self.password );
	
	}
	
	this.Url=function( OrdNo ){
	  
		var host = self.options.host;
		
		if( host ===  'Fetcher' ){
			host = document.location.host;
			host = host.replace( /:.*$/, '' );
			}
			
		var updir = self.options.basepath + '/' + self.options.process + '_' + OrdNo;
		var ftpUrl = 'ftp://' + self.options.user + ':' + self.Passwd() + '@' + host + '/' + updir;
		
		return( ftpUrl );		
	}
	
	this.Mode=function(){
		
		if( ! document.forms[ 'sdUploaderOpts' ].elements[ 'Mode' ] ){
	  				var u = SDForm.Settings.getElementsByTagName( 'Upload' )[0];
						var mode = u.getAttribute( 'Mode' );
					}
		else{
				el = document.forms[ 'sdUploaderOpts' ].elements[ 'Mode' ];
				var mode = el.options[ el.selectedIndex ].text.toLowerCase();
				}
		return( mode );
	}
	
	this.Begin=function( OrdNo ){
		document.rup.setFtpMode( self.Mode() );
  		document.rup.setUrl( self.Url( OrdNo ) );
  		document.rup.jsStartUpload();
	}
	
	this.Remove=function(){ if( self.el ){ self.el.innerHTML = ''; } }
		
}

function filesQueued() { UC.client.filesAttached = true; }
function uploadCancelled() { var btn = document.getElementById('btn_send'); btn.disabled=true; }
function fileUploaded(s){ if( UC.Log && UC.options.LogEachFile ){ UC.Log( s ); } }
function uploadCompleted(){
	UC.UploadComplete();
	return;
}
