function loadFile(fileID) {
	$.ajax({
		type: "POST",
		url: "/ajax/load_file.php",
		data: "file_id=" + fileID,
		success: function(data){
			$("div#showcase").hide();
			$("div#showcase").html(data);
			$("div#showcase").fadeIn("fast");
	   }
	});
}
//************		User Functions		************//
//**************************************************//

function userEdit(userID, username, fullName, groupID) {
	var idPath = "tr#user_" + userID;
	$.ajax({
		type: "POST",
		url: "/ajax/user_edit_form.php",
		data: "user_id=" + userID + "&username=" + username + "&full_name=" + fullName + "&group_id=" + groupID,
		success: function(data) {
			$(idPath).html(data);
		}
	});
}
function userUpdate(userID) {
	var idPath = "tr#user_" + userID;
	var username = 			$(idPath + " .username").val();
	var password = 			$(idPath + " .password").val();
	var passwordConfirm = 	$(idPath + " .password_confirm").val();
	var fullName = 			$(idPath + " .full_name").val();
	var groupID = 			$(idPath + " .group").val();
	
	$.ajax({
		type: "POST",
		url: "/ajax/user_update.php",
		data: "user_id=" + userID + "&username=" + username + "&password=" + password + "&password_confirm=" + passwordConfirm + "&full_name=" + fullName + "&group_id=" + groupID,
		success: function(data) {
			$(idPath).html(data);
		}
	});
}
function userCancelUpdate(userID) {
	var idPath = "tr#user_" + userID;
	$.ajax({
		type: "POST",
		url: "/ajax/user_cancel_update.php",
		data: "user_id=" + userID,
		success: function(data) {
			$(idPath).html(data);
		}
	});
}
function userDelete(userID, fullName) {
	var confirmDelete = confirm("Are you sure you want to delete \"" + fullName + "\"?");
	if (confirmDelete) {
		$.ajax({
			type: "POST",
			url: "/ajax/user_delete.php",
			data: "user_id=" + userID,
			success: function(data) {
				$(idPath).html(data);
			}
		});
	} else {
		$("p#message").html("User deletion aborted.");
	}
}

//************		File Functions		************//
//**************************************************//

function fileNew(userID) {
	var idPath = "tr#file_create_" + userID;
	$.ajax({
		type: "POST",
		url: "/ajax/file_new_form.php",
		data: "user_id=" + userID,
		success: function(data) {
			$(idPath).before(data);
			$(idPath).html("<td colspan=\"7\"><p class=\"disabled_add_link\">Upload File</p></td>");
		}
	});
}
function fileUpdate(userID, newFile) {
	var filePath = "#upload_file_" + userID;
	var idPath1 = "tr#file_new_1_" + userID;
	var idPath2 = "tr#file_new_2_" + userID;
	var visible_by = 	userID;
	var title = 		$.base64Encode($(idPath1 + " .title").val());
	var position = 		$(idPath1 + " .position").val();
	var type_id = 		$(idPath1 + " .type_id").val();
	var ratio = 		$(idPath1 + " .ratio").val();
	var downloadable = 	$(idPath1 + " .downloadable").val();
	var description = 	$.base64Encode($(idPath2 + " .description").val());
	
	if (newFile == true) {
		$(filePath).fileUploadSettings('scriptData',"&visible_by=" + visible_by + "&title=" + title + "&position=" + position + "&type_id=" + type_id + "&ratio=" + ratio + "&downloadable=" + downloadable + "&description=" + description);
		$(filePath).fileUploadStart();
	} else {
		var submittedFile = 	$(idPath1 + " .submitted_file").val();
		$.ajax({
			type: "GET",
			url: "/ajax/file_new_update.php",
			data: "visible_by=" + visible_by + "&title=" + title + "&position=" + position + "&type_id=" + type_id + "&ratio=" + ratio + "&downloadable=" + downloadable + "&description=" + description + "&submitted_file=" + submittedFile,
			success: function(data) {
				$("tr#file_new_1_" + userID).remove();
				$("tr#file_new_2_" + userID).remove();
				$("tr#file_create_" + userID).before(data);
				$("tr#file_create_" + userID).html("<td colspan=\"7\"><p class=\"add_link\"><a href=\"javascript:fileNew(" + userID + ")\" >Upload File</a></p></td>");
			}
		});
	}
}
function fileCancelNew(userID) {
	$("#upload_file_" + userID).fileUploadCancel();
	$("tr#file_new_1_" + userID).remove();
	$("tr#file_new_2_" + userID).remove();
	$("tr#file_create_" + userID).html("<td colspan=\"7\"><p class=\"add_link\"><a href=\"javascript:fileNew(" + userID + ")\" >Upload File</a></p></td>");
	$("p#message").html("File Upload aborted.");
}
function fileEdit(fileID, visible_by, title, position, type_id, ratio, downloadable, description, file) {
	$.ajax({
		type: "POST",
		url: "/ajax/file_edit_form.php",
		data: "file_id=" + fileID + "&visible_by" + visible_by + "&title=" + title + "&position=" + position + "&type_id=" + type_id + "&ratio=" + ratio + "&downloadable=" + downloadable + "&description=" + description + "&file=" + file,
		success: function(data) {
			$("tr#user_file_2_" + fileID).remove();
			$("tr#user_file_1_" + fileID).replaceWith(data);
		}
	});
}
function fileEditUpdate(fileID, userID) {
	var idPath1 = "tr#file_edit_1_" + fileID;
	var idPath2 = "tr#file_edit_2_" + fileID;
	var title = 		$(idPath1 + " .title").val();
	var position = 		$(idPath1 + " .position").val();
	var type_id = 		$(idPath1 + " .type_id").val();
	var ratio = 		$(idPath1 + " .ratio").val();
	var downloadable = 	$(idPath1 + " .downloadable").val();
	var description = 	$(idPath2 + " .description").val();
	
	$.ajax({
		type: "POST",
		url: "/ajax/file_edit_update.php",
		data: "file_id=" + fileID + "&visible_by" + userID + "&title=" + title + "&position=" + position + "&type_id=" + type_id + "&ratio=" + ratio + "&downloadable=" + downloadable + "&description=" + description,
		success: function(data) {
			$("tr#file_edit_2_" + fileID).remove();
			$("tr#file_edit_1_" + fileID).replaceWith(data);
		}
	});
}
function fileEditCancel(fileID) {
	$.ajax({
		type: "POST",
		url: "/ajax/file_cancel_update.php",
		data: "file_id=" + fileID,
		success: function(data) {
			$("tr#file_edit_2_" + fileID).remove();
			$("tr#file_edit_1_" + fileID).replaceWith(data);
		}
	});
}
function fileDelete(fileID, title) {
	var confirmDelete = confirm("Are you sure you want to delete \"" + title + "\"?");
	if (confirmDelete) {
		$.ajax({
			type: "POST",
			url: "/ajax/file_delete.php",
			data: "file_id=" + fileID,
			success: function(data) {
				$("head").append(data);
			}
		});
	} else {
		$("p#message").html("File deletion aborted.");
	}
}