<?php

	// we might pass some of these values in to automatically load content
	$path = initialize("path", "get", "filename"); 
	$field = initialize("field", "get", "filename");
	$rollback = initialize("rollback", "get", "integer");
	
	$onload = "";
	
	// if we have a rollback ID, load that content's info
	if ($rollback) {
		$query = "SELECT path, field FROM content WHERE ID=$rollback";
		$result = db_do_query($query);
		$count = db_num_rows($result);
		if (!$count) {
			clear_feedback();
			set_feedback(0, "There is no content matching the requested ID.");
			$feedback = trim(addslashes(get_feedback()));
			$onload .= "show_feedback(\"$feedback\");";
		} else {
			$row = db_get_row($result, 0);
			extract($row);
			clear_feedback();
			set_feedback(1, "The requested content is displayed below, but is not yet published.");
			$feedback = trim(addslashes(get_feedback()));
			$onload .= "show_feedback(\"$feedback\");";
		}
	}
	
	// if we have content IDs, load that content for immediate editing
	if ($path) {
		// separate the parts of the path value
		$paths = explode("/", $path);
		array_pop($paths); // this separates the last part from the end of the path
		switch(CONTENT_TYPE) {
			case "contemplate": $groups = CONTEMPLATE_CONTENT_DIRECTORIES; break;
			case "database": $groups = DATABASE_TABLES; break;
			case "dreamweaver": $groups = DREAMWEAVER_CONTENT_DIRECTORIES; break;
		}
		if (strpos($groups, ",") === false) {
			array_shift($paths); // if there's only one directory or database table, it will already be open, so this removes it from the beginning of the path
		}
		
		// build a command of all the paths we have to open
		// we'll start with the last one and nest it inside of each preceding one
		$open_command = "click_field(\"$path\", \"$field\", \"$rollback\");";
		$open_command = "click_path(\"$path\", 1, \"".addslashes($open_command)."\");";
		for ($i=(count($paths) - 1); $i>=0; $i--) {
			$open_command = "click_group(\"$paths[$i]\", 1, \"".addslashes($open_command)."\");";
		}
		$onload = $open_command.$onload; // we want this to appear before the feedback so it doesn't clear the feedback
	}
	
	// we want this to appear before anything else
	$onload = "build_content_browser(\"".addslashes($onload)."\");";
	
	// we just want this to appear after the editor is loaded
	$onload .= "undoManager = new tinymce.UndoManager(tinyMCE.activeEditor);";
	
?>

<html>

	<head>
		<title><?php print EDITOR_NAME; ?></title>
		<?php eval(include_namespace(HEAD_FILE)); ?>
		<script language="JavaScript">
		
			content_type = "<?php print CONTENT_TYPE; ?>";
			cookie_path = "<?php print ini_get('session.cookie_path'); ?>";
			default_editor_color = "<?php print EDITOR_BG_COLOR; ?>";
			editor_index = "<?php print $editor_index; ?>";
			multiple_spaces = parseInt("<?php print MULTIPLE_SPACES; ?>");
		
			function build_content_browser(next) {
				PHP_command = escape("build_content_browser()");
				ajax_URL = editor_index + "?page=ajax_handler&command=" + PHP_command;
				success_code = "show_content_browser(ajax_response);";
				if (next) { success_code += next; }
				failure_code = "alert(\"There was an error starting the content browser.\");";
				ajax_request(ajax_URL, success_code, failure_code);
			}
			
			function show_content_browser(response) {
				document.getElementById('content_browser').innerHTML = response;
				//show_open_paths("groups");
				//show_open_paths("paths");
				show_open_field();
			}
		
			function click_group(group, overwrite, next) {
				if ((document.getElementById("paths_" + group).innerHTML.replace(/\s/, "") == "")||(overwrite)) {
					// if this group's paths container is empty, load it
					group_label = (content_type == "database") ? "table" : "directory" ;
					PHP_command = escape("get_path_links('" + group + "')");
					ajax_URL = editor_index + "?page=ajax_handler&command=" + PHP_command;
					success_code = "document.getElementById('paths_" + group + "').innerHTML = ajax_response; document.getElementById('group_" + group + "').className = document.getElementById('group_" + group + "').className.replace(/collapsed/, 'expanded');";
					failure_code = "alert(\"There was an error loading the contents of the '" + group + "' " + group_label + ".\");";
					if (next) { success_code += next; }
					ajax_request(ajax_URL, success_code, failure_code);
					remember_open_paths(group, "groups", 1);
				} else {
					// if if is already loaded, empty it
					document.getElementById("paths_" + group).innerHTML = "";
					document.getElementById("group_" + path).className = document.getElementById("group_" + group).className.replace(/expanded/, "collapsed");
					remember_open_paths(group, "groups", 0);
				}
			}
		
			function click_path(path, overwrite, next) {
				if ((document.getElementById("paths_" + path).innerHTML.replace(/\s/, "") == "")||(overwrite)) {
					// if this path's paths container is empty, load it
					path_label = (content_type == "database") ? "fields" : "file" ;
					PHP_command = escape("get_fields('" + path + "')");
					ajax_URL = editor_index + "?page=ajax_handler&command=" + PHP_command;
					success_code = "document.getElementById('paths_" + path + "').innerHTML = ajax_response; document.getElementById('path_" + path + "').className = document.getElementById('path_" + path + "').className.replace(/collapsed/, 'expanded');";
					failure_code = "alert(\"There was an error loading the contents of the '" + path + "' " + path_label + ".\");";
					if (next) { success_code += next; }
					ajax_request(ajax_URL, success_code, failure_code);
					remember_open_paths(path, "paths", 1);
				} else {
					// if if is already loaded, empty it
					document.getElementById("paths_" + path).innerHTML = "";
					document.getElementById("path_" + path).className = document.getElementById("path_" + path).className.replace(/expanded/, "collapsed");
					remember_open_paths(path, "paths", 0);
				}
			}
			
			function click_field(path, field, rollback, next) {
				if (!rollback) { rollback = ""; }
				tinyMCE.activeEditor.setProgressState(0); // this is in case the progress state gets stuck after a previous operation
				if (warn_unsaved("load")) {
					// if it's okay to replace the current content, load the new content
					tinyMCE.activeEditor.setProgressState(1);
					save_command = "save_content('" + path + "', '" + field + "');";
					revert_command = (field) ? "revert_content('" + path + "', '" + field + "');" : "" ; // we don't need the revert button when adding new content
					delete_command = (field) ? "delete_content('" + path + "', '" + field + "');" : "" ; // we don't need the delete button when adding new content
					if (field) {
						label = "Editing " + field + " in " + path;
					} else {
						label = "Adding <input type=\"text\" name=\"name\" size=\"16\" class=\"form\" /> to " + path;
					}
					PHP_command = escape("get_content('" + path + "', '" + field + "', '" + rollback + "')");
					ajax_URL = editor_index + "?page=ajax_handler&command=" + PHP_command;
					success_code = "load_content(ajax_response, label, save_command, revert_command, delete_command);";
					if (field) {
						failure_code = "alert(\"There was an error loading the contents of the '" + name + "' field.\");";
					} else {
						failure_code = "alert(\"There was an error loading the new field.\");";
					}
					if (next) { success_code += next; }
					ajax_request(ajax_URL, success_code, failure_code);
					remember_open_field(path, field);
				}
			}
			
			function load_content(data, label, save_command, revert_command, delete_command) {
				//alert(data); // debug
				//clear_feedback(); // this would be nice here, but then it clears any feedback generated by the rollback routine
				data = ajax_unserialize(data, 1);
				content = data["content"];
				content = show_content_scripts(content);
				tinyMCE.activeEditor.setContent(content);
				saved_content = tinyMCE.activeEditor.getContent();
				show_unsaved = 0;
				if (!data["lock_name"]) {
					document.getElementById("content_editor_controls_name").innerHTML = label + " <span id=\"content_editor_controls_status\"><\/span>";
					document.getElementById("content_editor_controls_schedule").innerHTML = "<div class=\"stack_left\">Schedule for: <\/div>" + data["schedule_menu"] + "<div class=\"stack_left\"><a href=\"JavaScript:clear_schedule_menus();\">Clear<\/a><\/div>"; // <div class=\"stack_left\"><input type=\"checkbox\" name=\"schedule\" value=\"1\" class=\"form\" onclick=\"toggle_schedule_menus();\" /> 
					document.getElementById("content_editor_controls_comment").innerHTML = "Comment: <input type=\"text\" name=\"comment\" size=\"48\" class=\"form\" />";
					document.getElementById("content_editor_controls_save").innerHTML = (save_command) ? data["status_menu"] + "&nbsp;" + "<input type=\"button\" value=\"Save\" onclick=\"" + save_command + "\" class=\"form\" />" : "" ;
					document.getElementById("content_editor_controls_delete").innerHTML = ((revert_command)&&(data["ID"])) ? "<input type=\"button\" value=\"Revert\" onclick=\"" + revert_command + "\" class=\"form\" />" : "" ;
					document.getElementById("content_editor_controls_delete").innerHTML += ((delete_command)&&(content_type != "dreamweaver")) ? "<input type=\"button\" value=\"Delete\" onclick=\"" + delete_command + "\" class=\"form\" />" : "" ; // we don't allow deleting fields from Dreamweaver files because that would have to be done at the template leve
				} else {
					// Dreamweaver has locked the file, so show it as read-only
					document.getElementById("content_editor_controls_name").innerHTML = label + " <span id=\"content_editor_controls_status\" class=\"file_locked\">(read-only)<\/span>";
					document.getElementById("content_editor_controls_schedule").innerHTML = "You cannot save changes to this file because it is locked in Dreamweaver or Contribute by " + data["lock_name"];
					document.getElementById("content_editor_controls_comment").innerHTML = "";
					document.getElementById("content_editor_controls_save").innerHTML = "";
					document.getElementById("content_editor_controls_delete").innerHTML = "";
				}
				set_editor_color(data["bg_color"]);
				tinyMCE.activeEditor.undoManager.clear();
				tinyMCE.activeEditor.nodeChanged();
				tinyMCE.activeEditor.setProgressState(0);
				//tinyMCE.activeEditor.focus();
			}
			
			function save_content(path, field) {
				status_value = document.content_edit.status.options[document.content_edit.status.selectedIndex].value; // I'd rather just call it status, but that's a reserved word in IE
				if (!field) {
					field = document.content_edit.name.value;
				}
				if (!field) {
					alert("Please enter a name for your new content field.");
					document.content_edit.name.focus();
					return;
				}
				if (status_value <= 0) {
					alert("Please select a status for this content.");
					document.content_edit.status.focus();
					return;
				}
				if ((status_value == 3)&&(document.content_edit.schedule_month.selectedIndex == 0)) {
					if (confirm("You have selected the Scheduled status, but have not set a date for scheduled publishing. Click OK to publish your content immediately, or Cancel to go back and set a date.")) {
						status_value = 4;
						set_menu("content_edit", "status", "value", status_value);
					} else {
						return;
					}
				}
				if ((status_value == 4)&&(document.content_edit.schedule_month.selectedIndex > 0)) {
					if (confirm("You have set a date for scheduled publishing, but have selected the Published status. Click OK to publish your content immediately, or Cancel to go back and change the status to Scheduled.")) {
						clear_schedule_menus();
					} else {
						return;
					}
				}
				tinyMCE.activeEditor.setProgressState(1);
				current_content = tinyMCE.activeEditor.getContent();
				if (!multiple_spaces) {
					current_content = strip_multiple_spaces(current_content);
					tinyMCE.activeEditor.setContent(current_content);
				}
				current_content = activate_content_scripts(current_content);
				ajax_URL = editor_index + "?page=content_submit";
				data = new Object();
				data["status"] = status_value;
				data["path"] = path;
				data["field"] = field;
				data["content"] = current_content;
				//data["schedule"] = (document.content_edit.schedule.checked) ? 1 : 0 ;
				data["schedule_year"] = document.content_edit.schedule_year.options[document.content_edit.schedule_year.selectedIndex].value;
				data["schedule_month"] = document.content_edit.schedule_month.options[document.content_edit.schedule_month.selectedIndex].value;
				data["schedule_day"] = document.content_edit.schedule_day.options[document.content_edit.schedule_day.selectedIndex].value;
				data["schedule_hours"] = document.content_edit.schedule_hours.options[document.content_edit.schedule_hours.selectedIndex].value;
				data["schedule_minutes"] = document.content_edit.schedule_minutes.options[document.content_edit.schedule_minutes.selectedIndex].value;
				data["schedule_seconds"] = document.content_edit.schedule_seconds.value;
				data["schedule_ampm"] = document.content_edit.schedule_ampm.options[document.content_edit.schedule_ampm.selectedIndex].value;
				data["comment"] = document.content_edit.comment.value;
				data = ajax_serialize(data, 1);
				success_code = "show_saved_content('" + path + "', '" + field + "', ajax_response);";
				path_label = (content_type == "database") ? "fields" : "file" ;
				failure_code = "alert(\"There was an error saving the content to the '" + path + "' " + path_label + ".\");";
				ajax_request(ajax_URL, success_code, failure_code, "POST", "text", data);
			}
			
			function revert_content(path, field) {
				if ((field)&&(confirm("Are you sure you wish to revert '" + field + "' in " + path + " to the last published version?"))) {
					tinyMCE.activeEditor.setProgressState(1);
					ajax_URL = editor_index + "?page=content_revert";
					data = new Object();
					data["path"] = path;
					data["field"] = field;
					data = ajax_serialize(data, 0);
					success_code = "show_reverted_content('" + path + "', '" + field + "', ajax_response);";
					failure_code = "alert(\"There was an error reverting the content.\");";
					ajax_request(ajax_URL, success_code, failure_code, "GET", "text", data);
				}
			}
			
			function delete_content(path, field) {
				if ((field)&&(confirm("Are you sure you wish to delete '" + field + "' in " + path + "?"))) {
					tinyMCE.activeEditor.setProgressState(1);
					current_content = tinyMCE.activeEditor.getContent();
					ajax_URL = editor_index + "?page=content_submit";
					data = new Object();
					data["status"] = 6;
					data["path"] = path;
					data["field"] = field;
					data["content"] = current_content;
					data = ajax_serialize(data, 1);
					success_code = "show_deleted_content('" + path + "', '" + field + "', ajax_response);";
					path_label = (content_type == "database") ? "fields" : "file" ;
					failure_code = "alert(\"There was an error deleting the content from the '" + path + "' " + path_label + ".\");";
					ajax_request(ajax_URL, success_code, failure_code, "POST", "text", data);
				}
			}
			
			function show_unsaved_content() {
				current_content = tinyMCE.activeEditor.getContent();
				if ((current_content != saved_content)&&(!show_unsaved)) {
					document.getElementById("content_editor_controls_status").innerHTML = "(unsaved)";
					show_unsaved = 1;
				}
			}

			function show_saved_content(path, field, result) {
				if (result == "1") {
					saved_content = tinyMCE.activeEditor.getContent();
					if (document.getElementById("content_editor_controls_name").innerHTML.indexOf("<input") != -1) {
						// if we just added a new field, reload the path contents in the browser, and the field contents in the editor to update the editing controls, then set the content status
						click_path(path, 1, "click_field('" + path + "', '" + field + "', '', 'document.getElementById(\"content_editor_controls_status\").innerHTML = \"(saved)\";');");
					} else {
						// otherwise just reload the path contents and update the content status
						click_path(path, 1);
						document.getElementById("content_editor_controls_status").innerHTML = "(saved)";
					}
					if (document.getElementById("content_editor_controls_delete").innerHTML.indexOf("revert") == -1) {
						// if it wasn't already there, add a Revert button
						revert_command = "revert_content('" + path + "', '" + field + "');"
						document.getElementById("content_editor_controls_delete").innerHTML = "<input type=\"button\" value=\"Revert\" onclick=\"" + revert_command + "\" class=\"form\" />" + document.getElementById("content_editor_controls_delete").innerHTML;
					}
					show_unsaved = 0;
				} else {
					alert("There was an error saving the content.");
					//alert(result); // debug
				}
				tinyMCE.activeEditor.setProgressState(0);
			}

			function show_reverted_content(path, field, result) {
				//alert(result); // debug
				if (result.indexOf("ERROR") == -1) {
					saved_content = tinyMCE.activeEditor.getContent();
					// reload the field contents in the browser, then set the content status
					click_path(path, 1, "click_field('" + path + "', '" + field + "', '', 'document.getElementById(\"content_editor_controls_status\").innerHTML = \"(reverted)\";');");
					show_unsaved = 0;
				} else {
					alert("There was an error reverting the content.");
				}
				tinyMCE.activeEditor.setProgressState(0);
			}

			function show_deleted_content(path, field, result) {
				if (result == "1") {
					tinyMCE.activeEditor.setContent("");
					saved_content = tinyMCE.activeEditor.getContent();
					// reload the path contents in the browser
					click_path(path, 1);
					// clear the editor so there's no ambiguity about the status of the field
					document.getElementById("content_editor_controls_name").innerHTML = "Deleted " + field + " from " + path;
					document.getElementById("content_editor_controls_delete").innerHTML = "";
					document.getElementById("content_editor_controls_schedule").innerHTML = "";
					document.getElementById("content_editor_controls_comment").innerHTML = "";
					document.getElementById("content_editor_controls_save").innerHTML = "";
					show_unsaved = 0;
				} else {
					alert("There was an error deleting the content.");
					//alert(result); // debug
				}
				tinyMCE.activeEditor.setProgressState(0);
			}
			
			function show_content_scripts(content) {
				// JavaScript delimiters
				//content = content.replace(/(<script[\s\S]*?>[\s\S]*?)<([\s\S]*?<\/script>)/gim, "$1&lt;$2");
				//content = content.replace(/(<script[\s\S]*?>[\s\S]*?)>([\s\S]*?<\/script>)/gim, "$1&gt;$2");
				content = content.replace(/<script([\s\S]*?)>/gim, "&lt;script$1&gt;");
				content = content.replace(/<\/script>/gim, "&lt;\/script&gt;");
				
				// PHP-style delimiters
				//content = content.replace(/(<\?[\s\S]*?)<([\s\S]*?\?>)/gim, "$1&lt;$2");
				//content = content.replace(/(<\?[\s\S]*?)>([\s\S]*?\?>)/gim, "$1&gt;$2");
				content = content.replace(/<\?/gim, "&lt;?");
				content = content.replace(/\?\>/gim, "?&gt;");
				
				// ASP-style delimiters
				//content = content.replace(/(<\%[\s\S]*?)<([\s\S]*?\%>)/gim, "$1&lt;$2");
				//content = content.replace(/(<\%[\s\S]*?)>([\s\S]*?\%>)/gim, "$1&gt;$2");
				content = content.replace(/<\%/gim, "&lt;%");
				content = content.replace(/\%\>/gim, "%&gt;");
				return content;
			}
			
			function activate_content_scripts(content) {
				// JavaScript delimiters
				content = content.replace(/&lt;script([\s\S]*?)&gt;/gim, "<script$1>");
				content = content.replace(/&lt;\/script&gt;/gim, "<\/script>");
				content = content.replace(/(<script[\s\S]*?>[\s\S]*?)&lt;([\s\S]*?<\/script>)/gim, "$1<$2");
				content = content.replace(/(<script[\s\S]*?>[\s\S]*?)&gt;([\s\S]*?<\/script>)/gim, "$1>$2");
				
				// PHP-style delimiters
				content = content.replace(/&lt;\?/gim, "<\?");
				content = content.replace(/\?&gt;/gim, "?\>");
				content = content.replace(/(<\?[\s\S]*?)&lt;([\s\S]*?\?>)/gim, "$1<$2");
				content = content.replace(/(<\?[\s\S]*?)&gt;([\s\S]*?\?>)/gim, "$1>$2");
				
				// ASP-style delimiters
				content = content.replace(/&lt;%/gim, "<\?");
				content = content.replace(/%&gt;/gim, "?\>");
				content = content.replace(/(<\%[\s\S]*?)&lt;([\s\S]*?%\>)/gim, "$1<$2");
				content = content.replace(/(<\%[\s\S]*?)&gt;([\s\S]*?%\>)/gim, "$1>$2");
				return content;
			}
			
			function strip_multiple_spaces(content) {
				// if a user types multiple spaces, TinyMCE alternates entering spaces and non-breaking spaces; this changes them all back to normal spaces
				if (!multiple_spaces) {
					content = content.replace(/ &nbsp;/g, "  ");
				}
				return content;
			}
			
			function toggle_schedule_menus() {
				if (document.content_edit.schedule.checked) {
					// set the menus to the current time
					select_date("content_edit.schedule", "");
					select_time("content_edit.schedule", "", 15);
				} else {
					// clear the menus	
					select_date("content_edit.schedule", "-1");
					select_time("content_edit.schedule", "-1", 15);
				}
			}

			function clear_schedule_menus() {
				select_date("content_edit.schedule", "-1");
				select_time("content_edit.schedule", "-1", 0);
			}
			
			function show_feedback(message) {
				document.getElementById("feedback").innerHTML = message;
			}
			
			function clear_feedback() {
				document.getElementById('feedback').innerHTML = "";
			}
			
			function warn_unsaved(action) {
				current_content = tinyMCE.activeEditor.getContent();
				if (current_content == saved_content) {
					return true;
				} else {
					if (action == "load") {
						message = "Your content is not saved. Are you sure you want to load new content?";
						return confirm(message);
					} else if (action == "leave") {
						message = "Your content is not saved. Are you sure you want to leave the editor?";
						return true; // returning false doesn't stop the unload event, so there's no point in using this
					}
				}
			}
			
			function remember_open_paths(path, type, state) {
				open_paths = get_cookie("content_browser", "open_" + type);
				open_paths = (open_paths) ? open_paths.split(",") : new Array() ;
				path_position = get_position(path, open_paths);
				if (state) {
					if (path_position == -1) {
						open_paths.push(path);
					}
				} else {
					if (path_position != -1) {
						open_paths.splice(path_position);
					}
				}
				open_paths = open_paths.join(",");
				set_cookie("content_browser", "open_" + type, open_paths);
			}
			
			/* this doesn't work because multiple paths would need to be queued for AJAX execution, so we're doing it in the PHP functions instead
			function show_open_paths(type) {
				open_paths = get_cookie("content_browser", "open_" + type);
				alert("open paths: " + open_paths);
				open_paths = (open_paths) ? open_paths.split(",") : new Array() ;
				open_paths_count = open_paths.length;
				for (i=0; i<open_paths_count; i++) {
					if (type == "files") {
						alert("opening file " + open_paths[i]);
						click_file(open_paths[i], 1);
					} else if (type == "directories") {
						click_group(open_paths[i], 1);
					}
				}
			}
			*/
			
			function remember_open_field(path, field) {
				set_cookie("content_browser", "open_field", path + "," + field);
			}
			
			function show_open_field() {
				open_field = get_cookie("content_browser", "open_field");
				if (open_field) {
					open_field = open_field.split(",");
					path = open_field[0];
					field = open_field[1];
					click_field(path, field);
				}
			}
			
			function set_editor_color(color) {
				if (!color) { color = default_editor_color; }
				tinyMCE.getInstanceById("content_editor_field").getWin().document.body.style.backgroundColor = color;
			}
			
			saved_content = "";
			show_unsaved = 0;
			
		</script>
	</head>
	
	<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	
		<?php eval(include_namespace(HEADER_FILE)); ?>

		<p class="title">Edit content</p>
		
		<div id="feedback"></div>

		<div id="content_browser" class="body"></div>
		
		<div id="content_editor" class="body">
			<script type="text/javascript" src="<?php print EDITOR_SUBDIRECTORY; ?>/thirdparty/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript">
				tinyMCE.init({
					// general options
					// removed: save, iespell, insertdatetime, preview, directionality, visualchars, template, imagemanager, filemanager
					mode : "textareas",
					theme : "advanced",
					plugins : "safari,spellchecker,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,inlinepopups,media,searchreplace,contextmenu,paste,fullscreen,noneditable,nonbreaking,xhtmlxtras",
					height : "400",
				
					// theme options
					// removed: save, newdocument, hr, iespell, insertdate, inserttime, preview, print, visualchars, template
					theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,search,replace,|,spellchecker,|,fullscreen,visualaid,code,cleanup,|,help",
					theme_advanced_buttons2 : "styleselect,formatselect,attribs,styleprops,removeformat,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote",
					theme_advanced_buttons3 : "forecolor,backcolor,|,sub,sup,|,cite,abbr,acronym,del,ins,|,fontselect,fontsizeselect",
					theme_advanced_buttons4 : "link,unlink,anchor,image,media,|,insertlayer,moveforward,movebackward,absolute,|,tablecontrols,|,nonbreaking,advhr,pagebreak,charmap,emotions",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : true,
					theme_advanced_resize_horizontal : false,
				
					// content CSS
					content_css : "<?php print SITE_STYLESHEET; ?>",
				
					// drop lists for link/image/media/template dialogs
					//template_external_list_url : "js/template_list.js",
					//external_link_list_url : "js/link_list.js",
					external_image_list_url : "<?php print $editor_index; ?>?page=ajax_handler&command=get_images%28%29",
					//media_external_list_url : "js/media_list.js",

					// advanced options
					extended_valid_elements : "script[*],div[*],input[*],form[*]",
					oninit : "set_editor_color",
					onchange_callback : "show_unsaved_content",
					remove_linebreaks : false,
					convert_urls : false,
					button_tile_map : true
				});
			</script>
			
			<form name="content_edit" onsubmit="return false;">
				<div class="content_editor_controls_upper"><div class="content_editor_controls_inner">
					<div id="content_editor_controls_name"></div>
					<div id="content_editor_controls_delete"></div>
					<div class="reset_right"></div>
				</div></div>
				<textarea name="content" id="content_editor_field" style="width: 100%;" rows="5" cols="20"></textarea>
				<div class="content_editor_controls_lower"><div class="content_editor_controls_inner">
					<div id="content_editor_controls_schedule"></div>
					<div id="content_editor_controls_comment"></div>
					<div id="content_editor_controls_save"></div>
					<div class="reset_right"></div>
				</div></div>
			</form>
		</div>
		
		<script language="JavaScript">
			<?php print $onload; ?>
			document.onunload = "warn_unsaved('leave')";
		</script>
		
		<?php eval(include_namespace(FOOTER_FILE)); ?>

	</body>
	
</html>