var existing_upload_lines = 1;
function addUploadLine()
{
	var table = document.getElementById('UploadTable');
	
	if(table)
	{
		existing_upload_lines++;
		
		// -- Header Row
		
			var header_row = document.createElement('tr');
			var header_cell = document.createElement('td');
			header_cell.className =  'header';
			header_cell.colSpan = 3;
			header_cell.appendChild(document.createTextNode('File ' + existing_upload_lines + ' Information'));
			header_row.appendChild(header_cell);
			table.appendChild(header_row);
			
		// -- Private Checkbox
		
			var private_img_row = document.createElement('tr');
			var private_left = document.createElement('td');
			var private_right = document.createElement('td');
			var private_cbx = document.createElement('input');
			var private_label = document.createElement('label');
			
			private_left.className = 'body';
			private_left.style.textAlign = 'right';
			private_cbx.setAttribute('name', 'IsPrivate[]');
			private_cbx.setAttribute('value', '1');
			private_cbx.setAttribute('type', 'checkbox');
			private_cbx.setAttribute('id', 'private' + existing_upload_lines);
			private_left.appendChild(private_cbx);
			
			private_right.className = 'body';
			private_label.setAttribute('for', 'private' + existing_upload_lines);
			private_label.appendChild(document.createTextNode('Make Private'));
			private_right.appendChild(private_label);
			
			private_img_row.appendChild(private_left);
			private_img_row.appendChild(private_right);
			
		// -- Preview Thumbnail
			
			var thumb_image_cell = document.createElement('td');
			var thumb_image = document.createElement('img');
			
			thumb_image_cell.className = 'body';
			thumb_image_cell.rowSpan = 4;
			thumb_image_cell.style.textAlign = 'center';
			thumb_image.setAttribute('src', '/styles/default/images/waiting.gif');
                        thumb_image.style.width = '100px';
			thumb_image.style.height = '100px';
                        thumb_image.style.border = '1px solid black';
			thumb_image.id =  'thumb' + existing_upload_lines;
			thumb_image_cell.appendChild(thumb_image);
			
			private_img_row.appendChild(thumb_image_cell);
			
			table.appendChild(private_img_row);
		
		// -- NSFW Checkbox
		
			var nsfw_row = document.createElement('tr');
			var nsfw_left = document.createElement('td');
			var nsfw_right = document.createElement('td');
			var nsfw_cbx = document.createElement('input');
			var nsfw_label = document.createElement('label');
			
			nsfw_left.className = 'body';
			nsfw_left.style.textAlign = 'right';
			nsfw_cbx.setAttribute('name', 'IsNSFW[]');
			nsfw_cbx.setAttribute('value', '1');
			nsfw_cbx.setAttribute('type', 'checkbox');
			nsfw_cbx.setAttribute('id', 'nsfw' + existing_upload_lines);
			nsfw_left.appendChild(nsfw_cbx);
			
			nsfw_right.className = 'body';
			nsfw_label.setAttribute('for', 'nsfw' + existing_upload_lines);
			nsfw_label.appendChild(document.createTextNode('Mark as Not Safe For Work'));
			nsfw_right.appendChild(nsfw_label);
			
			nsfw_row.appendChild(nsfw_left);
			nsfw_row.appendChild(nsfw_right);
			
			table.appendChild(nsfw_row);
		
		// -- File Row
			var file_row = document.createElement('tr');
			var file_left = document.createElement('td');
			var file_right = document.createElement('td');
			var file_input = document.createElement('input');
			
			file_left.className = 'body';
			file_left.style.textAlign = 'right';
			file_left.appendChild(document.createTextNode('File to Upload:'));
			
			file_right.className = 'body';
			file_input.setAttribute('name', 'File[]');
			file_input.setAttribute('type', 'file');
			eval('var imgswapfunc = function(){swapImage(' + existing_upload_lines + ', this.value);};');
			file_input.onchange = imgswapfunc;
			file_right.appendChild(file_input);
			
			file_row.appendChild(file_left);
			file_row.appendChild(file_right);
			table.appendChild(file_row);	
		
		// -- Description Row
		
			var description_row = document.createElement('tr');
			var description_left = document.createElement('td');
			var description_right = document.createElement('td');
			var description_textarea = document.createElement('textarea');
			var description_label = document.createElement('label');
			
			description_left.className = 'body';
			description_left.style.textAlign = 'right';
			description_left.appendChild(document.createTextNode('File Description:'));
			
			description_right.className = 'body';
			description_textarea.setAttribute('name', 'Description[]');
			description_right.appendChild(description_textarea);
			
			description_row.appendChild(description_left);
			description_row.appendChild(description_right);
			table.appendChild(description_row);
			header_row.scrollIntoView();
		
	}
	
}


function swapImage(index, image_path)
{
	var img = document.getElementById('thumb' + index);
	if(img)
	{
		var path = 'file:///' + (image_path.replace(/\\/gi, '/')).replace(/\s/gi, '%20');
		img.setAttribute("src", path);
	}
}

var spiderMasks = [];


