﻿/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	WebCore: Rich test editing scripts
	Abyss Studios Ltd. (c) 2004-2007

	history:
		080402 - creation -=AGi=-

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

function RichTextEditing() {
	this.frame = null;	
	
	function EnableDesignMode() {
		this.frame.contentWindow.document.designMode = "On";
	}


	function ExecuteCommand(command, value) {
		this.frame.contentWindow.focus();
		if (!document.all) { //no spans for bold, italic
			this.frame.contentWindow.document.execCommand('useCSS', '', true);
			//this.frame.contentWindow.document.execCommand('styleWithCSS', '', false);
		};		
		this.frame.contentWindow.document.execCommand(command, '', value);
		this.frame.contentWindow.focus();
	}
	
	
	function QueryCommandValue(command, value) {
		this.frame.contentWindow.focus();
		this.frame.contentWindow.document.queryCommandValue(command, '', value);
		this.frame.contentWindow.focus();
	}
	
	
	function CopyHTMLBodyTo(element) {
		if (typeof(element)=='string') element = document.getElementById(element);		
		element.value = encodeURIComponent(this.frame.contentWindow.document.body.innerHTML.toString());
	}


	function CopyHTMLBodyFrom(element) {
		if (typeof(element)=='string') element = document.getElementById(element);
		if (element.value!='' && this.frame.contentWindow.document.body) {
			this.frame.contentWindow.document.body.innerHTML = decodeURIComponent(element.value); 
		}
	}


	function Print()
	{
		this.frame.contentWindow.print();
	}

	function Init(frame) {
		if (typeof(frame)=='string') frame = document.getElementById(frame);
		this.frame = frame;
	}
	
	function InitEx(frame, sourceElement, enableDesignMode) {
		this.Init(frame);
		this.CopyHTMLBodyFrom(sourceElement);
		if (enableDesignMode) {		
			this.EnableDesignMode();
		}
	}
	

	this.EnableDesignMode = EnableDesignMode;
	this.ExecuteCommand = ExecuteCommand;
	this.QueryCommandValue = QueryCommandValue;
	this.CopyHTMLBodyTo = CopyHTMLBodyTo;
	this.CopyHTMLBodyFrom = CopyHTMLBodyFrom;
	this.Print = Print;
	this.Init = Init;
	this.InitEx = InitEx;
}
