function multiselector(list_target, max)
{
	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 = 'file_' + 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.display='none';
			};
			if( this.max != -1 && this.count >= this.max )
			{ element.disabled = true; };
			this.count++; this.current_element = element;
		} else { alert( 'Error: not a file input element' ); };
	};
	this.addListRow = function(element)
	{
		var new_row = document.createElement('div');
		var new_row_button = document.createElement('input');
		new_row_button.type = 'button';
		new_row_button.className ='deleteimg';
		new_row.className='itemimage'
		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--;
			this.parentNode.element.multi_selector.current_element.disabled = false;
			return false;
		};
		new_row.innerHTML = "<div class=\"file\">"+element.value+"</div>";
		new_row.appendChild(new_row_button);
		this.list_target.appendChild(new_row);
	};
};

function inline_(object_) { document.getElementById(object_).style.display='inline'; }
function show_(object_) { document.getElementById(object_).style.display='block'; }
function hide_(object_) { document.getElementById(object_).style.display='none'; }
function clear_(object_)
{
  var listbox_ = document.getElementById(object_);
  while (listbox_.hasChildNodes()) { listbox_.removeChild(listbox_.childNodes[0]); }
}
function itemadd_(object_, text_, value_)
{
  var listbox_ = document.getElementById(object_); var opt_ = document.createElement("option");
  listbox_.options.add(opt_); opt_.value = value_; opt_.text = text_;
}
function itseladd_(object_, text_, value_)
{
  var listbox_ = document.getElementById(object_); var opt_ = document.createElement("option");
  listbox_.options.add(opt_); opt_.value = value_; opt_.text = text_; opt_.selected="selected";
}

function setpath_(part_)
{
  hidepath_();
  if (part_==0) { try { inline_("path0"); } catch (e_) {}; }
  else if (part_==1) { try { inline_("path1"); } catch (e_) {}; }
  else if (part_==2) { try { inline_("path2"); } catch (e_) {}; }
  else if (part_==3) { try { inline_("path3"); } catch (e_) {}; }
  return false;
}
function hidepath_()
{
  try { hide_("path0"); } catch (e_) {};
  try { hide_("path1"); } catch (e_) {};
  try { hide_("path2"); } catch (e_) {};
  try { hide_("path3"); } catch (e_) {};
}

