function uploadElement(mother, id) {
	this.mother = mother;
	this.id = id;
	this.lis = '';
	this.lfdnr = 0;
	
	this.print = function print() {
		var string = '';
		
		var fileInputWidth = window.opera ? 50 : 55;
		
		string += addLine('<form name="uploadForm[' + this.id + ']" action="" target="" method="post" enctype="multipart/form-data" style="margin: 1px; padding: 1px;" onSubmit="return doControlledSubmit(this);">');
		string += addLine('	<input type="file" name="uploadfile_0" size="' + fileInputWidth + '">');
		string += addLine('	<input type="hidden" name="successURL" value="">');
		string += addLine('	<input type="hidden" name="LIS_host" value="">');
		string += addLine('	<input type="hidden" name="LIS_port" value="">');
		string += addLine('	<input type="hidden" name="LIS_path" value="">');
		string += addLine('	<input type="hidden" name="VENDORID" value="">');
		string += addLine('     <input type="hidden" name="tan" value="">');
		string += addLine('     <input type="hidden" name="orderid" value="">');
		string += addLine('	<input type="hidden" name="LFDNR" value="">');
		string += addLine('	<input type="hidden" name="email" value="">');
		string += addLine('</form>');

		var ref = this.getRef();
		ref.innerHTML += string;
	}

	this.getRef = function getRef() {
		if(this.exists() == false) {
			this.create();
		}
		return myGetElementById(elementName + '[' + this.id + ']');			
	}
	
	this.getForm = function getForm() {
//		return document.forms["uploadForm[" + this.id + "]"];

		var form = false;
		for(i = 0; i < window.document.forms.length; i++) {
			form = window.document.forms[i];
			if(form.name == 'uploadForm[' + this.id + ']') {
				return form;
			}
		}

		return false;
	}
	
	this.getItem = function getItem(field) {
		var form = this.getForm();
		if(!field) {
			field = 'uploadfile_0';
		}
		return form.elements[field];
	}
	
	this.exists = function exists() {
		if(myGetElementById(elementName + '[' + this.id + ']')) {
			return true;
		} else {
			return false;
		}
	}
	
	this.create = function create() {
		if(this.exists() == true) {
			// Cannot create, because it already exists
		} else {
			var inputdiv = document.createElement('div');
			inputdiv.id = elementName + '[' + this.id + ']';

			mother.appendChild(inputdiv);
		}
	}
	
	this.clean = function clean() {
		this.remove();
		this.print();
	}
	
	this.remove = function remove() {
		if(this.exists() == true) {
			var ref = this.getRef();
			mother.removeChild(ref);
		} else {
			// cannot delete. It does not exist yet.
		}
	}
	
	this.check = function check() {
		var fileName = this.getItem().value;
		var extensionPos = fileName.lastIndexOf('.');
		if(extensionPos > 0) {
			var extension = fileName.substr(extensionPos + 1).toUpperCase().replace(/\"/, '');
			if(extension != 'JPG' && extension != 'JPEG') {
				return false;
			}
		} else {
			return false;
		}
		return true;
	}

	this.isset = function isset() {
		return this.getItem().value.length > 0;
	}
	
	this.upload = function upload(target) {
		if(!target) {
			alert("Action or Target not set. Cannot send form");
		} else if(!this.getForm()) {
			alert("Form not yet printed. Cannot send it !");
		} else if(this.getForm().VENDORID.value == '') {
			alert("Upload not prepared. Will not upload anything.");
		} else {
			this.getForm().action = this.lis;
			this.getForm().target = target;
			this.getForm().submit();
		}
	}

	this.prepareUpload = function prepareUpload(tan, orderid, vendorid, email, successURL, lis) {
		if(this.exists() == false) {
			alert("cannot prepare, because form does not exist yet");
		} else if(!process) {
			alert("cannot prepare, process not started yet");
		} else {
			this.lfdnr = process.getNextLfdnr();

			this.getForm().VENDORID.value = vendorid;
			this.getForm().successURL.value = successURL;
			this.getForm().tan.value = tan;
			this.getForm().orderid.value = orderid;
			this.getForm().email.value = email;
			this.getForm().LFDNR.value = this.lfdnr;

			this.lis = 'http://' + lis['host'] + ':' + lis['port'] + lis['path'];
		}
	}
}

