<?php
include_once ('../../inc/inc.init_external.php');
$cfg_client = $val_ct -> get_by_group('cfg_client', $client);
?>
// write out styles for UI buttons
/*document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
document.write('on error resume next \n');
document.write('spellEnabled = (IsObject(CreateObject("Word.Application"))) \n');
document.write('</SCR' + 'IPT\> \n');*/

/* ---------------------------------------------------------------------- *\
  Function    : editor_defaultConfig
  Description : default configuration settings for wysiwyg editor
\* ---------------------------------------------------------------------- */
function editor_defaultConfig(objname) {
this.toolbar = [// 1. Zeile
	      ['selectall','cut','copy','paste','delete','remove','undo','redo','find','changecase'],
	      ['InsertTable','showborder','TableProperties','RowProperties','InsertRowBefore','InsertRowAfter','DeleteRow','SplitRow','InsertColumnBefore','InsertColumnAfter','DeleteColumn','CellProperties','InsertCellBefore','InsertCellAfter','DeleteCell','SplitCell','MergeCells'],
	      ['linebreak'],

	      // 2. Zeile
	      ['bold','italic','underline','strikethrough','subscript','superscript','justifyleft','justifycenter','justifyright','justifyfull','justifynone'],
	      ['forecolor','backcolor','OrderedList','UnOrderedList','Outdent','Indent'],
	      ['insertlink','insertfile','unlink','InsertImage','liveresize', 'multipleselect'],
	      ['line','specchar','today','marquee'],
	      ['linebreak'],

	      // 3. Zeile
	      ['refresh','preview','print'],
	      ['fontstyle'],
	      ['fontname'],
	      ['fontsize'],
	      ['htmlmode','popupeditor']];

this.fontnames = {'Arial'		: 'arial, helvetica, sans-serif',
		 'Courier New' 		: 'courier new, courier, mono',
		 'Georgia'		: 'Georgia, Times New Roman, Times, Serif',
		 'Tahoma'		: 'Tahoma, Arial, Helvetica, sans-serif',
		 'Times New Roman'	: 'times new roman, times, serif',
		 'Verdana'		: 'Verdana, Arial, Helvetica, sans-serif'};

this.fontsizes = {'1 (8 pt)'	: '1',
		 '2 (10 pt)'	: '2',
		 '3 (12 pt)'	: '3',
		 '4 (14 pt)'	: '4',
		 '5 (18 pt)'	: '5',
		 '6 (24 pt)'	: '6',
		 '7 (36 pt)'	: '7'};

this.btnList = {
//	 buttonName:	  commandID,	       	   title,						onclick,                  image,
	'removefont'	: ['RemoveFont', 	   '<?php echo $dedi_lang['wys_RemoveFont'] ?>', 	'editor_action(this.id)', 'ed_removefont.gif'],
	'htmlmode'	: ['HtmlMode',		   '<?php echo $dedi_lang['wys_HtmlMode']; ?>', 	'editor_setmode(\''+objname+'\')', 'ed_html.gif'],
	'popupeditor'	: ['popupeditor', 	   '<?php echo $dedi_lang['wys_popupeditor'] ?>', 	'editor_action(this.id)', 'fullscreen_maximize.gif'],
	'refresh'	: ['Refresh',              '<?php echo $dedi_lang['wys_Clear Contents'] ?>',	'editor_action(this.id)',   'ed_refresh.gif'],
	'preview'	: ['Preview',              '<?php echo $dedi_lang['wys_Preview'] ?>',		'editor_action(this.id)',   'ed_preview.gif'],
	'print'		: ['Print',                '<?php echo $dedi_lang['wys_Print'] ?>',		'editor_action(this.id)',   'ed_print.gif'],
	'selectall'	: ['selectall',            '<?php echo $dedi_lang['wys_selectall'] ?>',		'editor_action(this.id)',   'ed_selectall.gif'],
	'cut'		: ['Cut',                  '<?php echo $dedi_lang['wys_Cut'] ?>',      		'editor_action(this.id)',   'ed_cut.gif'],
	'copy'		: ['Copy',                 '<?php echo $dedi_lang['wys_Copy'] ?>',     		'editor_action(this.id)',   'ed_copy.gif'],
	'paste'		: ['Paste',                '<?php echo $dedi_lang['wys_Paste'] ?>',    		'editor_action(this.id)',   'ed_paste.gif'],
	'delete'	: ['delete',               '<?php echo $dedi_lang['wys_delete'] ?>',   		'editor_action(this.id)',   'ed_delete.gif'],
	'remove'	: ['RemoveFormat',         '<?php echo $dedi_lang['wys_RemoveFormat'] ?>',	'editor_action(this.id)',   'ed_remove.gif'],
	'undo'		: ['Undo',                 '<?php echo $dedi_lang['wys_Undo'] ?>',   		'editor_action(this.id)',   'ed_undo.gif'],
	'redo'		: ['Redo',                 '<?php echo $dedi_lang['wys_Redo'] ?>',		'editor_action(this.id)',   'ed_redo.gif'],
	'find'		: ['Find',                 '<?php echo $dedi_lang['wys_Find'] ?>',		'editor_action(this.id)',  'ed_find.gif'],
	'changecase'	: ['changecase',           '<?php echo $dedi_lang['wys_changecase'] ?>',	'editor_action(this.id)',   'ed_changecase.gif'],
	'bold'		: ['Bold',                 '<?php echo $dedi_lang['wys_Bold'] ?>',		'editor_action(this.id)',  'ed_format_bold.gif'],
	'italic'	: ['Italic',               '<?php echo $dedi_lang['wys_Italic'] ?>',		'editor_action(this.id)',  'ed_format_italic.gif'],
	'underline'	: ['Underline',            '<?php echo $dedi_lang['wys_Underline'] ?>',		'editor_action(this.id)',  'ed_format_underline.gif'],
	'strikethrough'	: ['StrikeThrough',        '<?php echo $dedi_lang['wys_StrikeThrough'] ?>',	'editor_action(this.id)',  'ed_format_strike.gif'],
	'subscript'	: ['SubScript',            '<?php echo $dedi_lang['wys_SubScript'] ?>',		'editor_action(this.id)',  'ed_format_sub.gif'],
	'superscript'	: ['SuperScript',          '<?php echo $dedi_lang['wys_SuperScript'] ?>',	'editor_action(this.id)',  'ed_format_sup.gif'],
	'justifyleft'	: ['JustifyLeft',          '<?php echo $dedi_lang['wys_JustifyLeft'] ?>',	'editor_action(this.id)',  'ed_align_left.gif'],
	'justifycenter'	: ['JustifyCenter',        '<?php echo $dedi_lang['wys_JustifyCenter'] ?>',	'editor_action(this.id)',  'ed_align_center.gif'],
	'justifyright'	: ['JustifyRight',         '<?php echo $dedi_lang['wys_JustifyRight'] ?>',	'editor_action(this.id)',  'ed_align_right.gif'],
	'justifyfull'	: ['JustifyFull',          '<?php echo $dedi_lang['wys_JustifyFull'] ?>',	'editor_action(this.id)', 'ed_align_justify.gif'],
	'justifynone'	: ['JustifyNone', 	   '<?php echo $dedi_lang['wys_JustifyNone'] ?>',    	'editor_action(this.id)', 'ed_align_none.gif'],
	'orderedlist'	: ['InsertOrderedList',    '<?php echo $dedi_lang['wys_OrderedList'] ?>', 	'editor_action(this.id)',  'ed_list_num.gif'],
	'unorderedlist'	: ['InsertUnorderedList',  '<?php echo $dedi_lang['wys_UnorderedList'] ?>',	'editor_action(this.id)',  'ed_list_bullet.gif'],
	'outdent'	: ['Outdent',              '<?php echo $dedi_lang['wys_Outdent'] ?>',		'editor_action(this.id)',  'ed_indent_less.gif'],
	'indent'	: ['Indent',               '<?php echo $dedi_lang['wys_Indent'] ?>',		'editor_action(this.id)',  'ed_indent_more.gif'],
	'forecolor'	: ['ForeColor',            '<?php echo $dedi_lang['wys_ForeColor'] ?>',		'editor_action(this.id)',  'ed_color_fg.gif'],
	'backcolor'	: ['BackColor',            '<?php echo $dedi_lang['wys_BackColor'] ?>',		'editor_action(this.id)',  'ed_color_bg.gif'],
	'marquee'	: ['marquee',              '<?php echo $dedi_lang['wys_marquee'] ?>',  		'editor_action(this.id)', 	'ed_marquee.gif'],
	'line'		: ['line',                 '<?php echo $dedi_lang['wys_line'] ?>',     		'editor_action(this.id)',  'ed_line.gif'],
	'specchar'	: ['SpecChar',             '<?php echo $dedi_lang['wys_SpecChar'] ?>', 		'editor_action(this.id)',  	'ed_spec_char.gif'],
	'insertlink'	: ['insertlink',           '<?php echo $dedi_lang['wys_insertlink'] ?>',	'editor_action(this.id)',  'ed_link.gif'],
	'insertfile'	: ['insertfile',           '<?php echo $dedi_lang['wys_insertfile'] ?>',	'editor_action(this.id)',  'ed_link_file.gif'],
	'unlink'	: ['unlink',               '<?php echo $dedi_lang['wys_unlink'] ?>',		'editor_action(this.id)',   'ed_unlink.gif'],
	'insertimage'	: ['InsertImage',          '<?php echo $dedi_lang['wys_InsertImage'] ?>',	'editor_action(this.id)',  'ed_image.gif'],
	'multipleselect': ['MultipleSelection',    '<?php echo $dedi_lang['wys_MultipleSel'] ?>',	'editor_action(this.id)',  	'ed_multipleselect.gif'],
	'liveresize'	: ['LiveResize',     	   '<?php echo $dedi_lang['wys_LiveResize'] ?>', 	'editor_action(this.id)',  	'ed_live.gif'],
	'today'		: ['Today',                '<?php echo $dedi_lang['wys_Today'] ?>',    		'editor_action(this.id)',  'ed_date.gif'],
	'inserttable'	: ['InsertTable',          '<?php echo $dedi_lang['wys_InsertTable'] ?>',	'editor_action(this.id)',  'insert_table.gif'],
	'tableproperties':['TableProperties',      '<?php echo $dedi_lang['wys_TableProps'] ?>',	'editor_action(this.id)',  'ed_tableprop.gif'],
	'showborder'	: ['ShowBorder',           '<?php echo $dedi_lang['wys_ShowBorder'] ?>',	'editor_action(this.id)',  'ed_show_border.gif'],
	'rowproperties'	: ['RowProperties',        '<?php echo $dedi_lang['wys_RowProperties'] ?>',	'editor_action(this.id)',  'ed_rowprop.gif'],
	'insertrowbefore':['InsertRowBefore',      '<?php echo $dedi_lang['wys_InsertRowBefore'] ?>',	'editor_action(this.id)',  'ed_insabove.gif'],
	'insertrowafter': ['InsertRowAfter',       '<?php echo $dedi_lang['wys_InsertRowAfter'] ?>',	'editor_action(this.id)',  'ed_insunder.gif'],
	'deleterow'	: ['DeleteRow',            '<?php echo $dedi_lang['wys_DeleteRow'] ?>',		'editor_action(this.id)',  'ed_delrow.gif'],
	'splitrow'	: ['SplitRow',             '<?php echo $dedi_lang['wys_SplitRow'] ?>',		'editor_action(this.id)',  'ed_splitrow.gif'],
	'insertcolumnbefore':['InsertColumnBefore','<?php echo $dedi_lang['wys_InsertColumnBefore'] ?>','editor_action(this.id)',  'ed_insleft.gif'],
	'insertcolumnafter':['InsertColumnAfter',  '<?php echo $dedi_lang['wys_InsertColumnAfter'] ?>',	'editor_action(this.id)',  'ed_insright.gif'],
	'deletecolumn'	: ['DeleteColumn',         '<?php echo $dedi_lang['wys_DeleteColumn'] ?>',	'editor_action(this.id)',  'ed_delcol.gif'],
	'cellproperties': ['CellProperties',       '<?php echo $dedi_lang['wys_CellProperties'] ?>',	'editor_action(this.id)',  'ed_cellprop.gif'],
	'insertcellbefore':['InsertCellBefore',    '<?php echo $dedi_lang['wys_InsertCellBefore'] ?>',	'editor_action(this.id)',  'ed_inscellft.gif'],
	'insertcellafter':['InsertCellAfter',      '<?php echo $dedi_lang['wys_InsertCellAfter'] ?>',	'editor_action(this.id)',  'ed_inscelrgt.gif'],
	'deletecell'	: ['DeleteCell',           '<?php echo $dedi_lang['wys_DeleteCell'] ?>',       	'editor_action(this.id)',  'ed_delcel.gif'],
	'splitcell'	: ['SplitCell',            '<?php echo $dedi_lang['wys_SplitCell'] ?>',		'editor_action(this.id)',  'ed_splitcel.gif'],
	'mergecells'	: ['MergeCells',           '<?php echo $dedi_lang['wys_MergeCells'] ?>',       	'editor_action(this.id)',  'ed_mergecels.gif'],
	'spell'		: ['spell',		   '<?php echo $dedi_lang['wys_spell'] ?>',		'editor_action(this.id);', 'ed_spellcheck.gif']};

this.replaceNextlines = 0; // replace nextlines from spaces (on output)
this.plaintextInput = 0; // replace nextlines with breaks (on input)
this.showborders = true;
if (objname == 'editor') this.btnList['popupeditor'] = ['popupeditor', 'Minimize Editor',  'update_parent(); window.close();', 'fullscreen_minimize.gif'];
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_generate
  Description : replace textarea with wysiwyg editor
  Usage       : editor_generate("textarea_id",[height],[width+]);
  Arguments   : objname - ID of textarea to replace
                w       - width of wysiwyg editor
                h       - height of wysiwyg editor
\* ---------------------------------------------------------------------- */
function editor_generate(objname) {

	// Konfigurationsparameter speichern
	document.all[objname].config = new editor_defaultConfig(objname);
	if (eval(objname+'_conf')['toolbar']) document.all[objname].config.toolbar = eval(objname+'_conf')['toolbar'];
	if (eval(objname+'_conf')['style']) document.all[objname].config.style = eval(objname+'_conf')['style'];
	if (eval(objname+'_conf')['stylesheet']) document.all[objname].config.stylesheet = eval(objname+'_conf')['stylesheet'];
	if (eval(objname+'_conf')['fontstyles']) document.all[objname].config.fontstyles = eval(objname+'_conf')['fontstyles'];
	if (eval(objname+'_conf')['imagefiletypes']) document.all[objname].config.imagefiletypes = eval(objname+'_conf')['imagefiletypes'];
	if (eval(objname+'_conf')['imagefolders']) document.all[objname].config.imagefolders = eval(objname+'_conf')['imagefolders'];
	if (eval(objname+'_conf')['imagesubfolders']) document.all[objname].config.imagesubfolders = eval(objname+'_conf')['imagesubfolders'];
	if (eval(objname+'_conf')['filefiletypes']) document.all[objname].config.filefiletypes = eval(objname+'_conf')['filefiletypes'];
	if (eval(objname+'_conf')['filefolders']) document.all[objname].config.filefolders = eval(objname+'_conf')['filefolders'];
	if (eval(objname+'_conf')['filesubfolders']) document.all[objname].config.filesubfolders = eval(objname+'_conf')['filesubfolders'];
	var config = document.all[objname].config;

	// Groesze setzen
	var obj = document.all[objname];
	var tblOpen  = '<table border=0 cellspacing=2 cellpadding=0 style="float: left;"  unselectable="on"><tr><td style="border: inset 1px;"><nobr>';
	var tblClose = '</nobr></td></tr></table>\n';

	// Toolbar generieren
	var toolbar = '';
	var btnGroup, btnItem, aboutEditor;
	for (var btnGroup in config.toolbar) {
		// Zeilenumbruch
		if (config.toolbar[btnGroup].length == 1 && config.toolbar[btnGroup][0].toLowerCase() == 'linebreak') {
			toolbar += '<br clear="all">';
			continue;
		}
		toolbar += tblOpen;
		for (var btnItem in config.toolbar[btnGroup]) {
			var btnName = config.toolbar[btnGroup][btnItem].toLowerCase();

			// Schriftnamen
			if (btnName == 'fontname') {
				toolbar += '<select id="_'+objname+'_FontName" onChange="editor_action(this.id)" unselectable="on">';
				for (var fontname in config.fontnames) toolbar += '<option value="' +config.fontnames[fontname]+ '">' +fontname+ '</option>'
				toolbar += '</select>';
				continue;
			}

			// Schriftgroeszen
			if (btnName == 'fontsize') {
				toolbar += '<select id="_'+objname+'_FontSize" onChange="editor_action(this.id)" unselectable="on">';
				for (var fontsize in config.fontsizes) toolbar += '<option value="' +config.fontsizes[fontsize]+ '">' +fontsize+ '</option>'
				toolbar += '</select>\n';
				continue;
			}

			// Schriftarten
			if (btnName == 'fontstyle') {
				toolbar += '<select id="_'+objname+'_FontStyle" onChange="editor_action(this.id)" unselectable="on">';
				toolbar += '<option value="">Schriftarten</option>';
				for (var i in config.fontstyles) {
					var fontstyle = config.fontstyles[i];
					toolbar += '<option value="' +fontstyle.className+ '">' +fontstyle.name+ '</option>'
				}
				toolbar += '</select>';
				continue;
			}

			// Schaltflaechen
			var btnObj = config.btnList[btnName];
			if (btnName == 'linebreak') {
				alert("htmlArea error: 'linebreak' must be in a subgroup by itself, not with other buttons.\n\nhtmlArea wysiwyg editor not created.");
				return;
			}
			if (!btnObj) {
	                 	alert("htmlArea error: button '" +btnName+ "' not found in button list when creating the wysiwyg editor for '"+objname+"'.\nPlease make sure you entered the button name correctly.\n\nhtmlArea wysiwyg editor not created.");
	                         return;
			}
			var btnCmdID   = btnObj[0];
			var btnTitle   = btnObj[1];
			var btnOnClick = btnObj[2];
			var btnImage   = btnObj[3];
			toolbar += '<button title="' +btnTitle+ '" id="_'+objname+'_'+btnCmdID+ '" class="btn" onClick="' +btnOnClick+ '" onmouseover="if(this.className==\'btn\'){this.className=\'btnOver\'}" onmouseout="if(this.className==\'btnOver\'){this.className=\'btn\'}" unselectable="on"><img src="<?PHP echo $cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin']; ?>/img/wysiwyg/' + btnImage+ '" border=0 unselectable="on"></button>';
		}
		toolbar += tblClose;
	}

	// Editor generieren
	var editor = '<span id="_editor_toolbar"><table border=0 cellspacing=0 cellpadding=0 style="padding: 1 0 0 0" width="640" unselectable="on"><tr><td>\n'
	+ toolbar
	+ '</td></tr></table>\n'
	+ '</td></tr></table></span>\n'
	+ '<textarea ID="_'+objname+'_editor" style="width: 640; height: 300; margin-top: -1px; margin-bottom: -1px;" wrap=soft></textarea>';
	+ '<div id="_'+objname+'_cMenu" style="position: absolute; visibility: hidden;"></div>';

	// Textarea verstecken und HTMLAREA einfuegen
	document.all[objname].style.display = 'none';
	if (config.plaintextInput) {
		var contents = document.all[objname].value;
		contents = contents.replace(/\r\n/g, '<br>');
		contents = contents.replace(/\n/g, '<br>');
		contents = contents.replace(/\r/g, '<br>');
		document.all[objname].value = contents;
	}
	document.all[objname].insertAdjacentHTML('afterEnd', editor)

	// Modus umschalten
	editor_setmode(objname, 'init');

	// filterOutput aufrufen?
	for (var idx=0; idx < document.forms.length; idx++) {
		var r = document.forms[idx].attachEvent('onsubmit', function() {editor_filterOutput(objname);});
		if (!r) alert("Error attaching event to form!");
	}
	return true;
}

/* ---------------------------------------------------------------------- *\
  Funktion    : editor_action
  Beschreibung: perform an editor command on selected editor content
  Usage       :
  Argumente   : button_id - Schaltflaechen-Id mit Editor und Aktionsnamen
\* ---------------------------------------------------------------------- */

function editor_action(button_id) {
	var BtnParts = Array();
	BtnParts = button_id.split('_');
	var objname    = button_id.replace(/^_(.*)_[^_]*$/, '$1');
	var cmdID      = BtnParts[ BtnParts.length-1 ];
	var button_obj = document.all[button_id];
	var editor_obj = document.all['_'+objname+'_editor'];
	var config     = document.all[objname].config;

	// Editor im Popup anzeigen
	if (cmdID == 'popupeditor') {
		showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=fullscreen&'.$sess->name.'='.$sess->id; ?>&objname="+objname, window, "resizable: yes; help: no; status: no; scroll: no; ", 'popupeditor');
		return;
	}

	// Tabellenrahmen anzeigen
	else if (cmdID == 'ShowBorder') {
		var btnObj = document.all['_'+objname+'_ShowBorder'];
		if (config.showborders) {
			nullBorders(editor_obj.contentWindow.document,'hide');
			btnObj.className = 'btn';
			config.showborders = false;
		} else {
			nullBorders(editor_obj.contentWindow.document,'show');
			btnObj.className = 'btnDown';
			config.showborders = true;
		}
		return;
	}

	// Text durchsuchen
	else if (cmdID == 'Find') {
		setGlobalVar ('_editor_field', objname);
		var TxtRange = editor_obj.contentWindow.document.body.createTextRange();
		showModelessDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=find&view=edit&'.$sess->name.'='.$sess->id; ?>",window, "resizable: no; help: no; status: no; scroll: no; ");
		return;
	}

	// Modus nochmal checken
	if (editor_obj.tagName.toLowerCase() == 'textarea') return;
	var editdoc = editor_obj.contentWindow.document;

	// Vorschau
	if (cmdID == 'Preview') {
		var predoc = editdoc.body.createTextRange().htmlText;
		if (config.showborders) {
			var re1 = /BORDER-RIGHT: #c0c0c0 1px dotted; BORDER-TOP: #c0c0c0 1px dotted; BORDER-LEFT: #c0c0c0 1px dotted; BORDER-BOTTOM: #c0c0c0 1px dotted/g;
			var re2 = / style=""/g;
			predoc = predoc.replace(re1, '');
			predoc = predoc.replace(re2, '');
		}
		win = window.open('','preview','toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes');
		doc=win.document.open();
		// Robert Hartwig 18.07.2004: charset-Variable eingefuegt
		doc.writeln('<html>\n<head>\n<meta http-equiv="content-type" content="text/html; charset=<?php echo $lang_charset ?>">\n<title>Preview</title>');
		if (config.stylesheet) doc.writeln(config.stylesheet);
		doc.writeln('</head>\n');
		doc.writeln('<body topmargin="1" leftmargin="1" ');
		if (config.style) doc.writeln(config.style);
		doc.writeln('>\n');
		doc.writeln(predoc);
		doc.writeln('</body>\n</html>\n');
		doc=win.document.close();
		win.focus();
		return;
	}

	// Editor fokusieren
	editor_focus(editor_obj);

	// get index and value for pulldowns
	var idx = button_obj.selectedIndex;
	var val = (idx != null) ? button_obj[ idx ].value : null;
	if (0) {}   // use else if for easy cutting and pasting

	// aktuelles Datum einfuegen
	else if (cmdID == 'Today') {
		var myTitle = '<?PHP echo $dedi_lang['wys_pop_InsDate']; ?>';
		var myText = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=today&view=edit&'.$sess->name.'='.$sess->id; ?>", myTitle, "resizable: yes; help: no; status: no; scroll: no; ");
		if (myText) { editor_insertHTML(objname, myText); }
	}

	else if (cmdID == 'Refresh') {
		editdoc.execCommand('SelectAll');
		editdoc.execCommand('Delete');
	}

	// Rechtschreibpruefung
	else if (cmdID == 'spell') {
		var str=editdoc.selection.createRange().htmlText;
		var disTag1=str.indexOf('<IMG');
		var disTag2=str.indexOf('<SELECT');
		var disTag3=str.indexOf('<FORM');
		var disTag4=str.indexOf('<INPUT');
		var disTag5=str.indexOf('<BUTTON');
		if (disTag1 >= 0 || disTag2 >= 0 || disTag3 >= 0 || disTag4 >= 0 || disTag5 >= 0) alert("Die Auswahl darf keine Bilder enthalten.");
		else if (!str){alert('Bitte markieren Sie erst einen Bereich, der ueberprueft werden soll.');}
		else {
			editdoc.execCommand('copy');
			CheckDocument();
                         return true;
		}
	}

	// aus Zwischenablage einfuegen
	else if (cmdID == 'Paste') {
		editdoc.execCommand('Paste');
		myclean(editdoc);
	}

	// Schriftart entfernen
	else if (cmdID == 'RemoveFont') {
		oTags = editdoc.all.tags('FONT');
	         if (oTags != null) {
                  	for (var i = oTags.length - 1; i >= 0; i--) oTags[i].outerHTML = oTags[i].innerHTML;
                  }
	}

	// Grosz- und Kleinschreibung aendern
	else if (cmdID == 'changecase') {
		if (editdoc.selection.createRange().htmlText != '') {
			var highlightedText = editdoc.selection.createRange().htmlText;
			editdoc.execCommand('copy');
			editdoc.execCommand('FormatBlock', '', 'Normal')
			editdoc.execCommand('RemoveFormat');
			editdoc.execCommand('unlink');
			var myText = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=changecase&view=edit&'.$sess->name.'='.$sess->id; ?>", highlightedText, "resizable: yes; help: no; status: no; scroll: no; ");
			if (myText) editor_insertHTML(objname, unescape( myText) );
			else {editdoc.execCommand('paste');}
			window.clipboardData.clearData();
		}
		else alert('\n<?php echo $dedi_lang['wys_pop_SelectTextFirst'] ?>');
	}

	// Schriftname
	else if (cmdID == 'FontName' && val) editdoc.execCommand(cmdID,0,val);
	else if (cmdID == 'FormatBlock' && val) editdoc.execCommand(cmdID,0,val);

	// Sonderzeichen einfuegen
	else if (cmdID == 'SpecChar') {
		var newchar = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_char&view=edit&'.$sess->name.'='.$sess->id; ?>", '', "dialogWidth:493px; dialogHeight: 140px; resizable: no; help: no; status: no; scroll: no;");
		if (newchar == '') return;
		else editor_insertHTML(objname,newchar);
	}

	// Schriftgroesze
	else if (cmdID == 'FontSize' && val) editdoc.execCommand(cmdID,0,val);

	// Schriftart (change CSS className)
	else if (cmdID == 'FontStyle' && val) {
		if (val != 'remove') {
			editdoc.execCommand('RemoveFormat');
			editdoc.execCommand('FontName',0,'636c6173734e616d6520706c616365686f6c646572');
			var fontArray = editdoc.all.tags('FONT');
			for (i=0; i<fontArray.length; i++) {
				if (fontArray[i].face == '636c6173734e616d6520706c616365686f6c646572') {
					fontArray[i].face = '';
					fontArray[i].className = val;
					fontArray[i].outerHTML = fontArray[i].outerHTML.replace(/face=['"]+/, '');
				}
			}
			button_obj.selectedIndex = 0;
		} else editdoc.execCommand('RemoveFormat');
	}

	// Text und Hintergrundfarben
	else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
		var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
		var newcolor = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=select_color&view=edit&'.$sess->name.'='.$sess->id; ?>", oldcolor, "resizable: no; help: no; status: no; scroll: no;");
		if (newcolor != null) editdoc.execCommand(cmdID, false, "#"+newcolor);
	}

	// Link einfuegen
	else if (cmdID.toLowerCase() == 'insertlink') {
		var theRange = editdoc.selection.createRange();
		var highlightedText = '';
		var linkText = '';
		var href_attribute = '';
		var tar_attribute = '';
		var elmSelectedImage;
		var htmlSelectionControl = 'Control';
		if (editdoc.selection.type == htmlSelectionControl) {
			elmSelectedImage = theRange.item(0);
			highlightedText = elmSelectedImage.outerHTML;
			theRange = editdoc.body.createTextRange();
			theRange.moveToElementText(elmSelectedImage);
			theRange.select();
			fullElement = theRange.htmlText;
		} else {
			highlightedText = theRange.htmlText;
			fullElement = theRange.parentElement().outerHTML;
		}
		if (highlightedText.search(/^\<[A|a]/) != -1) fullElement = highlightedText;
		if (fullElement.search(/^\<[A|a]/) != -1) {
			fullElement = fullElement.replace(/\"/g, '');
			fullElement = fullElement.replace(/\'/g, '');

			// href herausfinden
			var href_value = fullElement.split(/href=/);
			href_value2 = href_value[1].split(/\s|>/);
			href_attribute = href_value2[0];

			// target herausfinden
			if (fullElement.search(/target=/) != -1) {
				var tar = fullElement.split(/target=/);
				tar2 = tar[1].split(/\s|>/);
				tar_attribute = tar2[0];
			}

			// 3. der Link-Text
			pos1 = fullElement.indexOf('>');
			pos2 = fullElement.lastIndexOf('<');
			linkText = fullElement.substring(pos1+1,pos2);
		}
		var myValues = new Object();
		myValues.highlightedText = highlightedText;
		myValues.tar_attribute = tar_attribute;
		myValues.href_attribute = href_attribute;
		myValues.linkText = linkText;
		var myText = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_link&view=edit&'.$sess->name.'='.$sess->id; ?>", myValues, "status=no; scroll=no");
	      	if (myText == '-1') {
			if(theRange.parentElement().outerHTML.search(/^\<[A|a]/) != -1)	theRange.parentElement().outerHTML = linkText;
			myText = '';
		}
		if (linkText != '') {
			if (myText) {
				theRange.parentElement().outerHTML = '';
				editor_insertHTML(objname, unescape( myText));
			}
		// generiert den Link. Dieser ist immer absolut!
		} else if (myText) editor_insertHTML(objname, unescape(myText));
	}

	// Datei einfuegen
	else if (cmdID.toLowerCase() == 'insertfile') {
		var theRange = editdoc.selection.createRange();
		var highlightedText = '';
		var linkText = '';
		var href_attribute = '';
		var tar_attribute = '';
		var elmSelectedImage;
		var htmlSelectionControl = 'Control';

		if (editdoc.selection.type == htmlSelectionControl) {
			elmSelectedImage = theRange.item(0);
			highlightedText = elmSelectedImage.outerHTML;
			theRange = editdoc.body.createTextRange();
			theRange.moveToElementText(elmSelectedImage);
			theRange.select();
			fullElement = theRange.htmlText;
		} else {
			highlightedText = theRange.htmlText;
			fullElement = theRange.parentElement().outerHTML;
		}

		// in case we happen to select the link itself!
		if (highlightedText.search(/^\<[A|a]/) != -1) fullElement = highlightedText;

		// extrect attributes from HTML
		if (fullElement.search(/^\<[A|a]/) != -1) {
			fullElement = fullElement.replace(/\"/g, '');
			fullElement = fullElement.replace(/\'/g, '');

			// href herausfinden
			var href_value = fullElement.split(/href=/);
			href_value2 = href_value[1].split(/\s|>/);
			href_attribute = href_value2[0];

			// target herausfinden
			if (fullElement.search(/target=/) != -1) {
				var tar = fullElement.split(/target=/);
				tar2 = tar[1].split(/\s|>/);
				tar_attribute = tar2[0];
			}

			// 3. der Link-Text
			pos1 = fullElement.indexOf('>');
			pos2 = fullElement.lastIndexOf('<');
			linkText = fullElement.substring(pos1+1,pos2);
		}
		var myValues = new Object();
		myValues.highlightedText = highlightedText;
		myValues.tar_attribute = tar_attribute;
		myValues.href_attribute = href_attribute;
		myValues.linkText = linkText;
		var myText = showModalDialog("<?PHP echo $cfg_dedi['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_file&view=edit&dummy=true&'.$sess->name.'='.$sess->id; ?>&filetypes="+config.filefiletypes+"&folders="+config.filefolders+"&subfolders="+config.filesubfolders, myValues, "status=no; scroll=no");
	      	if (myText == '-1') {
			if(theRange.parentElement().outerHTML.search(/^\<[A|a]/) != -1) theRange.parentElement().outerHTML = linkText;
			myText = '';
		}
		if (linkText != '') {
			if (myText) {
				theRange.parentElement().outerHTML = '';
				editor_insertHTML(objname, unescape( myText) );
			}
		// generiert den Link. Dieser ist immer absolut!
		} else if (myText) editor_insertHTML(objname, unescape(myText));
	}

	// Bild einfuegen
	else if (cmdID.toLowerCase() == 'insertimage') showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_image&view=edit&dummy=true&'.$sess->name.'='.$sess->id; ?>&filetypes="+config.imagefiletypes+"&folders="+config.imagefolders+"&subfolders="+config.imagesubfolders, editdoc, "resizable: no; help: no; status: no; scroll: no; ");

	// Tabelle einfuegen
	else if (cmdID.toLowerCase() == 'inserttable') {
		setGlobalVar('_editor_field',objname);
		showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_table&view=edit&dummy=true&'.$sess->name.'='.$sess->id; ?>&objname="+objname,window,"resizable: yes; help: no; status: no; scroll: no; ");
		if (config.showborders) nullBorders(editdoc,'show');
	}

	// Linie einfuegen
	else if (cmdID == 'line') {
		setGlobalVar('_editor_field',objname);
		var myText = showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_line&view=edit&'.$sess->name.'='.$sess->id; ?>",window,"resizable: yes; help: no; status: no; scroll: no; ");
		if (myText) editor_insertHTML(objname, unescape(myText));
	}

	// Lauftext einfuegen
	else if (cmdID == 'marquee') {
		var myTitle = '';
		var myText = showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=insert_marquee&view=edit&'.$sess->name.'='.$sess->id; ?>",myTitle,"resizable: yes; help: no; status: no; scroll: no; ");
		if (myText) editor_insertHTML(objname, unescape(myText));
	}

	// Tabellenfunktionen auf Gueltigkeit pruefen
	else if (cmdID == 'TableProperties' || cmdID == 'RowProperties' || cmdID == 'InsertRowBefore' || cmdID == 'InsertRowAfter' || cmdID == 'DeleteRow' || cmdID == 'InsertColumnBefore' || cmdID == 'InsertColumnAfter' || cmdID == 'DeleteColumn' || cmdID == 'CellProperties' || cmdID == 'InsertCellBefore' || cmdID == 'InsertCellAfter' || cmdID == 'SplitCell' || cmdID == 'MergeRows' || cmdID == 'SplitRow' || cmdID == 'MergeCells' || cmdID == 'DeleteCell') {
		var table_src_element = editdoc.selection.createRange().parentElement();
		while (table_src_element != null && table_src_element.tagName != 'TD' && table_src_element.tagName != 'TH') table_src_element = table_src_element.parentElement;
		if (table_src_element == null) alert('Table operations not allowed here');
		else tables_action(button_id,table_src_element);
	}

	// alle anderen Microsoft-Kommandos
	else {
		if (cmdID.toLowerCase() == 'subscript' && editdoc.queryCommandState('superscript')) editdoc.execCommand('superscript');
		if (cmdID.toLowerCase() == 'superscript' && editdoc.queryCommandState('subscript')) editdoc.execCommand('subscript');
         	editdoc.execCommand(cmdID);
         }
	editor_event(objname);
}

/* ---------------------------------------------------------------------- *\
  Funktion    : tables_action
  Beschreibung: perform an action on selected table
  Usage       :
  Argumente   : table_action - objectname + action
\* ---------------------------------------------------------------------- */

// Funktion steht nur in Tabellenzellen zur Verfuegung
function tables_action(table_action,td) {
	if (td.tagName == 'TD' || td.tagName == 'TH') {
		var TableParts = table_action.split('_');
		var objname    = table_action.replace(/^_(.*)_[^_]*$/, '$1');
		var cmdID      = TableParts[ TableParts.length-1 ];
		var editor_obj = document.all['_' +objname + '_editor'];
		var config     = document.all[objname].config;
		var tr,td,tbody,table,newtr;
		tr = td.parentNode;
		while(tr != null && tr.tagName != 'TR') tr = tr.parentNode;
		if (tr != null) {
			var tbody = tr.parentNode;
			while(tbody != null && tbody.tagName != 'TBODY' && tbody.tagName != 'THEAD' && tbody.tagName != 'TFOOT') tbody = tbody.parentNode;
			if (tbody != null) {
				table = tbody.parentNode;
				while(table!= null && table.tagName != 'TABLE') table = table.parentNode;
			}
		}
		if (table != null) {
			function insertRowDetails(tr,newtr) {
				for (var i=0;i < tr.cells.length;i++) newtr.insertCell(-1);
			}

			function insertColumn(tbody,where) {
				for (var i=0;i < tbody.rows.length;i++) {
					tr = tbody.rows(i);
					if (where > tr.cells.length) tr.insertCell();
					else tr.insertCell(where);
				}
			}

			function deleteColumn(tbody,where) {
				for (var i=0;i <  tbody.rows.length;i++) {
					var tr = tbody.rows(i);
					if (tr.cells.length - 1 < where) tr.deleteCell(tr.cells.length - 1);
					else tr.deleteCell(where);
					tr = tbody.rows(i);
		 			if (tr.cells.length == 0) tbody.deleteRow(i);
				}
			}

			function splitCell(tbody,currTr,currTd) {
				if (currTd.colSpan > 1) {
					currTd.colSpan = currTd.colSpan - 1;
					currTr.insertCell(currTd.cellIndex + 1);
				} else {
					for (var i=0;i <  tbody.rows.length;i++) {
						var tr = tbody.rows(i);
						var td = tr.cells(currTd.cellIndex);
						if (i == currTr.rowIndex) tr.insertCell(currTd.cellIndex + 1);
						else td.colSpan = td.colSpan + 1;
					}
				}
			}

			function mergeCells(tbody,currTr,currTd) {
				if (currTd.cellIndex < currTr.cells.length-1) {
					var currColSpan = currTd.colSpan ;
					var mergeCellColSpan = currTr.cells(currTd.cellIndex+1).colSpan;
					var mergeCell = currTr.cells(currTd.cellIndex+1);
					currTd.innerHTML = currTd.innerHTML + mergeCell.innerHTML;
					currTr.deleteCell(currTd.cellIndex + 1);
					currTd.colSpan = currColSpan+mergeCellColSpan ;
				} else alert('Select the leftmost cell of the split to merge.');
			}

			function splitRow(tbody,currTr,currTd) {
				if (currTd.rowSpan > 1) {
					currTd.rowSpan = currTd.rowSpan - 1;
					var tr = tbody.rows(currTr.rowIndex + 1);
					var where = 0;
					for (var i=0;i <  currTr.cells.length;i++) {
						if (i < currTd.cellIndex) if (currTr.cells(i).rowSpan < 2){where++;}
					}
					tr.insertCell(where);
				} else {
					for (var i=0;i <  currTr.cells.length;i++) {
						var td = currTr.cells(i);
						if (i == currTd.cellIndex) {
							tr = tbody.insertRow(currTr.rowIndex + 1);
							tr.insertCell(0);
						} else td.rowSpan = td.rowSpan + 1;
					}
				}
			}

			function mergeRows(tbody,currTr,currTd) {
				var top = false;
				if (currTd.rowSpan < 2) {
					for (var i=0;i <  currTr.cells.length;i++) {
						if (i !== currTd.cellIndex) {
							if (currTr.cells(i).rowSpan > 1) top = true; break;
						}
					}
				}
				if (top) return;
				else alert('Select the topmost row of the split to merge.');
			}
			switch(cmdID) {
				case 'CreateCaption'      : table.createCaption();break;
				case 'DeleteCaption'      : table.deleteCaption();break;
				case 'CreateTHead'        : table.createTHead();break;
				case 'DeleteTHead'        : table.deleteTHead();break;
				case 'CreateTFoot'        : table.createTFoot();break;
				case 'DeleteTFoot'        : table.deleteTFoot();break;
				case 'InsertRowTop'       : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
				case 'InsertRowBottom'    : newtr = tbody.insertRow(-1);insertRowDetails(tr,newtr);break;
				case 'InsertRowBefore'    : newtr = tbody.insertRow(tr.rowIndex);insertRowDetails(tr,newtr);break;
				case 'InsertRowAfter'     : newtr = tbody.insertRow(tr.rowIndex+1);insertRowDetails(tr,newtr);break;
				case 'InsertRowStart'     : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
				case 'DeleteRow'          : tbody.deleteRow(tr.rowIndex);break;
				case 'InsertColumnLeft'   : insertColumn(tbody,0);break;
				case 'InsertColumnRight'  : insertColumn(tbody,-1);break;
				case 'InsertColumnBefore' : insertColumn(tbody,td.cellIndex);break;
				case 'InsertColumnAfter'  : insertColumn(tbody,td.cellIndex+1);break;
				case 'DeleteColumn'       : deleteColumn(tbody,td.cellIndex);break;
				case 'InsertCellLeft'     : tr.insertCell(0);break;
				case 'InsertCellRight'    : tr.insertCell(-1);break;
				case 'InsertCellBefore'   : tr.insertCell(td.cellIndex);break;
				case 'InsertCellAfter'    : tr.insertCell(td.cellIndex+1);break;
				case 'InsertCellStart'    : tr.insertCell(0);break;
				case 'DeleteCell'         : tr.deleteCell(td.cellIndex);break;
				case 'SplitCell'          : splitCell(tbody,tr,td);break;
				case 'MergeCells'         : mergeCells(tbody,tr,td);break;
				case 'SplitRow'           : splitRow(tbody,tr,td);break;
				case 'MergeRows'          : mergeRows(tbody,tr,td);break;
			        case 'TableProperties':
					nullBorders(editor_obj.contentWindow.document,'hide');
					setGlobalVar('_editor_field',objname);
					setGlobalVar('_editor_table',table);
					showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=table_prop&view=edit&'.$sess->name.'='.$sess->id; ?>", window, "resizable: yes; help: no; status: no; scroll: no; ");
					td.focus();
					break;
				case 'RowProperties':
                                 	setGlobalVar('_editor_field',objname);
					setGlobalVar('_editor_row',tr);
					showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=table_rowprop&view=edit&'.$sess->name.'='.$sess->id; ?>", window, "resizable: yes; help: no; status: no; scroll: no; ");
					td.focus();
					break;
				case 'CellProperties':
                                 	setGlobalVar('_editor_field',objname);
					setGlobalVar('_editor_cell',td);
					showModalDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=table_cellprop&view=edit&'.$sess->name.'='.$sess->id; ?>", window, "resizable: yes; help: no; status: no; scroll: no; ");
					td.focus();
					break;
				default:
                                 	break;
			}
			if (config.showborders) nullBorders(editor_obj.contentWindow.document,'show');
		}
	}
	return;
}

/* ---------------------------------------------------------------------- *\
  Funktion    : editor_event
  Beschreibung: called everytime an editor event occurs
  Usage       : editor_event(objname, runDelay, eventName)
  Argumente   : objname - ID of textarea to replace
                runDelay: -1 = run now, no matter what
                          0  = run now, if allowed
                        1000 = run in 1 sec, if allowed at that point

Default Shortcuts built-in in IE (*cannot be cancelled).
When called, these events will fire being the cursor anywhere in the page
CTRL+f	=	FIND (Browser/Editor)*
CTRL+o	=	IE OPEN (Browser)*
F1  	=	IE BROWSER HELP*
CTRL+i	=	IE FAVORITES (Browser)*

Default Shortcuts built-in in IE we don't want cancelled.
DEL     	= 	DELETES SELECTION
HOME	=	GO TO TOP OF PAGE
END	=	GO TO BOTTOM OF PAGE
CTRL+a	=	SELECT ALL (Editor)
CTRL+b	=	BOLD (Editor)
CTRL+c	=	COPY (Editor)
CTRL+i	=	ITALICS (Editor)
CTRL+k	=	IE INSERT LINK (Editor)
CTRL+p	=	PRINT (Editor)
CTRL+u	=	UNDERLINE (Editor)
CTRL+v	=	PASTE (Editor)
CTRL+y	=	REDO (Editor)
CTRL+z	=	UNDO (Editor)
\* ---------------------------------------------------------------------- */
function editor_event(objname,runDelay) {
	var config = document.all[objname].config;
	var editor_obj  = document.all['_'+objname+'_editor'];
	if (runDelay == null) runDelay = 0;
	var editdoc;
	var editEvent = editor_obj.contentWindow ? editor_obj.contentWindow.event : event;

	// auf Tastenkombinationen reagieren
	if (editEvent && editEvent.keyCode) {
		if (editor_obj.tagName.toLowerCase() == 'textarea') return;
		var editdoc = editor_obj.contentWindow.document;

		// ascii order of key pressed
		var ord       = editEvent.keyCode;
		var ctrlKey   = editEvent.ctrlKey;
		var altKey    = editEvent.altKey;
		var shiftKey  = editEvent.shiftKey;

		// ignore shift, ctrl, alt key by itself
		if (ord == 16) return;
		if (ord == 17) return;
		if (ord == 18) return;

		// Auf Tastenkombination reagieren
		if (ctrlKey && editEvent.type == 'keydown') {
			switch(ord) {
				case 87:
					// Cancels CTRL+w (Close Browser Window)
					editEvent.returnValue = false;
                                         editEvent.cancelBubble = true;
         	                        break;
				case 86:
					// cleans up the code while pasting on CTRL+V
					editEvent.returnValue = false;
                                         editEvent.cancelBubble = true;
					editdoc.execCommand('Paste');
					var str=editdoc.body.createTextRange().htmlText;
					if (str.indexOf('; mso-') >= 0 || str.indexOf('<v:') >= 0 || str.indexOf('class=Mso') >= 0) myclean(editdoc);
					editdoc.body.innerHTML = cleanHTML(editdoc.body.innerHTML);
         	                        break;
				case 82:
					// Cancels CTRL+r (Refresh Browser Window)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.body.innerHTML = '';
         	                        break;
				case 83:
					// CTRL+s (Search and Replace)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					showModelessDialog("<?PHP echo $cfg_client['htmlpath'].$cfg_client['contentfile'] .'?popup=find&view=edit&'.$sess->name.'='.$sess->id; ?>",window, "resizable: no; help: no; status: no; scroll: no; ");
					return;
         	                        break;
				case 76:
					// CTRL+l(Bulleted List)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('InsertUnorderedList');
         	                        break;
				case 78:
					// CTRL+n(Numbered List)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('InsertOrderedList');
         	                        break;
				default:
                                 	break;
			}
		}

		// Auf Tastenkombination reagieren
		if (shiftKey && editEvent.type == 'keydown') {
			switch(ord) {
				case 45:
					// cleans up the code while pasting on Shift+INS
					editEvent.returnValue = false;
                                         editEvent.cancelBubble = true;
					editdoc.execCommand('Paste');
					var str=editdoc.body.createTextRange().htmlText;
					if (str.indexOf('; mso-') >= 0 || str.indexOf('<v:') >= 0 || str.indexOf('class=Mso') >= 0) myclean(editdoc);
					editdoc.body.innerHTML = cleanHTML(editdoc.body.innerHTML);
         	                        break;
				default:
                                 	break;
			}
		}

		// Auf Tastenkombination reagieren
		if (altKey && editEvent.type == 'keydown') {
			switch(ord) {
				case 83:
					//ALT+s (Spell Check)
					var str = editdoc.selection.createRange().htmlText;
					var disTag1 = str.indexOf('<IMG');
					var disTag2 = str.indexOf('<SELECT');
					var disTag3 = str.indexOf('<FORM');
					var disTag4 = str.indexOf('<INPUT');
					var disTag5 = str.indexOf('<BUTTON');

					if (disTag1 >= 0 || disTag2 >= 0 || disTag3 >= 0 || disTag4 >= 0 || disTag5 >= 0) alert("Die Auswahl darf keine Bilder enthalten.");
					else if (!str){alert('Bitte markieren Sie erst einen Bereich, der ueberprueft werden soll.');}
					else {
						editdoc.execCommand('copy');
						CheckDocument();
                                                 return true;
					}
         	                        break;
				case 88:
					// ALT+x (Formatierung entfernen)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('RemoveFormat');
         	                        break;
				case 76:
					// ALT+l (links ausrichten)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('JustifyLeft');
         	                        break;
				case 67:
					// ALT+c (zentrieren)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('JustifyCenter');
         	                        break;
				case 82:
					// ALT+r (rechts ausrichten)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('JustifyRight');
         	                        break;
				case 74:
					// ALT+j (Blocksatz)
					editEvent.returnValue = false;
					editEvent.cancelBubble = true;
					editdoc.execCommand('JustifyFull');
         	                        break;
				default:
                                 	break;
			}
		}

/* ---------------------------------------------------------------------- *\
		if (ord == 13 && editEvent.type == 'keypress') {
			editEvent.returnValue = false;
			editor_insertHTML(objname, '<div>'); return;
		}
\* ---------------------------------------------------------------------- */
	}

	// eventuelle Pause, da die Aktion noch ausgefuehrt wird
	if (runDelay > 0) return setTimeout(function() {editor_event(objname);}, runDelay);
	if (this.tooSoon == 1 && runDelay >= 0) {
         	this.queue = 1;
                 return;
         }
	this.tooSoon = 1;
	setTimeout(function() {
         	this.tooSoon = 0;
                 if (this.queue) editor_event(objname,-1);
                 this.queue = 0;
         }, 333);
	editor_updateToolbar(objname);
}

/* ---------------------------------------------------------------------- *\
  Function    : editor_updateToolbar
  Description : update toolbar state
  Usage       :
  Arguments   : objname - ID of textarea to replace
                action  - enable, disable, or update (default action)
\* ---------------------------------------------------------------------- */
function editor_updateToolbar(objname,action) {
	var config = document.all[objname].config;
	var editor_obj  = document.all['_'+objname+'_editor'];

	// Toolbar ein und ausschalten
 	if (action == 'enable' || action == 'disable') {
		var tbItems = new Array('FontName','FontSize','FontStyle','FormatBlock');
		if (action == 'disable') setGlobalVar('_editor_field', '_editor_disabled');
		else setGlobalVar('_editor_field', objname);
		for (var btnName in config.btnList) tbItems.push(config.btnList[btnName][0]);
		for (var idxN in tbItems) {
			var cmdID = tbItems[idxN].toLowerCase();
			var tbObj = document.all['_'+objname+'_'+tbItems[idxN]];
			if (cmdID == 'htmlmode' || cmdID == 'about' || cmdID == 'popupeditor') continue;
			if (tbObj == null) continue;
			var isBtn = (tbObj.tagName.toLowerCase() == 'button') ? true : false;
			if (action == 'enable') {
				tbObj.disabled = false;
				if (isBtn) tbObj.className = 'btn';
			}
			if (action == 'disable') {
				tbObj.disabled = true;
				if (isBtn) tbObj.className = 'btnNA';
			}
		}
		return;
	}

	// Toolbarstatus updaten
	if (editor_obj.tagName.toLowerCase() == 'textarea') return;
	var editdoc = editor_obj.contentWindow.document;

	// Set FontName pulldown
	var fontname_obj = document.all['_'+objname+'_FontName'];
	if (fontname_obj) {
		var fontname = editdoc.queryCommandValue('FontName');
		if (fontname == null) fontname_obj.value = null;
		else {
			var found = 0;
			for (i=0; i<fontname_obj.length; i++) {
				if (fontname.toLowerCase() == fontname_obj[i].text.toLowerCase()) {
					fontname_obj.selectedIndex = i;
					found = 1;
				}
			}
			if (found != 1) fontname_obj.value = null;
		}
         }

	// Set Formatblock pulldown inserted by lvn
	var formatblock_obj = document.all['_'+objname+'_FormatBlock'];
	if (formatblock_obj) {
		var formatblock = editdoc.queryCommandValue('FormatBlock');
		if (formatblock == null) formatblock_obj.value = null;
		else {
			var found = 0;
			for (i=0; i<formatblock_obj.length; i++) {
				if (formatblock == formatblock_obj[i].value) {
					formatblock_obj.selectedIndex = i;
					found = 1;
				}
                         }
			if (found != 1) formatblock_obj.value = null;
		}
         }

	// Schriftgroesze
	var fontsize_obj = document.all['_'+objname+'_FontSize'];
	if (fontsize_obj) {
		var fontsize = editdoc.queryCommandValue('FontSize');
		if (fontsize == null) fontsize_obj.value = null;
		else {
			var found = 0;
			for (i=0; i<fontsize_obj.length; i++) {
				if (fontsize == fontsize_obj[i].value) {
                                 	fontsize_obj.selectedIndex = i;
                                         found=1;
                                 }
			}
			if (found != 1) fontsize_obj.value = null;
		}
         }

	// Schriftart
	var classname_obj = document.all['_'+objname+'_FontStyle'];
	if (classname_obj) {
		var curRange = editdoc.selection.createRange();
		var pElement;
		if (curRange.length) pElement = curRange[0];
		else pElement = curRange.parentElement();
		while (pElement && !pElement.className) pElement = pElement.parentElement;
		var thisClass = pElement ? pElement.className.toLowerCase() : '';
		if (!thisClass && classname_obj.value) classname_obj.value = null;
		else {
			var found = 0;
			for (i=0; i<classname_obj.length; i++) {
				if (thisClass == classname_obj[i].value.toLowerCase()) {
					classname_obj.selectedIndex = i;
					found=1;
				}
			}
			if (found != 1) classname_obj.value = null;
		}
         }

	// update button states
	var IDList = Array('Bold','Italic','Underline','StrikeThrough','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','JustifyNone','InsertOrderedList','InsertUnorderedList','MultipleSelection','LiveResize');
	for (i=0; i<IDList.length; i++) {
		var btnObj = document.all['_'+objname+'_'+IDList[i]];
		if (btnObj == null) continue;
		var cmdActive = editdoc.queryCommandState(IDList[i]);

		// option is OK
		if (!cmdActive)  {
			if (btnObj.className != 'btn') btnObj.className = 'btn';
			if (btnObj.disabled != false) btnObj.disabled = false;
		}

		// option already applied or mixed content
		else if (cmdActive)  {
			if (btnObj.className != 'btnDown') btnObj.className = 'btnDown';
			if (btnObj.disabled != false) btnObj.disabled = false;
		}
	}

	var table_src_element = null;
	if (editdoc.selection.type != 'Control') {
		table_src_element = editdoc.selection.createRange().parentElement();
		while (table_src_element != null && table_src_element.tagName != 'TD' && table_src_element.tagName != 'TH') table_src_element = table_src_element.parentElement;
	}

	// check if buttons are set in the config
	var IDList = Array('TableProperties','RowProperties','InsertRowBefore','InsertRowAfter','DeleteRow','InsertColumnBefore','InsertColumnAfter','DeleteColumn','CellProperties','InsertCellBefore','InsertCellAfter','DeleteCell','SplitCell','MergeCells','SplitRow','MergeRows');
	for (var i=0; i<IDList.length; i++) {
		var found = false;
		for (var j=0;j<config.toolbar.length;j++) {
			if(config.toolbar[j]) {
				for (var k=0;k<config.toolbar[j].length;k++) if (IDList[i] == config.toolbar[j][k]) found = true;
			}
		}

		// if in cell enable buttons, else disable them
		if (found) {
			var btnObj = document.all['_'+objname+'_'+IDList[i]];
			if (table_src_element == null) {
	                 	btnObj.disabled = true;
				btnObj.className = 'btnNA';
			} else {
	                 	btnObj.disabled = false;
				btnObj.className = 'btn';
			}
		}
         }
}

/* ---------------------------------------------------------------------- *\
  Function    : editor_updateOutput
  Description : update hidden output field with data from wysiwg
\* ---------------------------------------------------------------------- */
function editor_updateOutput(objname) {
	var config = document.all[objname].config;
	var editor_obj  = document.all['_'+objname+'_editor'];
	var editEvent = editor_obj.contentWindow ? editor_obj.contentWindow.event : event;
	var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
	var editdoc = isTextarea ? null : editor_obj.contentWindow.document;

	// get contents of edit field
	var contents;
	if (isTextarea) contents = editor_obj.value;
	else {contents = editdoc.body.innerHTML;}
	contents = cleanHTML(contents);

	// check if contents has changed since the last time we ran this routine
	if (config.lastUpdateOutput && config.lastUpdateOutput == contents) return;
	else config.lastUpdateOutput = contents;

	// update hidden output field
	document.all[objname].value = contents;
}

/* ---------------------------------------------------------------------- *\
  Function    : editor_filterOutput
  Description :
\* ---------------------------------------------------------------------- */
function editor_filterOutput(objname) {
	editor_updateOutput(objname);
	var contents = document.all[objname].value;
	var config = document.all[objname].config;

	// ignore blank contents
	if (contents.toLowerCase() == '<p>&nbsp;</p>') contents = '';

	// filter tag - this code is run for each HTML tag matched
	var filterTag = function(tagBody,tagName,tagAttr) {
		tagName = tagName.toLowerCase();
		var closingTag = (tagBody.match(/^<\//)) ? true : false;

		// fix placeholder URLS - remove absolute paths that IE adds
		if (tagName == 'img') tagBody = tagBody.replace(/(src\s*=\s*.)[^*]*(\*\*\*)/, "$1$2");
		if (tagName == 'a') tagBody = tagBody.replace(/(href\s*=\s*.)[^*]*(\*\*\*)/, "$1$2");
		return tagBody;
	}

	// match tags and call filterTag
	RegExp.lastIndex = 0;
	var matchTag = /<\/?(\w+)((?:[^'">]*|'[^']*'|"[^"]*")*)>/g;
	contents = contents.replace(matchTag, filterTag);
	contents = contents.replace(/class=borders /gi, '');
	var re1 = /BORDER-RIGHT: #c0c0c0 1px dotted; BORDER-TOP: #c0c0c0 1px dotted; BORDER-LEFT: #c0c0c0 1px dotted; BORDER-BOTTOM: #c0c0c0 1px dotted/g;
	var re2 = / style=""/g;
	contents = contents.replace(re1, '');
	contents = contents.replace(re2, '');
	if (config.replaceNextlines) {
		contents = contents.replace(/\r\n/g, ' ');
		contents = contents.replace(/\n/g, ' ');
		contents = contents.replace(/\r/g, ' ');
	}
	document.all[objname].value = contents;
}

/* ---------------------------------------------------------------------- *\
  Function    : nullBorders
  Description : show 'dotted' borders for tables with border=0
  Usage       : nullBorders(doc,status);
  Arguments   : doc - document object in wich the borders must be shown
                status - show or hide
\* ---------------------------------------------------------------------- */
function nullBorders(doc,status) {
	var edit_Tables = doc.body.getElementsByTagName('TABLE');
	for (i=0; i < edit_Tables.length; i++) {
		if (edit_Tables[i].border == '' || edit_Tables[i].border == '0' ) {
			if (status == 'show' ) edit_Tables[i].style.border = "1px dotted #C0C0C0";
			else edit_Tables[i].removeAttribute('style');
		}
		edit_Rows = edit_Tables[i].rows;
		for (j=0; j < edit_Rows.length; j++) {
			edit_Cells = edit_Rows[j].cells;
			for (k=0; k < edit_Cells.length; k++) {
				if (edit_Tables[i].border == '' || edit_Tables[i].border == '0' ) {
					if (!edit_Cells[k].border || edit_Cells[k].border == '' || edit_Cells[k].border == '0' ) {
						if (status == 'show' ) edit_Cells[k].style.border = "1px dotted #C0C0C0";
						else edit_Cells[k].removeAttribute('style');
					}
                                 } else {
					if ( edit_Cells[k].border == '0' ) {
						if (status == 'show' ) edit_Cells[k].style.border = "1px dotted #C0C0C0";
						else edit_Cells[k].removeAttribute('style');
					}
				}
			}
                 }
	}
}

/* ---------------------------------------------------------------------- *\
  Function    : editor_setmode
  Description : change mode between WYSIWYG and HTML editor
  Usage       : editor_setmode(objname, mode);
  Arguments   : objname - button id string with editor and action name
                mode      - init, textedit, or wysiwyg
\* ---------------------------------------------------------------------- */
function editor_setmode(objname, mode) {
	var config = document.all[objname].config;
	var editor_obj = document.all['_'+objname+'_editor'];
	if (document.readyState != 'complete') {
		setTimeout(function() {editor_setmode(objname,mode)}, 25);
		return;
	}

	// define different editors
	var TextEdit   = '<textarea ID="_' +objname + '_editor" style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ '; margin-top: -1px; margin-bottom: -1px;"></textarea>';
	var RichEdit   = '<iframe ID="_' +objname+ '_editor"    style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ ';"></iframe>';


	if (mode == 'textedit' || editor_obj.tagName.toLowerCase() == 'iframe') {
		config.mode = 'textedit';
		var editdoc = editor_obj.contentWindow.document;
		nullBorders(editdoc,'hide');
		var contents = cleanHTML(editdoc.body.createTextRange().htmlText);
		editor_obj.outerHTML = TextEdit;
		editor_obj = document.all['_'+objname+'_editor'];
		editor_obj.value = contents;
		editor_event(objname);
		if (config.showborders) {
			editor_updateToolbar(objname, 'disable');
			config.showborders = true;
		} else editor_updateToolbar(objname, 'disable');

		// set event handlers
		editor_obj.onkeydown = function() {editor_event(objname);}
		editor_obj.onkeypress = function() {editor_event(objname);}
		editor_obj.onkeyup = function() {editor_event(objname);}
		editor_obj.onmouseup = function() {editor_event(objname);}
		editor_obj.ondrop = function() {editor_event(objname, 100);}
		editor_obj.oncut = function() {editor_event(objname, 100);}
		editor_obj.onpaste = function() {editor_event(objname, 100);}
		editor_obj.onblur = function() {editor_event(objname, -1);}
		editor_updateOutput(objname);
		editor_focus(editor_obj);
	} else {
		config.mode = 'wysiwyg';
		var contents = editor_obj.value;
		if (mode == 'init') contents = document.all[objname].value;

		// WYSIWYG erstellen
		editor_obj.outerHTML = RichEdit;
		editor_obj = document.all['_'+objname+'_editor'];
		var html = '';
		// Robert Hartwig: 18.07.2004: Variable fuer charset
		html += '<html><head><meta http-equiv="content-type" content="text/html; charset=<?php echo $lang_charset ?>">\n';
		if (config.stylesheet) html += config.stylesheet+'\n';
		html += '<style>\n';
		if (config.style) html += '\n';
		else html += 'body {font-family: "Verdana"; font-size:  11pt;} \n';
		html += 'TD {font-family: "Verdana"; font-size:  11pt;} \n';
		html += '.borders {border:1px dotted #ff0000;height:20px} \n';
		html += 'MARQUEE {border:1px dashed #0066FF;height:20px} \n';
		html += '</style>\n'
		+ '</head>\n'
		+ '<body contenteditable="true" topmargin="1" leftmargin="1"';
		if (config.style) html += ' '+config.style;
		html += ' oncontextmenu="parent.editor_cMenu_generate(window,\'' +objname+ '\');"'
		+'>'
		+ contents
		+ '</body>\n'
		+ '</html>\n';
		var editdoc = editor_obj.contentWindow.document;
		editdoc.open();
		editdoc.write(html);
		editdoc.close();
		editor_updateToolbar(objname, 'enable');
		editdoc.objname = objname;
		editdoc.onkeydown = function() {editor_event(objname);}
		editdoc.onkeypress = function() {editor_event(objname);}
		editdoc.onkeyup = function() {editor_event(objname);}
		editdoc.onmouseup = function() {editor_event(objname);}
		editdoc.body.ondrop = function() {editor_event(objname, 100);}
		editdoc.body.oncut = function() {editor_event(objname, 100);}
		editdoc.body.onpaste = function() {editor_event(objname, 100);}
		editdoc.body.onblur = function() {editor_event(objname, -1);}
		if (config.showborders) {
			nullBorders(editdoc,'show');
			var btnObj = document.all['_'+objname+'_ShowBorder'];
			if(btnObj) btnObj.className = 'btnDown';
		}

		// bring focus to editor
		if (mode != 'init') editor_focus(editor_obj);
	}

	// Call update UI
	if (mode != 'init') editor_event(objname);
}

/* ---------------------------------------------------------------------- *\
  Function    : editor_focus
  Description : bring focus to the editor
  Usage       : editor_focus(editor_obj);
  Arguments   : editor_obj - editor object
\* ---------------------------------------------------------------------- */
function editor_focus(editor_obj) {
	// check editor mode
	if (editor_obj.tagName.toLowerCase() == 'textarea') {
		var myfunc = function() {editor_obj.focus();}
		setTimeout(myfunc,100);
	} else {
		var editdoc = editor_obj.contentWindow.document;
		var editorRange = editdoc.body.createTextRange();
		var curRange = editdoc.selection.createRange();
		if (curRange.length == null && !editorRange.inRange(curRange)) {
			editorRange.collapse();
			editorRange.select();
			curRange = editorRange;
		}
	}
}

/* ---------------------------------------------------------------------- *\
  Function    : _dec_to_rgb
  Description : convert dec color value to rgb hex
  Usage       : var hex = _dec_to_rgb('65535');   // returns FFFF00
  Arguments   : value   - dec value
\* ---------------------------------------------------------------------- */
function _dec_to_rgb(value) {
	var hex_string = '';
	for (var hexpair = 0; hexpair < 3; hexpair++) {
		var myByte = value & 0xFF;
		value >>= 8;
		var nybble2 = myByte & 0x0F;
		var nybble1 = (myByte >> 4) & 0x0F;
		hex_string += nybble1.toString(16);
		hex_string += nybble2.toString(16);
	}
	return hex_string.toUpperCase();
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_insertHTML
  Description : insert string at current cursor position in editor.
  				If two strings are specifed, surround selected text with them.
  Usage       : editor_insertHTML(objname, str1, [str2], reqSelection)
  Arguments   : objname - ID of textarea
                str1 - HTML or text to insert
                str2 - HTML or text to insert (optional argument)
                reqSelection - (1 or 0) give error if no text selected
\* ---------------------------------------------------------------------- */
function editor_insertHTML(objname, str1,str2, reqSel) {
	var config = document.all[objname].config;
	var editor_obj = document.all['_'+objname+'_editor'];
	if (str1 == null) str1 = '';
	if (str2 == null) str2 = '';

	// for non-wysiwyg capable browsers just add to end of textbox
	if (document.all[objname] && editor_obj == null) {
		document.all[objname].focus();
		document.all[objname].value = document.all[objname].value + str1 + str2;
		return;
	}

	// error checking
	if (editor_obj == null) return alert("Unable to insert HTML.  Invalid object name '" +objname+ "'.");
	editor_focus(editor_obj);
	var tagname = editor_obj.tagName.toLowerCase();
	var sRange;

	// insertHTML for wysiwyg iframe
	if (tagname == 'iframe') {
	   	var editdoc = editor_obj.contentWindow.document;
		sRange = editdoc.selection.createRange();
		var sHtml = sRange.htmlText;

		// check for control ranges
		if (sRange.length) return alert("Unable to insert HTML.  Try highlighting content instead of selecting it.");

		// insert HTML
		var oldHandler = window.onerror;
		window.onerror = function() {
			alert("Unable to insert HTML for current selection.");
			return true;
	         }
		if (sHtml.length) {
			if (str2) sRange.pasteHTML(str1 +sHtml+ str2)
			else sRange.pasteHTML(str1);
		} else {
			if (reqSel) return alert("Unable to insert HTML.  You must select something first.");
			sRange.pasteHTML(str1 + str2);
		}
		window.onerror = oldHandler;
	} else if (tagname == 'textarea') {
		editor_obj.focus();
		sRange = document.selection.createRange();
		var sText = sRange.text;

		// insert HTML
		if (sText.length) {
			if (str2) sRange.text = str1 +sText+ str2;
			else sRange.text = str1;
		} else {
			if (reqSel) return alert("Unable to insert HTML.  You must select something first.");
			sRange.text = str1 + str2;
		}
	} else alert("Unable to insert HTML.  Unknown object tag type '" +tagname+ "'.");

	// move to end of new content
	sRange.collapse(false);
	sRange.select();
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_getHTML
  Description : return HTML contents of editor (in either wywisyg or html mode)
  Usage       : var myHTML = editor_getHTML('objname');
\* ---------------------------------------------------------------------- */
function editor_getHTML(objname) {
	var editor_obj = document.all['_'+objname+'_editor'];
	var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
	if (isTextarea) return editor_obj.value;
	else return editor_obj.contentWindow.document.body.innerHTML;
}
/* ---------------------------------------------------------------------- *\
  Function    : editor_setHTML
  Description : set HTML contents of editor (in either wywisyg or html mode)
  Usage       : editor_setHTML('objname',"<b>html</b> <u>here</u>");
\* ---------------------------------------------------------------------- */
function editor_setHTML(objname, html) {
	var editor_obj = document.all['_'+objname+'_editor'];
	var isTextarea = (editor_obj.tagName.toLowerCase() == 'textarea');
	if (isTextarea) editor_obj.value = html;
	else editor_obj.contentWindow.document.body.innerHTML = html;
}
/* ---------------------------------------------------------------- */
function _isMouseOver(obj,event) {
	var mouseX = event.clientX;
	var mouseY = event.clientY;
	var objTop = obj.offsetTop;
	var objBottom = obj.offsetTop + obj.offsetHeight;
	var objLeft = obj.offsetLeft;
	var objRight = obj.offsetLeft + obj.offsetWidth;
	if (mouseX >= objLeft && mouseX <= objRight && mouseY >= objTop && mouseY <= objBottom) return true;
	return false;
}
/* ---------------------------------------------------------------- */
function editor_cMenu_generate(editorWin,objname) {
	var parentWin = window;
	editorWin.event.returnValue = false;
	var table_object = document.all['_'+objname+'_editor'];
	var table_src_element = table_object.contentWindow.event.srcElement;
	if (table_src_element.tagName == 'TD') {
		cMenuOptions = [
         ['<?php echo $dedi_lang['wys_InsertTable'] ?>' , ''		, function() {editor_action('_' + objname + '_' + 'InsertTable');}],
         ['<?php echo $dedi_lang['wys_pop_Caption'] ?>' , ''		, function() {tables_action('_' + objname + '_' + 'CreateCaption',table_src_element);}],
         ['<?php echo $dedi_lang['wys_InsertRowBefore'] ?>'   , ''	, function() {tables_action('_' + objname + '_' + 'InsertRowBefore',table_src_element );}],
         ['<?php echo $dedi_lang['wys_InsertRowAfter'] ?>'   , ''	, function() {tables_action('_' + objname + '_' + 'InsertRowAfter',table_src_element );}],
         ['<?php echo $dedi_lang['wys_DeleteRow'] ?>'   , ''		, function() {tables_action('_' + objname + '_' + 'DeleteRow',table_src_element );}],
         ['<?php echo $dedi_lang['wys_InsertColumnBefore'] ?>', ''	, function() {tables_action('_' + objname + '_' + 'InsertColumnBefore',table_src_element );}],
         ['<?php echo $dedi_lang['wys_InsertColumnAfter'] ?>', ''	, function() {tables_action('_' + objname + '_' + 'InsertColumnAfter',table_src_element );}],
	['<?php echo $dedi_lang['wys_DeleteColumn'] ?>', ''		, function() {tables_action('_' + objname + '_' + 'DeleteColumn',table_src_element );}],
         ['<?php echo $dedi_lang['wys_InsertCellBefore'] ?>'  , ''	, function() {tables_action('_' + objname + '_' + 'InsertCellBefore',table_src_element );}],
         ['<?php echo $dedi_lang['wys_InsertCellAfter'] ?>'  , ''	, function() {tables_action('_' + objname + '_' + 'InsertCellAfter',table_src_element );}],
         ['<?php echo $dedi_lang['wys_DeleteCell'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'DeleteCell',table_src_element );}],
         ['<?php echo $dedi_lang['wys_SplitCell'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'SplitCell',table_src_element );}],
         ['<?php echo $dedi_lang['wys_MergeCells'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'MergeCells',table_src_element );}],
         ['<?php echo $dedi_lang['wys_SplitRow'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'SplitRow',table_src_element );}],
         ['<?php echo $dedi_lang['wys_TableProps'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'TableProperties',table_src_element );}],
         ['<?php echo $dedi_lang['wys_RowProperties'] ?>'  , ''		, function() {tables_action('_' + objname + '_' + 'RowProperties',table_src_element );}],
         ['<?php echo $dedi_lang['wys_CellProperties'] ?>'  , ''	, function() {tables_action('_' + objname + '_' + 'CellProperties',table_src_element );}]];
	} else {
		// reset to de default browser contextmenu
		editorWin.event.returnValue = true;
		return;
	}
	editor_cMenu.options = cMenuOptions;

	// generate context menu
	var cMenuHeader = ''
	+ '<div id="_'+objname+'_cMenu" onblur="editor_cMenu(this);" oncontextmenu="return false;" onselectstart="return false"'
	+ 'style="position: absolute; visibility: hidden; cursor: default; width: 167px; background-color: threedface;'
	+ ' border: solid 1px; border-color: threedlightshadow threeddarkshadow threeddarkshadow threedlightshadow;">'
	+ '<table border=0 cellspacing=0 cellpadding=0 width="100%" style="width: 167px; background-color: threedface; border: solid 1px; border-color: threedhighlight threedshadow threedshadow threedhighlight;">'
	+ ' <tr><td colspan=2 height=1></td></tr>';
	var cMenuList = '';
	var cMenuFooter = ''
	+ ' <tr><td colspan=2 height=1></td></tr>'
	+ '</table></div>';
	for (var menuIdx in editor_cMenu.options) {
		var menuName = editor_cMenu.options[menuIdx][0];
		var menuKey  = editor_cMenu.options[menuIdx][1];
		var menuCode = editor_cMenu.options[menuIdx][2];

		// menu option
		cMenuList += '<tr class="cMenu" onmouseover="editor_cMenu(this)" onmouseout="editor_cMenu(this)" onClick="editor_cMenu(this, \'' +menuIdx+ '\',\'' +objname+ '\')">';
		if (menuKey) cMenuList += ' <td align=left class="cMenu">' +menuName+ '</td><td align=right class="cMenu">' +menuKey+ '</td>';
		else cMenuList += ' <td colspan=2 class="cMenu">' +menuName+ '</td>';
		cMenuList += '</tr>';
	}
	var cMenuHTML = cMenuHeader + cMenuList + cMenuFooter;
	document.all['_'+objname+'_cMenu'].outerHTML = cMenuHTML;
	editor_cMenu_setPosition(parentWin, editorWin, objname);
	parentWin['_'+objname+'_cMenu'].style.visibility = 'visible';
	parentWin['_'+objname+'_cMenu'].focus();
}
/* ---------------------------------------------------------------- */
function editor_cMenu_setPosition(parentWin, editorWin, objname) {
	var event = editorWin.event;
	var cMenuObj = parentWin['_'+objname+'_cMenu'];
	var mouseX = event.clientX + parentWin.document.all['_'+objname+'_editor'].offsetLeft;
	var mouseY = event.clientY + parentWin.document.all['_'+objname+'_editor'].offsetTop;
	var cMenuH = cMenuObj.offsetHeight;
	var cMenuW = cMenuObj.offsetWidth;
	var pageH = document.body.clientHeight + document.body.scrollTop;
	var pageW = document.body.clientWidth + document.body.scrollLeft;

	// set horzontal position
	if (mouseX + 5 + cMenuW > pageW) var left = mouseX - cMenuW - 5;
	else var left = mouseX + 5;

	// set vertical position
	if (mouseY + 5 + cMenuH > pageH) var top = mouseY - cMenuH + 250;
	else var top = mouseY + 5;
	cMenuObj.style.top = top;
	cMenuObj.style.left = left;
}
/* ---------------------------------------------------------------- */
function editor_cMenu(obj,menuIdx,objname) {
	var action = event.type;
	if (action == 'mouseover' && !obj.disabled && obj.tagName.toLowerCase() == 'tr') {
		obj.className = 'cMenuOver';
		for (var i=0; i < obj.cells.length; i++) obj.cells[i].className = 'cMenuOver';
	} else if (action == 'mouseout' && !obj.disabled && obj.tagName.toLowerCase() == 'tr') {
		obj.className = 'cMenu';
		for (var i=0; i < obj.cells.length; i++) obj.cells[i].className = 'cMenu';
	} else if (action == 'click' && !obj.disabled) {
		document.all['_'+objname+'_cMenu'].style.visibility = 'hidden';
		var menucode = editor_cMenu.options[menuIdx][2];
		menucode();
	} else if (action == 'blur') {
		if (!_isMouseOver(obj,event)) { obj.style.visibility = 'hidden'; }
		else if (obj.style.visibility != 'hidden') obj.focus();
	} else alert("editor_cMenu, unknown action: " + action);
}
/* ---------------------------------------------------------------------- *\
  Function    : setGlobalVar
  Description : set a variable with a global scope
  Usage       : setGlobalVar(varName, value);
  Arguments   : varName - name of the global variable to set
                value - value of the global variable to set
\* ---------------------------------------------------------------------- */
function setGlobalVar(varName, value) {
	if (this.cache == null) this.cache = new Object();
	this.cache[varName] = value;
}
/* ---------------------------------------------------------------------- *\
  Function    : getGlobalVar
  Description : get a variable in a global scope
  Usage       : value = getGlobalVar(varName);
  Arguments   : varName - name of the global variable to get
                value - value of the global variable to get
\* ---------------------------------------------------------------------- */
function getGlobalVar(varName, value) {
	if (this.cache == null) return null;
	else return this.cache[varName];
}
/* ---------------------------------------------------------------------- *\
  Function    : MS-Word clean-up
  Description : replace textarea with wysiwyg editor
  Usage       : editor_generate("textarea_id",[height],[width]);
  Arguments   : objname - ID of textarea to replace
                w       - width of wysiwyg editor
                h       - height of wysiwyg editor
\* ---------------------------------------------------------------------- */
function cleanEmptyTag(oElem) {
	if (oElem.hasChildNodes) {
		var tmp = oElem
		for (var k = tmp.children.length; k >= 0; k--) if (tmp.children[k] != null) cleanEmptyTag(tmp.children[k]);
	}
	var oAttribs = oElem.attributes;
	if (oAttribs != null) {
		for (var j = oAttribs.length - 1; j >=0; j--) {
			var oAttrib = oAttribs[j];
			if (oAttrib.nodeValue != null) {
				oAttribs.removeNamedItem('style')
				oAttribs.removeNamedItem('title')
				oAttribs.removeNamedItem('class')
			}
		}
         }
	if (oElem.style) oElem.style.cssText = '';
	if (oElem.outerHTML != '<BR>') oElem.outerHTML = '';
}

function cleanTable(oElem) {
	oElem.style.cssText = '';
	var oAttribs = oElem.attributes;
	if (oAttribs != null) {
         	for (var j = oAttribs.length - 1; j >=0; j--) {
                 	var oAttrib = oAttribs[j];
			if (oAttrib.nodeValue != null) {
				oAttribs.removeNamedItem('class')
				oAttribs.removeNamedItem('style')
			}
		}
	}
	var oTR = oElem.rows;
	if (oTR != null) {
		for (var r = oTR.length - 1; r >= 0; r--) oTR[r].style.cssText = '';
	}
	var oTD = oElem.cells;
	if (oTD != null) {
		for (var t = oTD.length - 1; t >= 0; t--) oTD[t].style.cssText = '';
	}
}

function CheckDocument() {
	oShell= new ActiveXObject("WScript.Shell");
	oShell.SendKeys( "^c" ); // copy
	oWord = new ActiveXObject("Word.Application");
	oWord.Documents.Add();
	oWord.Selection.Paste();
	oWord.ActiveDocument.CheckSpelling();
	oWord.Selection.WholeStory();
	oWord.Selection.Copy();
	oWord.ActiveDocument.Close(0);
	oWord.Quit();
	var nRet= oShell.Popup( "HTMLArea finished checking your document.\nApply changes? Click OK to replace the corrected words.",0,"Spell Check Complete",33 );
	if ( nRet == 1 ) {oShell.SendKeys( "^v" );}// paste
}

function cleanHTML(unclean) {
	this.FormatStock=1;
	this.FormatTables=0;
	var re  = /style=\"width\s*:\s*(\d+)px;\s*height:\s*(\d+)px;*\s*\"/gi;
	unclean = unclean.replace(re, 'width=$1 height=$2');
	unclean = unclean.replace(/(\s*):(\s*)/gi, ':');
	unclean = unclean.replace(/<[^>]+>/g, function(w) {
		var PcaseArray = w.split(' ');
		for (var i=0; i < PcaseArray.length; i++) {
			PcaseArray[i] = PcaseArray[i].replace(/<\/?.+/, function(x) {return x.toLowerCase()})
			PcaseArray[i] = PcaseArray[i].replace(/[^=]+=/, function(y) {return y.toLowerCase()})
			PcaseArray[i] = PcaseArray[i].replace(/[^:]+:/, function(z) {return z.toLowerCase()})
		}
		w = PcaseArray.join(' ')
		return w
         })
	unclean = unclean.replace(/<br>/gi, '<br />');
	unclean = unclean.replace(/<hr[^>]*>/gi, "\n<hr />");
	unclean = unclean.replace(/<hr([^>]*[^\/])>/gi, '<hr\$1 />');
	unclean = unclean.replace(/<img([^>]*[^\/])>/gi, '<img\$1 />');
	unclean = unclean.replace(/<input([^>]*[^\/])>/gi, '<input\$1 />');
	unclean = unclean.replace(/<(\/)?I>/ig, '<$1em>');
	unclean = unclean.replace(/<(\/)?B>/ig, '<$1strong>');
	unclean = unclean.replace(/noshade/gi, 'noshade=\"noshade\"');
	unclean = unclean.replace(/[<td]?(nowrap)/gi, 'nowrap=\"nowrap\"');
	unclean = unclean.replace(/[<input]?(checked)/gi, 'checked=\"checked\"');
	unclean = unclean.replace(/[<input]?(readonly)/gi, 'readonly=\"readonly\"');
	unclean = unclean.replace(/[<input]?(disabled)/gi, 'disabled=\"disabled\"');
	unclean = unclean.replace(/[<frame]?(noresize)/gi, 'noresize=\"noresize\"');
	unclean = unclean.replace(/<option([^>]*)(selected>)/gi, '<option\$1 selected=\"selected\">');
	var re = unclean.match(/[<img]?(alt)/gi);
	if (re) null;
         else unclean = unclean.replace(/<img/gi, '<img alt=\"\"');
	unclean = unclean.replace(/<IMG>/gi, "");
	unclean = unclean.replace(/ ([^=]+)=([^" >]+)/gi, " $1=\"$2\"");
	unclean = unclean.replace(/<!--(.*)-->/gi, '<!--$1-->');
	unclean = unclean.replace(/ ([^=]+)=([^" >]+)/gi, " $1=\"$2\"");
	unclean = unclean.replace(/hspace=0 /gi, '');
	unclean = unclean.replace(/<\/?\w+:[^>]*>/gi, "");
	unclean = unclean.replace(/\r\n/g, "");
	unclean = unclean.replace(/\t/g, " ");
	unclean = unclean.replace(/<[.]*>/gi, '');
  unclean = unclean.replace(/:/gi, ": ");
  unclean = unclean.replace(/http: /gi, "http:");
	if (FormatStock) {
		unclean = unclean.replace(/<br[^>]*>/gi, "\n<br />");
		unclean = unclean.replace(/<hr[^>]*>/gi, '<hr />');
		unclean = unclean.replace(/<p>/gi, '\n<p>');
		unclean = unclean.replace(/<p><table/gi, '\n<table');
		unclean = unclean.replace(/<\/table><\/p>/gi, '\n<\/table>');
		unclean = unclean.replace(/<table/gi, '\n<table');
		unclean = unclean.replace(/<\/table>/gi, '\n<\/table>');
		unclean = unclean.replace(/<tbody/gi, '\n<tbody');
		unclean = unclean.replace(/<\/tbody>/gi, '\n<\/tbody>');
		unclean = unclean.replace(/<td>/gi, '\n<td>');
		unclean = unclean.replace(/<\/td>/gi, '<\/td>');
		unclean = unclean.replace(/<tr/gi, '\n<tr');
		unclean = unclean.replace(/<\/tr>/gi, '\n<\/tr>');
		unclean = unclean.replace(/<\/li>/gi, '');
		unclean = unclean.replace(/<li/gi, '<\/li>\n<li');
		unclean = unclean.replace(/<ul([^>]*[^\/])><\/li>/gi, '\n<ul\$1>');
		unclean = unclean.replace(/<ul><\/li>/gi, '\n<ul>');
		unclean = unclean.replace(/<\/ul>/gi, '<\/li>\n<\/ul>');
		unclean = unclean.replace(/<ol([^>]*[^\/])><\/li>/gi, '\n<ol\$1>');
		unclean = unclean.replace(/<ol><\/li>/gi, '\n<ol>');
		unclean = unclean.replace(/<\/ol>/gi, '<\/li>\n<\/ol>');
		unclean = unclean.replace(/<dl/gi, '\n<dl');
		unclean = unclean.replace(/<\/dl>/gi, '<\/dl>');
		unclean = unclean.replace(/<dd/gi, '\n<dd');
		unclean = unclean.replace(/<a/gi, '\n<a');
		unclean = unclean.replace(/<img/gi, '\n<img');
		unclean = unclean.replace(/<h/gi, '\n<h');
		unclean = unclean.replace(/<form/gi, '\n<form');
		unclean = unclean.replace(/<\/form/gi, '\n<\/form');
		unclean = unclean.replace(/<select/gi, '\n<select');
		unclean = unclean.replace(/<option/gi, '\n<option');
		unclean = unclean.replace(/<input/gi, '\n<input');
	}
	if (FormatTables) {
		unclean = unclean.replace(/<br[^>]*>/gi, "\n<br />");
		unclean = unclean.replace(/<p>/gi, '\n<p>');
		unclean = unclean.replace(/<table/gi, '\n<table');
		unclean = unclean.replace(/<\/table>/gi, '\n<\/table>\n');
		unclean = unclean.replace(/<tbody/gi, '\n\<tbody');
		unclean = unclean.replace(/<\/tbody>/gi, '\n<\/tbody>');
		unclean = unclean.replace(/<td/gi, '\n<td');
		unclean = unclean.replace(/<\/td>/gi, '<\/td>');
		unclean = unclean.replace(/<tr/gi, '\n<tr');
		unclean = unclean.replace(/<\/tr>/gi, '\n<\/tr>');
		unclean = unclean.replace(/<div/gi, '\n<div');
		unclean = unclean.replace(/<\/div>/gi, '\n<\/div>');
		unclean = unclean.replace(/<ul/gi, '\n<ul');
		unclean = unclean.replace(/<\/ul>/gi, '\n<\/ul>');
		unclean = unclean.replace(/<ol/gi, '\n<ol');
		unclean = unclean.replace(/<\/ol>/gi, '\n<\/ol>');
		unclean = unclean.replace(/<li/gi, '\n<li');
		unclean = unclean.replace(/<dl/gi, '\n<dl');
		unclean = unclean.replace(/<\/dl>/gi, '<\/dl>\n');
		unclean = unclean.replace(/<dd/gi, '\n<dd');
		unclean = unclean.replace(/<form/gi, '\n<form');
		unclean = unclean.replace(/<\/form/gi, '\n<\/form');
		unclean = unclean.replace(/<select/gi, '\n<select');
		unclean = unclean.replace(/<option/gi, '\n<option');
		unclean = unclean.replace(/<input/gi, '\n<input');
	}
	return unclean;
}

function myclean(editdoc) {
	var 	oTags = editdoc.all.tags('SPAN'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {oTags[i].outerHTML = oTags[i].innerHTML;}}
		oTags = editdoc.all.tags('DIV'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {oTags[i].outerHTML = oTags[i].innerHTML;}}
		oTags = editdoc.all.tags('FONT'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {oTags[i].outerHTML = oTags[i].innerHTML;}}
		oTags = editdoc.all.tags('P'); 			if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('B'); 			if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('I'); 			if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('U'); 			if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H1'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H2'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H3'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H4'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H5'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('H6'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('BLOCKQUOTE');		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('OL'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('UL'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags[i]);}}
		oTags = editdoc.all.tags('TABLE'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanTable(oTags[i]);}}
		oTags = editdoc.all.tags('TR'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanTable(oTags[i]);}}
		oTags = editdoc.all.tags('TD'); 		if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanTable(oTags[i]);}}
}