/***********************************************************************************************************************************
	
	This file contains the functions necessary to add a new file upload section via AJAX for records that make use of file uploads
	
	History:
		File added on 11/13/2005
	
***********************************************************************************************************************************/

// some global vars to store references to the add file button, and the span inside it that contains it's caption text
var addFileButton;

// this function is used as a callback to add file upload HTML to current page
function addFileUploadCB(data){
	var aboveClass;
	var uploadsLeft = document.getElementById('file_uploads_left');
	
	// set vars only if not already done before
	addFileButton 	= !addFileButton ? 	document.getElementById('add_file_button') 	: addFileButton;
	
	// add HTML returned from PHP as a new row above the last row in the fieldset
	var newRow = addRow('last_upload_row',data);

	// set the class of the table inside the new row, based on the class name of the table inside the row immediately above this new one
	var aboveRow = getPreviousElement(newRow);

	// set var referencing the table inside this row
	var thisTable = getFirstChildElement(getFirstChildElement(newRow));
	
	if (aboveRow) {
		// drill down inside the row to get at the class name of the table inside the first <td> in this row
		var aboveTable = getFirstChildElement(getFirstChildElement(aboveRow));
		if (aboveTable) {
			if (aboveTable.nodeName == 'TABLE' && aboveTable.className) aboveClass = aboveTable.className;
		}
	}
	
	thisTable.className = aboveClass == 'field_image_alt_row' || !aboveClass ? 'field_image_row' : 'field_image_alt_row';
	
	// decrement the value of the file_uploads_left hidden field, so we know when to hide the "Add File" button
	uploadsLeft.value--;
	
	// hide add button if needed
	if (uploadsLeft.value < 1) addFileButton.style.display = 'none';
	
	// change caption back to what it was before
	addFileButton.innerHTML = addFileButton.oldInnerHTML;
	
	
}