////////////////////////////////
//  Editor-Funktionen Anfang  //
////////////////////////////////

function init_content_editor(width, height){

	var editor_width = width;
	var editor_height = height;

	var textArea = document.getElementById('editor_textarea');
	textArea.style.width = editor_width + 'px';
	textArea.style.height = editor_height + 'px';
	
	var iframe = document.createElement('iframe');
	iframe.setAttribute('id', 'content_editor');
	iframe.style.width = editor_width + 'px';
	iframe.style.height = editor_height + 'px';	
	
	textArea.style.display = 'none';
	textArea.parentNode.insertBefore(iframe, textArea);

	var editor = document.getElementById('content_editor').contentWindow.document;
	var iframeContent;
	iframeContent  = '<html>\n';
	iframeContent += '<head>\n';
	iframeContent += '<link href="css/style.css" rel="stylesheet" type="text/css" />\n';
	iframeContent += '</head>\n';
	iframeContent += '<body leftmargin="1" topmargin="1" marginwidth="1" marginheight="1" style="background-color: #FFFFFF; background-image: none">\n';
	iframeContent += textArea.value;
	iframeContent += '</body>\n';
	iframeContent += '</html>';
	
	editor.open();
	editor.write(iframeContent);
	editor.close();	

	if(navigator.appName == 'Microsoft Internet Explorer')
		editor.body.contentEditable = true;
	else
		editor.designMode = 'on';
	
	textArea.form.onsubmit = function(){
		textArea.value = editor.body.innerHTML;
	}
	
}

function createLink() {
	var editor = document.getElementById('content_editor').contentWindow.document;
	if(navigator.appName == 'Microsoft Internet Explorer')
		editor.execCommand('CreateLink', true, null);
	else{
		var selectedRange = document.getElementById('content_editor').contentWindow.getSelection();
		if(url = prompt('URL?', 'http://'))
			editor.execCommand('CreateLink', false, url);	
	}
	focus_editor();	
}

function runCommand(theCommand, thebool, theparam) {
	var editor = document.getElementById('content_editor').contentWindow.document;
	editor.execCommand(theCommand, thebool, theparam);
	focus_editor();
}

function focus_editor(){
	if(navigator.appName == 'Opera')
		document.getElementById('content_editor').focus();
	else
		document.getElementById('content_editor').contentWindow.focus();
}

////////////////////////////////
//  Editor-Funktionen Ende    //
////////////////////////////////

