<?php
if (!defined('IS_DEDI')) die();
include_once($cfg_dedi['dedi_path'].'inc/inc.init_external.php'); ?>
<html style="width:800px; height:600px;">
<head>
<title>Editor</title>
 <?php echo '<meta http-equiv="content-type" content="text/html; charset='.$lang_charset.'">'."\n"; ?>
<link rel="stylesheet" type="text/css" href="<?PHP echo $cfg_dedi['dedi_html_path']; ?>tpl/<?PHP echo $cfg_dedi['skin']; ?>/css/styles.css">
<style type="text/css">
  body {background-color: #DBE3EF; font-family: "Verdana"; font-size: x-small;}
  TD {font-family: "Verdana"; font-size: x-small;}
  .borders {border:1px dotted #ff0000;height:20px}
  MARQUEE {border:1px dashed #0066FF;height:20px}
</STYLE>
<SCRIPT>
function stoperror() {
	return true
}
</SCRIPT>
<script>

// if we pass the "window" object as a argument and then set opener to
// equal that we can refer to dialogWindows and popupWindows the same way
if (window.dialogArguments) opener = window.dialogArguments;
document.write('<scr'+'ipt src="<?PHP echo $sess->url($cfg_dedi['dedi_html_path'].'external/wysiwyg/wysiwyg2.php'); ?>" language="Javascript1.2"></scr'+'ipt>');
var parent_objname = "<?php echo $objname; ?>";
var parent_config = opener.document.all[parent_objname].config;
var editor_conf = cloneObject(parent_config);
var objname = 'editor'; // name of this editor
/* ---------------------------------------------------------------------- *\
  Function    :
  Description :
\* ---------------------------------------------------------------------- */
function _CloseOnEsc() {
	if (event.keyCode == 27) {
		update_parent();
		window.close();
		return;
	}
}

/* ---------------------------------------------------------------------- *\
  Function    : cloneObject
  Description : copy an object by value instead of by reference
  Usage       : var newObj = cloneObject(oldObj);
\* ---------------------------------------------------------------------- */

function cloneObject(obj) {
	var newObj = new Object;

	// check for array objects
	if (obj.constructor.toString().indexOf('function Array(') == 1) newObj = obj.constructor();
	for (var n in obj) {
		var node = obj[n];

		if (typeof node == 'object') newObj[n] = cloneObject(node);
		else newObj[n] = node;
	}
	return newObj;
}

/* ---------------------------------------------------------------------- *\
  Function    : resize_editor
  Description : resize the editor when the user resizes the popup
\* ---------------------------------------------------------------------- */

function resize_editor() {
	var editor = document.all['_editor_editor'];

	newWidth  = document.body.offsetWidth;
	newHeight = document.body.offsetHeight - editor.offsetTop;
	if (newWidth < 0) newWidth = 0;
	if (newHeight < 0) newHeight = 0;
	editor.style.width  = newWidth;
	editor.style.height = newHeight;
}

/* ---------------------------------------------------------------------- *\
  Function    : init
  Description : run this code on page load
\* ---------------------------------------------------------------------- */

function init() {
	// generate editor and resize it
	editor_generate(objname);
	resize_editor();

	// switch mode if needed
	if (parent_config.mode == 'textedit') editor_setmode(objname, 'textedit');

	// set child window contents
	var parentHTML = opener.editor_getHTML(parent_objname);
	editor_setHTML(objname, parentHTML);

	// continuously update parent editor window
	window.setInterval(update_parent, 333);

	// setup event handlers
	document.body.onkeypress = _CloseOnEsc;
	window.onresize = resize_editor;
}

/* ---------------------------------------------------------------------- *\
  Function    : update_parent
  Description : update parent window editor field with contents from child window
\* ---------------------------------------------------------------------- */

function update_parent() {
	var childHTML = editor_getHTML(objname);
	opener.editor_setHTML(parent_objname, childHTML);
}
</script>
</head>
<body scroll="no" onload="init()" onunload="update_parent()">
<textarea name="editor" style="width:100%; height:300px"></textarea><br>
</body>
</html>