window.addEvent('domready', function() {
	$('powermaildiv_uid5').getElement('input').disabled = 1;
	$('powermaildiv_uid5').getElement('input').setStyle('opacity', '0.5');
});

// JavaScript Document
// Multiple file selector by Stickman -- http://www.the-stickman.com
// with thanks to: [for Safari fixes] Luis Torrefranca -- http://www.law.pitt.edu and Shawn Parker & John Pennypacker -- http://www.fuzzycoconut.com [for duplicate name bug] 'neal'


function MultiSelector( list_target, uid, max, label ){
	var uid = uid;
	var label = label;
	this.list_target = list_target;
	this.count = 0;
	this.id = 0;
	if( max ){
		this.max = max;
	}
	else {
		this.max = -1;
	};
	this.addElement = function( element ){
		if( element.tagName == 'INPUT' && element.type == 'file' ){
			element.name = 'tx_powermail_pi1[' + uid + '][' + this.id++ +']';
			element.multi_selector = this;
			element.onchange = function(){
				var new_element = document.createElement( 'input' );
				new_element.type = 'file';
				this.parentNode.insertBefore( new_element, this );
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );
				this.style.position = 'absolute';
				this.style.left = '-1000px';};
				if( this.max != -1 && this.count >= this.max ){
					element.disabled = true;
				};
				this.count++;
				this.current_element = element;
				
				$('powermaildiv_uid5').getElement('input').disabled = 0;
    				$('powermaildiv_uid5').getElement('input').setStyle('opacity', '1');
			}
		else {
			alert( 'Error: not a file input element' );
		};
	};
	this.addListRow = function( element ){
		var new_row = document.createElement( 'div' );
    // adnew
    new_row.classname = "delbutton";
    // adend
		var new_row_button = document.createElement( 'input' );
		// adchange
		//new_row_button.type = 'button';
		//new_row_button.value = label;
    new_row_button.type = 'image';
    new_row_button.src = 'fileadmin/templates/images/cross.gif';
    new_row_button.value = '';
		// adend
		new_row.element = element;
		new_row_button.onclick= function(){
			this.parentNode.element.parentNode.removeChild( this.parentNode.element );
			this.parentNode.parentNode.removeChild( this.parentNode );
			this.parentNode.element.multi_selector.count--;
					
			if (this.parentNode.element.multi_selector.count <= 1) {
				$('powermaildiv_uid5').getElement('input').disabled = 1;
    				$('powermaildiv_uid5').getElement('input').setStyle('opacity', '0.5');
			}
			
			this.parentNode.element.multi_selector.current_element.disabled = false;

			return false;
		};
    // adnew
    var new_row_text = document.createElement( 'span' );
    new_row_text.classname = "deltitle";
    // display filename without path
    var f = (element.value).match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
    new_row_text.innerHTML = (f == null) ? element.value : f[2];
    // adend
    // adchange
		//new_row.innerHTML = element.value;
		new_row.appendChild( new_row_button );
		new_row.appendChild( new_row_text );
    // adend
		this.list_target.appendChild( new_row );
	};
};

