/* addFileObject(index, object)
	Adds a file upload object to a form, up to 5.
	index = the previous number index. The new file will be called "upload"+(index+1)
	object = the object to which to append this new object.
	The routine appends a paragraph containing the input box, and a link to call this routine and add
	another object. It also removes the previous iteration's link (the link which called the routine)
*/

function addFileObject(n, obj) {
	n++;
	a=document.getElementById(obj);							// Get the node to add children to
	p=document.createElement("p");							// Create a paragraph to contain our new objects
	p.setAttribute('id', 'p'+n);							// ID the paragraph so I can remove a child later on
	t=document.createElement("input");						// Create an input object
	t.setAttribute('type', 'file');							// Set type to file
	t.setAttribute('name', 'oFile'+n);						// Set the name to "oFileN", N is the index 1-5
	p.appendChild(document.createTextNode((n>1?"File #"+n:"Primary file")+": "));		// Add the text to our new paragraph
	p.appendChild(t);										// Add the input object to the paragraph
	p.appendChild(document.createTextNode(" "));			// Add a space in our paragraph
	p.appendChild(document.createElement("br"));		// 
	if (n<5) {												// If n<5, give user option to add another object
		t=document.createElement("a");						// Create a hyperlink
		t.setAttribute('href', 'javascript: addFileObject('+n+', "'+obj+'");');	// Hyperlink href calls this routine
		t.setAttribute('id', 'add'+n);						// Set the id of the link
		t.appendChild(document.createTextNode("(Add another file)"));
		p.appendChild(t);									// Add this anchor element to the paragraph
	}
	a.appendChild(p);										// Add the paragraph to the div
	if (n>1) {		// If there's a previous "(Add another file)" link then remove that child from the paragraph object
		document.getElementById("p"+(n-1)).removeChild(document.getElementById("add"+(n-1)));
	}
}
