// Gmail File Attachment Clone
// (c) 2005, Gavin Lynch

//number of forms currently in < span id="content" > tree
var form_count = 0;

//add file attachment form and associated elements
function add()
{
	//create new < input > element
	var new_attachment = document.createElement('input');
	//give element an id
	new_attachment.setAttribute('id', 'child_attachment_' + form_count);
	//set element type
	new_attachment.setAttribute('type', 'file');
	//set element size
	//new_attachment.setAttribute('size', '48');
	//append newly created element to < span id="content" > tree
	document.getElementById('content').appendChild(new_attachment);

	//create new < span > element
	var new_text = document.createElement('span');
	//give element an id
	new_text.setAttribute('id', 'child_attachment_text_' + form_count);

	//set element HTML to produce 'remove' text link
	new_text.innerHTML = '<a href="#" onclick="remove(' + form_count + ');">&nbsp;remove</a><br />';
	//append newly created element to < span id="content" > tree
	document.getElementById('content').appendChild(new_text);

	//increase the form count
	form_count++;

	//if an attachment has been added, change text to "Attach another file"
	document.getElementById('more').innerHTML = 'Attach another file';
 }

//remove file attachment form and associated elements
function remove(remove_form_num)
{
	//decrease the form count
	form_count--;

	//remove < input > element attachment
	document.getElementById('content').removeChild(document.getElementById('child_attachment_' + remove_form_num));
	//remove < span > element text
	document.getElementById('content').removeChild(document.getElementById('child_attachment_text_' + remove_form_num));
	//remove < img > element image
	document.getElementById('content').removeChild(document.getElementById('child_attachment_img_' + remove_form_num));

	//if all forms are removed, change text back to "Attach a file"
	if (form_count == 0)
	{
			document.getElementById('more').innerHTML = 'Attach a file';
	}
}
