function __edit_walk(d,f,g)
{
	var i;
	if (d.data) {
		var white = window.top._whitespace;

		var cl = 0;
		var lc = 0;
		var n = [];
		var wc = white.substr(0,1);
		var s = d.data + wc;
		i = 0;
		while (i < s.length) {
			if (white.indexOf(s.substr(i,1)) > -1) {
				cl = 1;
			} else {
				cl = -1;
			}
			if (lc != 0 && cl != lc) {
				var z;
				if (i > 0 && i < d.data.length) {
					z = d.splitText(i);
				} else {
					z = undefined;
				}
				if (cl == 1) {
					if (d.data.indexOf('--') > -1) {
						/* stop at signature! */
						return false;
					}
					f(d,g);
				}
				d = z;
				if (d == undefined) break;
				s = d.data + wc;
				i = 0;
			} else {
				i++;
			}
			lc = cl;
		}
	} else {
		i = d.firstChild;
		while (i) {
			var ni = i.nextSibling;
			if (!__edit_walk(i, f, g)) return false;
			i = ni;
		}
	}
	return true;
}

function __fix_conv(nd, d, ggsub)
{
	if (d.tagName && d.tagName.toLowerCase() == 'select') {
		var o = d.options[d.selectedIndex];
		var txt;
		if (o._replace) txt = o._replace;
		else if (o._original) txt = o._original;
		else txt = o._text;/*shrug */
		var da = o._addtodictionary;
		if (da) {
			ggsub[ggsub.length] = txt;
		}

		var tt = nd.createTextNode(txt);
		d.parentNode.replaceChild(tt,d);

	} else {
		var i;
		for (i = d.childNodes.length-1; i >= 0; i--) {
			__fix_conv(nd, d.childNodes[i], ggsub);
		}
	}
}

function __edit_spellcheck(ii, d, autofire)
{
	if (window.top._busycheck) return false;

	var nd = d._access_fake;
	var xh, ac;
	var o;

	if (d._swapback) {
		if (autofire && autofire.submit) {
			function __autofire_doit() {
				if (autofire.onsubmit) {
					if (!autofire.onsubmit()) return;
				}
				autofire.submit();
			}
			window.top.setTimeout(__autofire_doit, 10);
			return false;
		}

		nd.id = null;
		d.id = d._real_id;

		d.style.display = 'block';
		nd.style.display = 'none';

		// copy "results" back...
		var gg = [];
		__fix_conv(nd._document, nd._document.body, gg);

		o = '';
		for (i = 0; i < gg.length; i++) {
			o += 'a' + i + '=' + escape(gg[i]) + '&';
		}

		var str = nd._document.body.innerHTML + '';
		if (o.length > 0) {
			o = o.substr(0, o.length-1)
			xh = XHTTP();
			ac = d._spellcheck_url;
			if (ac.indexOf('?') == -1) {
				o = ac + "?" + o;
			} else {
				o = ac + "&" + o;
			}
			xh.open("GET", o, true);
			xh.setRequestHeader('Accept', 'text/x.vnd-spelling-check');
			xh.onreadystatechange = function() {
				document.body.style.cursor = 'default';
				return true;
			};
			document.body.style.cursor = 'wait';
			xh.send(undefined);
			window.top._fixed_spell = str;
		} else {
			window.top._fixed_spell = str;
			window.top._didspell = str;
			window.top._busycheck = false;
		}
	
		d._hacktimeout = nd._document.body;

		var layer0 = function() {
			d._document = d.contentDocument || d.contentWindow.document;
			nd._document = nd.contentDocument || nd.contentWindow.document;
			d.window = d.contentWindow || d._document.window;
			nd.window = nd.contentWindow || nd._document.window;

			d._document.designMode = 'on';

			var layer1 = function() {
				if (d.window.focus) d.window.focus();

				d._document.body.innerHTML = window.top._fixed_spell;
			};
			window.setTimeout(layer1, 100);
		};
		window.setTimeout(layer0, 0);

		d._swapback = false;
		ii.className = 'toolbarbutton';

		window.top.__finish_spelling = undefined;
		window.top.__finish_speller = undefined;

		return true;
	}

	window.top.__finish_speller = [ ii, d ];
	window.top.__finish_spelling = function(af) {
		var qqq = window.top.__finish_speller;

		return __edit_spellcheck(qqq[0], qqq[1], af);
	};

	ii.className = 'toolbarbutton active';

	var j = window.top.document.getElementById('activity');
	if (j) j.style.display = 'block';
	window.top._busycheck = true;

	nd._document.open('text/html', 'replace');
	nd._document.write('<body>' + d._document.body.innerHTML + '</body>');
	nd._document.close();
	nd._document.body.style.cursor = 'default';

	nd._document.body.style.background = '#eee';
	d.id = null;
	nd.id = d._real_id;
	d.style.display = 'none';
	nd.style.display = 'block';

	nd._document.body.normalize();
	var w = nd._document.body;
	function __edit_walk_collect(t, gg) {
		gg[gg.length] = t;
	}

	var gwords = [];
	__edit_walk(w, __edit_walk_collect, gwords);

	var scanner = new Object;

	function __edit_spell2(autofire, jd, sc, uw) {
		var i;

		var nd = jd._access_fake;
		var didany = false;
		for (i = 0; i < uw.length; i++) {
			var t = uw[i];
			var a = sc[t];
			var j;

			var m = window.top._wordcheck[t];
			if (m.length == 1 && m[0] == t) {
				// word valid; leave alone
				continue;
			}

			var gato = [];

			didany = true;
			for (j = 0; j < a.length; j++) {
				var tex = a[j];
				var so = nd._document.createElement('SELECT');
				so._peers = gato;

				var oo = nd._document.createElement('OPTION');
				oo.className = 'spellcheckorig';
				oo._text = tex.data;
				oo.value = oo._text;
				oo._replace = tex.data;

				var ot = nd._document.createTextNode(oo._text);
				oo.appendChild(ot);

				so.appendChild(oo);

				var x;
				for (x = 0; x < m.length; x++) {
					oo = nd._document.createElement('OPTION');
					oo.className = 'spellchecksuggestion';
					oo._text = m[x];
					oo.value = oo._text;
					oo._replace = m[x];
					ot = nd._document.createTextNode(oo._text);
					oo.appendChild(ot);
					so.appendChild(oo);
				}
				oo = nd._document.createElement('OPTION');
				oo.className = 'spellcheckedit';
				// TODO NLS
				oo._text = 'Edit/Add to dictionary...';
				oo.value = oo._text;
				oo._original = tex.data;
				ot = nd._document.createTextNode(oo._text);
				oo.appendChild(ot);
				so.appendChild(oo);

				so._origterm = tex.data;
				so.className = 'spellcheckorig';
				so.onchange = function(e) {
					if (typeof this.options[this.selectedIndex]._original != 'undefined') {
						var r = this.options[this.selectedIndex];
						this.selectedIndex = 0;
						var o = this.options[this.selectedIndex];
						// TODO NLS
						o._replace = window.top.prompt("Replace with:", r._original);
						if (o._replace == r._original) {
							// TODO NLS
							if (window.top._to_add[o._replace]) {
								o._addtodictionary = true;
							} else {
								o._addtodictionary = window.top.confirm("Add \"" + o._replace + "\" to dictionary?");
								if (o._addtodictionary) window.top._to_add[o._replace] = true;
							}
						}
						o._text = o._replace;
					}

					this.className = this.options[this.selectedIndex].className;

					if (this._peers.length > 1) {
						// TODO NLS
						var t = window.top.confirm("Change all other occurrences of \"" + this._origterm + "\"");
						if (t) {
							for (t = 0; t < this._peers.length; t++) {
								var mm = this._peers[t];
								mm.selectedIndex = this.selectedIndex;
								mm.className = this.options[this.selectedIndex].className;
								var mo = mm.options[mm.selectedIndex];
								var to = this.options[this.selectedIndex];
								mo._replace = to._replace;
								mo._text = to._text;
							}
						}
					}

				};

				tex.parentNode.replaceChild(so, tex);

				gato[gato.length] = so;
			}
		}

		i = window.top.document.getElementById('activity');
		if (i) i.style.display = 'none';

		jd._swapback = true;
		jd._didspell = jd._document.body.innerHTML + '';;
		window.top._busycheck = false;

		if (!didany) {
			if (window.top.__finish_spelling) {
				window.top.__finish_spelling(autofire);
			}
		}
	}

	var i;
	var uwords = [];
	o = '';
	for (i = 0; i < gwords.length; i++) {
		var term = gwords[i].data;
		if (scanner[term] == undefined) {
			scanner[term] = [ gwords[i] ];
			uwords[uwords.length] = term;
			if (window.top._wordcheck[term] == undefined) {
				window.top._wordcheck[term] = [];
				o += 'c' + i + '=' + escape(term) + '&';
			}
		} else {
			var a = scanner[term];
			a[a.length] = gwords[i];
		}
	}
	if (o.length > 0) {
		o = o.substr(0, o.length-1)
		xh = XHTTP();
		ac = d._spellcheck_url;
		if (ac.indexOf('?') == -1) {
			o = ac + "?" + o;
		} else {
			o = ac + "&" + o;
		}
		xh.open("GET", o, true);
		xh.setRequestHeader('Accept', 'text/x.vnd-spelling-check');
		xh.onreadystatechange = function() {
			if (xh.readyState == 4) {
				var j;
				var a = xh.responseText.split("\n");
				var did = new Object;
				for (j = 0; j < a.length; j++) {
					var kp = a[j].split("=", 2);
					var k, v;
					if (kp.length == 2) {
						k = kp[0];
						v = kp[1];
					} else if (kp.length == 1) {
						k = kp[0];
						v = undefined;
					} else {
						k = a[j];
						v = undefined;
					}
					if (k.substr(0, 1) != 'c') continue;
					k = k.substr(1, k.length-1);
					var term = gwords[k].data;
					if (!did[term]) {
						window.top._wordcheck[term] = [];
						did[term] = true;
					}
					var wl = window.top._wordcheck[term];
					if (v != undefined && v != '') {
						if (v != term) autofire = undefined;
						wl[wl.length] = v;
					}
				}

				__edit_spell2(autofire, d, scanner, uwords);
				document.body.style.cursor = 'default';
			}
		};
		document.body.style.cursor = 'wait';
		xh.send(undefined);
	} else {
		__edit_spell2(autofire, d, scanner, uwords);
	}

	return true;
}

function strmap(s, a,b) {
	var i, j;
	for (j = 0; j < s.length; j++) {
		for (i = 0; i < a.length; i++) {
			if (s.charAt(j) == a[i]) {
				s = s.substr(0, j)
					+ b[i]
					+ s.substr(j+1);
				j += (b[i].length)-1;
				break;
			}
		}
	}
	return s;
}
function html_escape(e) {
	return strmap(e, [ "&", "<", "\"" ], [ "&amp;", "&lt;", "&quot;" ]);
}
function __str_re(s,r,e) {
	var j = s.replace(r,e);
	if (typeof j == 'undefined') return s;
	return j;
}

function __edit_wrap(s, c)
{
	var o = '';
	var re = /[ \t\r\n]+$/;
	var ire = /^[ \t\r\n]+/;
	var tre = /[ \t\r\n]+([^ \t\r\n]+)$/;
	s=__str_re(s,re, '');
	while (s.length > c) {
		var left = s.substr(0, c);
		var right = s.substr(c, s.length - c);
		left=__str_re(left,re, '');
		right=__str_re(right,ire, '');
		if (left.length < c || right.length < (s.length - c)) {
			o += left + "\n";
			s = right;
		} else {
			var sr = tre.exec(left);
			left=__str_re(left,tre,'');
			s = sr[1] + right;
			o += left + "\n";
		}
	}

	if (o != '') s=__str_re(s,ire,'');
	o += s + "\n";
	return o;
}

function __edit_loadplain(t)
{
	t = html_escape(t);
	t=__str_re(t, /\r?\n\r?\n/g, '<P>');
	t=__str_re(t, /\r?\n/, '<BR/>');
	return t;
}

function __edit_plain_part(d)
{
	var i, o = '';
	var tn = d.tagName;
	if (tn != undefined) {
		tn = tn.toLowerCase();
		if (tn == 'br') {
			o = '\n';
		} else if (tn == 'p') {
			o = '\n\n';
		}
	}

	for (i = 0; i < d.childNodes.length; i++) {
		o += __edit_plain_part(d.childNodes[i]);
	}
	if (d && d.className && d.className == 'quotation') {
		var inlines = o.split("\n");
		var outlines = '';
		for (i = 0; i < inlines.length; i++) {
			outlines += '> ' + inlines[i];
			if (i < inlines.length-1) outlines += "\n";
		}
		return outlines;
	}
	if (d.data) o += d.data;
	return o;
}

function __edit_plain(d)
{
	var o = __edit_plain_part(d);

	// okay, word-wrap at 70 characters
	var inlines = o.split("\n");
	var outlines = '';
	for (i = 0; i < inlines.length; i++) {
		outlines += __edit_wrap(inlines[i], 70);
	}
	outlines=__str_re(outlines, /\240/g, " ");
	outlines=__str_re(outlines, /^[\r\n\t ]+/, "");
	return outlines;
}


function __colorpal(bigd, ii, cb)
{
	var colors = [
		'#FFFFFF', '#FFCCCC', '#FFCC99', '#FFFF99', '#FFFFCC',
	    	'#99FF99', '#99FFFF', '#CCFFFF', '#CCCCFF', '#FFCCFF',
		'#CCCCCC', '#FF6666', '#FF9966', '#FFFF66', '#FFFF33',
		'#66FF99', '#33FFFF', '#66FFFF', '#9999FF', '#FF99FF',
		'#C0C0C0', '#FF0000', '#FF9900', '#FFCC66', '#FFFF00',
		'#33FF33', '#66CCCC', '#33CCFF', '#6666CC', '#CC66CC',
		'#999999', '#CC0000', '#FF6600', '#FFCC33', '#FFCC00',
		'#33CC00', '#00CCCC', '#3366FF', '#6633FF', '#CC33CC',
		'#666666', '#990000', '#CC6600', '#CC9933', '#999900',
		'#009900', '#339999', '#3333FF', '#6600CC', '#993399',
		'#333333', '#660000', '#993300', '#996633', '#666600',
		'#006600', '#336666', '#000099', '#333399', '#663366',
		'#000000', '#330000', '#663300', '#663333', '#333300',
		'#003300', '#003333', '#000066', '#330099', '#330033'
	];
	function RGB2HSV(r,g,b) {
		r/=256; g/=256; b/=256;
		var d, min, max, H, S, V;
		min = Math.min(r,Math.min(g,b));
		max = Math.max(r,Math.max(g,b));
		d = max-min;
		V = max;
		if (d>0) S = d/max;
		else return [0,0,V];
		if (r==max) H = (g-b)/d;
		else if (g==max) H = 2 + (b-r)/d;
		else H = 4 + (r-g)/d;
		H *= 60;
		while (H<0) H += 360;
		while (H>=360) H -= 360;
		return [H,S,V];
	}
	function HSV2RGB(h,s,v) {
		var r, g, b;
		if (s == 0) {
			r = parseInt(Math.floor(255*v));
			return [r,r,r];
		}
		while (h<0) h += 360;
		while (h>=360) h -= 360;
		var nh = h / 60;
		var ic = Math.floor(nh);
		var fc = nh-ic;
		var colp = [ 0, 0, 0, 0 ];
		var colr = [ 2, 1, 0, 0, 3, 2 ];
		var colg = [ 3, 2, 2, 1, 0, 0 ];
		var colb = [ 0, 0, 3, 2, 2, 1 ];
		colp[2] = 255 * v;
		colp[0] = colp[2] * (1-s);
		colp[1] = colp[2] * (1-s*fc);
		colp[3] = colp[2] * (1-s*(1-fc));
		r = Math.floor(colp[colr[ic]] * 256);
		g = Math.floor(colp[colg[ic]] * 256);
		b = Math.floor(colp[colb[ic]] * 256);
		return [r,g,b];
	}

	var i, j;

	var tt = document.createElement('DIV');

	var fx = function() {
		var co = this._color;
		var cb = this._callback;
		var gii = this._button;
		var gtt = this._container;
		gtt._opened = false;
		gtt.style.display = 'none';
		if (gtt.saved_selection != undefined && gtt.saved_selection.select)
			gtt.saved_selection.select();
		gtt.saved_selection = undefined;
		cb(gii, co);
	};

	var dd = document.createElement('DIV');
	var row = 0;
	for (i = 0; i < colors.length;) {
		var tr = document.createElement('DIV');
		for (j = 0; j < 10; j++, i++) {
			var td = document.createElement('IMG');
			td.src = window.top.__htmlpath + '/spacer.gif';
			td.width = '18px';
			td.height = '18px';
			td._button = ii;
			td._callback = cb;
			td._container = tt;
			td._color = colors[i];
			var rpart = colors[i].substr(1,2);
			var gpart = colors[i].substr(3,2);
			var bpart = colors[i].substr(5,2);
			rpart = parseInt(rpart, 16);
			gpart = parseInt(gpart, 16);
			bpart = parseInt(bpart, 16);

			var hsv = RGB2HSV(rpart,gpart,bpart);
			hsv[0] += 180;
			hsv[2] = 1.0 - hsv[2];
			hsv[1] = 1.0 - hsv[1];
			var rgb = HSV2RGB(hsv[0], hsv[1], hsv[2]);
			rpart = rgb[0];
			gpart = rgb[1];
			bpart = rgb[2];

			td._rgb = 'rgb(' + rpart + ', ' + gpart + ', ' + bpart + ')';

			td.style.padding = '0px 0px';
			td.style.margin = '0px 0px';
			td.style.width = '18px';
			td.style.height = '18px';
			td.style.position = 'relative';
			td.style.background = colors[i];
			td.style.cursor = 'crosshair';
			td.style.border = '2px solid ' + colors[i];
			td._mouseenter = function() {
				this.style.border = '2px dashed ' + this._rgb;
			};
			td._mouseleave = function() {
				this.style.border = '2px solid ' + this._color;
			};
			if (document.addEventListener) {
				td.addEventListener('click', fx, false);
				td.addEventListener('mouseover', td._mouseenter, false);
				td.addEventListener('mouseout', td._mouseleave, false);
			} else {
				td.onclick = fx;
				td.onmouseenter = td._mouseenter;
				td.onmouseleave = td._mouseleave;
			}
			tr.appendChild(td);
		}
		dd.appendChild(tr);
		row++;
	}

	dd.style.border = '1px solid black';
	tt.appendChild(dd);

	tt.style.background = 'white';
	tt.style.position = 'absolute';
	tt.style.top = '0px';
	tt.style.left = '0px';
	tt.style.display = 'none';
	tt._opened = false;
	tt._bigd = bigd;
	var nx = function() {
		var gii = this;
		var gtt = this._palette;
		var gbigd = gtt._bigd;

		var cx = function(xtt) {
			if (xtt._opened) {
				xtt._opened = false;
				xtt.style.display = 'none';
				if (xtt.saved_selection != undefined && xtt.saved_selection.select)
					gtt.saved_selection.select();
				xtt.saved_selection = undefined;
				window.top._palette_close = undefined;
			}
		};

		if (gtt._opened) {
			cx(gtt);

		} else {
			if (window.top._palette_close) {
				window.top._palette_close();
			}
			window.top._palette_xtt = gtt;
			window.top._palette_close = function() {
				var xtt = window.top._palette_xtt;
				if (xtt._opened) {
					xtt._opened = false;
					xtt.style.display = 'none';
					if (xtt.saved_selection != undefined && xtt.saved_selection.select)
						gtt.saved_selection.select();
					xtt.saved_selection = undefined;
				}
				window.top._palette_close = undefined;
			};
			var fu = function() {
				this._clearme(this._palette);
			};
			gbigd._document._palette = gtt;
			gbigd._document._clearme = cx;
			if (gbigd._document) gtt.saved_selection = gbigd._document.selection;
			if (gbigd._document.addEventListener) {
				gbigd._document.addEventListener('mousedown', fu, false);
				gbigd._document.addEventListener('click', fu, false);
			} else {
				gbigd._document.onmousedown = fu;
				gbigd._document.onclick = fu;
			}

			gtt._opened = true;
			var l = parseInt(gii.offsetLeft);
			var t = parseInt(gii.offsetTop) + parseInt(gii.offsetHeight);
			var sig = gii;
			while (sig.offsetParent) {
				sig = sig.offsetParent;
				l += parseInt(sig.offsetLeft);
				t += parseInt(sig.offsetTop);
			}
			gtt.style.left = l + 'px';
			gtt.style.top = t + 'px';
			gtt.style.display = 'block';
		}
	};
	tt._open = nx;
	ii._palette = tt;


	// it needs an id for some reason...
	if (!window.top._counter) window.top._counter = 0;
	window.top._counter++;
	var sid = '$sPe33l1C3hez3v9t1$%' + window.top._counter;
	tt.id = sid;

	return tt;
}

function edit_install(htmlpath)
{
	var a = document.getElementsByTagName('textarea');
	var i;

	window.top.__htmlpath = htmlpath;
	window.top._whitespace = "\240 \t\r\n?.,:;\"";
	window.top._wordcheck = new Object;
	window.top._wordreplaceall = new Object;
	window.top._to_add = new Object;
	window.top._wordreplaceall_ready = 0;
	for (i = 0; i < a.length; i++) {
		if (!a[i].getAttribute) continue;

		var want_plain = false;

		var at = a[i].getAttribute('type');
		if (at == 'text/plain') {
			// plain editor
			want_plain = true;
		} else {
			if (at != 'text/html') continue;
		}

		var css = a[i].style;
		var as = a[i].getAttribute('spellcheck');
		var rt = a[i].getAttribute('richtools');
		if (!rt) rt = '';

		var d = document.createElement('IFRAME');
		d._want_plain = want_plain;
		var nd = document.createElement('IFRAME');

		var gb = document.createElement('DIV');
		gb.className = 'richeditor';

		var bb = document.createElement('DIV');
		bb.style.width = '100%';

		d._hidbox = a[i];

		rt = rt.split(" ");
		var x;
		if (as) {
			var need_sp = true;
			for (x = 0; x < rt.length; x++) {
				if (rt[x] == 'spellcheck'
				|| rt[x] == 'autospellcheck') {
					need_sp = false;
					break;
				}
			}
			if (need_sp) {
				rt[rt.length] = 'spellcheck';
			}
			d._spellcheck_url = as;
		}
		for (x = 0; x < rt.length; x++) {
			if (rt[x] == '|') {
				gb.appendChild(bb);
				bb = document.createElement('DIV');
				bb.style.width = '100%';
				continue;
			}

			if (rt[x] == 'fontname'
			|| rt[x] == 'fontsize'
			|| rt[x] == 'formatblock') {
				var ii = document.createElement('SELECT');
				ii.className = 'toolbarcombo';
				ii._command = rt[x];
				ii._editor = d;

				var op;
				var ov;
				if (rt[x] == 'fontname') {
					// TODO NLS
					op = [ 'Serif', 'Sans-Serif', 'Cursive', 'Fantasy', 'Monospace' ];
					ov = op;
				} else if (rt[x] == 'fontsize') {
					op = [ '1', '2', '3', '4', '5', '6', '7' ];
					ov = op;
				} else if (rt[x] == 'formatblock') {
					// TODO NLS
					op = [ 'Normal', 'Paragraph', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5', 'Heading 6', 'Address', 'Formatted' ];
					ov = [ '<p>', '<p>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<address>', '<pre>' ];
				}
				
				var y;
				for (y = 0; y < op.length; y++) {
					var oo = document.createElement('OPTION');
					oo.value = ov[y];
					var ot = document.createTextNode(op[y]);
					oo.appendChild(ot);
					ii.appendChild(oo);
				}
				if (rt[x] == 'fontsize') {
					ii.selectedIndex = 2;
				}
				ii.onchange = function() {
					this._editor._document.execCommand(this._command,
							false,
							this.options[this.selectedIndex].value);
					this._editor.window.focus();
				};

				bb.appendChild(ii);
				continue;
			}

			var src = rt[x];
			if (src == '') continue; /* err... */

			ii = document.createElement('IMG');
			bb.appendChild(ii);

			if (rt[x] == 'autospellcheck') {
				src = 'spellcheck';
				if (a[i].form) {
					a[i].form._autospellcheck = true;
				}

			}

			ii.src = window.top.__htmlpath + '/' + src + '.gif';

			if (!document.all && rt[x] == 'backcolor') {
				rt[x] = 'hilitecolor';
			}


			ii._command = rt[x];
			ii._editor = d;
			ii.className = 'toolbarbutton';
			ii._down = false;
			var fx;
			if (rt[x] == 'forecolor' || rt[x] == 'hilitecolor' || rt[x] == 'backcolor') {
				var cb = function(de, df) {
					var qw = de._editor._document;
					qw.execCommand(de._command, false, df);
					de._down = false;
					de.className = 'toolbarbutton';
					de._editor.window.focus();
				};
				var c = __colorpal(d, ii, cb);
				c._command = rt[x];
				c._editor = d;
				bb.appendChild(c);
				fx = c._open;

			} else if (rt[x] == 'spellcheck' || rt[x] == 'autospellcheck') {
				ii._top = gb;
				if (!d._speller) {
					d._speller = ii;
				}
				fx = function() {
					__edit_spellcheck(this, this._editor, undefined);
				};

			} else {
				if (rt[x] == 'orderedlist' || rt[x] == 'unorderedlist') {
					ii._command = 'insert' + rt[x];
				}
				fx = function() {
					var qw = this._editor._document;
					if (this._command.substr(0,7).toLowerCase() == 'justify') {
						this._down = false;
						this.className = 'toolbarbutton';
					}
					qw.execCommand(this._command, false, undefined);
					this._editor.window.focus();
				};
			}

			var bd = function() {
				this.className = 'toolbarbuttondown';
				return true;
			};
			var bu = function() {
				if (this._down == false) {
					this.className = 'toolbarbuttondown';
					this._down = true;
				} else {
					this.className = 'toolbarbutton';
					this._down = false;
				}
				return true;
			};

			if (ii.addEventListener) {
				ii.addEventListener('mousedown', bd, false);
				ii.addEventListener('mouseup', bu, false);
				ii.addEventListener('click', fx, false);
			} else {
				ii.onmousedown = bd;
				ii.onmouseup = bu;
				ii.onclick = fx;
			}
		}

		gb.appendChild(bb);

		nd.style.display = 'none';

		gb.appendChild(d);
		gb.appendChild(nd);
		d.className = a[i].className;
		nd.className = a[i].className;

		d._access_fake = nd;
		d._real_id = a[i].id;

		var ff = a[i].form;
		d._useform = ff;

		var j;
		var p = a[i].parentNode;
		a[i].style.display = 'none';
		p.insertBefore(gb, a[i]);

		nd.style.background = 'white';
		nd.style.width = '100%';
		d.style.background = 'white';
		d.style.width = '100%';

		var layer0 = function() {
			var f = d._hidbox;
			if (f.form) {
				f = f.form;
			} else {
				while (f && f.tagName && f.tagName.toLowerCase != 'form')
					f = f.parentNode;
				if (!f.tagName) f = undefined;
			}
			if (f) {
				if (!f.elements[d._hidbox.name]) {
					f.elements[d._hidbox.name] = d._hidbox;
				}
			}

			d._document = d.contentDocument || d.contentWindow.document;
			nd._document = nd.contentDocument || nd.contentWindow.document;
			d.window = d.contentWindow || d._document.window;
			nd.window = nd.contentWindow || nd._document.window;

			d._document.designMode = 'on';

			var layer1 = function() {
				d.window.focus();

				if (document.all) {
					var sid = '$eDit03rTem03mrady$%' + i;
					var gid = '$eDit03rTem03mraqY$%' + i;
					d.id = sid;
					nd.id = gid;
					d._framewindow = document.frames[sid];
					nd._framewindow = document.frames[gid];
					d._document = d._framewindow.document;
					nd._document = nd._framewindow.document;
				}
		
				d._document.open('text/html', 'replace');
				var ih = d._hidbox;
				if (want_plain) {
					var t = __edit_loadplain(ih.value);
					d._document.write('<body>' + t + '</body>');
				} else {
					d._document.write('<body>' + ih.value + '</body>');
				}
				d._document.close();

				nd._document.open('text/html','replace');
				nd._document.write('<body></body>');
				nd._document.close();
		
				if (css) gb.style.width = css.width;

				d._document._accessd = d;
				d.id = d._real_id;
				nd.id = null;

				DOM(d._document);
			};
			if (d._useform) {
				if (!d._useform._areas) {
					d._useform._areas = [];
				}
				d._useform._areas[ d._useform._areas.length ] = d;
			}

			window.setTimeout(layer1, 100);
		};
		window.setTimeout(layer0, 0);

		if (ff && !ff._marked) {
			ff._marked = true;

			ff._pf_chain = ff.onsubmit;
			ff.onsubmit = function(e) {
				if (!e) e = window.event;
				var i;
				var ad;
				if (!window.top._avert) {
					for (i = 0; i < ff._areas.length; i++) {
						ad = ff._areas[i];
						ad._hacktimeout = undefined;
					}
	
					if (this._pf_chain && !this._pf_chain(e)) return false;
					if (window.top.__finish_spelling) {
						if (!window.top.__finish_spelling(undefined)) return false;
					}
	
					if (this._autospellcheck && ff._areas) {
						for (i = 0; i < ff._areas.length; i++) {
							ad = ff._areas[i];
							var ads = ad._document.body.innerHTML+'';
							if (!ad._didspell || ad._didspell != ads) {
								__edit_spellcheck(ad._speller, ad, ff);
								return false;
							}
						}
					}
				}

				if (ff._areas) {
					// coppy hidden values back
					for (i = 0; i < ff._areas.length; i++) {
						ad = ff._areas[i];
						var ih = ad._hidbox;
						if (ad._want_plain) {
							if (ad._hacktimeout) {
								ih.value = __edit_plain(ad._hacktimeout);
							} else {
								ih.value = __edit_plain(ad._document.body);
							}
						} else {
							if (ad._hacktimeout) {
								ih.value = ad._hacktimeout.innerHTML;
							} else {
								ih.value = ad._document.body.innerHTML;
							}
						}
					}
				}

				// let it submit
				return true;
			};
		}
	}

}

