$(function() {

// security
	$.get('form-contents.html', function(data) {
		
		$('#place-form-here').html(data);
		
		$("form input.add-field").click(function(e) {
			$table = $("#select-files");
			count = $table.find("tr.file").length;
			$last_row = $table.find("tr.file:last");

			count++;
			$last_row.after("<tr class='file'><th>file "+count+"</th><td><input id='field_file"+count+"' name='file"+count+"' type='file' /></td></tr>");

			e.preventDefault();
		});

		$("form input.submit-button").attr("disabled", false).val("Upload Files").removeAttr("style");

		$("#submit-a-file form").submit(function() {
	
			verdict = true;
			$(this).find(".required").each(function() {
			label_selector = "label[for="+ $(this).attr("id") +"]";
			$(label_selector).removeAttr("style");
				if( $(this).val() == "" ) {
					verdict = false;
					$(label_selector).css({ color:"#b11" });
				}
			});
			if( verdict ) {
				$submit_button = $(this).find(".submit-button");
				$submit_button.attr("disabled", "disabled");
				$submit_button.css({ backgroundColor:"#f00", color:"#fff" });
				$submit_button.val("This May Take Quite A While. Be Patient!");
			// this replaces the action of the form
	//			$(this).attr("action", "upload.php");
			}
		
			return verdict;
		
		});
		
	});

	

});

function UploadsPopUp() {

	width = 720;
	height = 520;
	left = ( $(window).width() - width ) / 2;
	top = 100;

	new_window = window.open(
		"/submit-a-file/index.php",
		"submit-a-file",
		"height="+height+",width="+width+",left="+left+",top="+top+",status=no,toolbar=no,menubar=no,resizable=yes,location=no,titlebar=no,scrollbars=yes"
	)

}


