
function phpbb_Text_Editor(editorid, mode, parsetype, parsesmilies, initial_text)
{
	this.editorid = editorid;
	this.initialized = false;
	this.parsetype = (typeof parsetype == 'undefined' ? 'nonforum' : parsetype);
	this.parsesmilies = (typeof parsesmilies == 'undefined' ? 1 : parsesmilies);
	this.popupmode = (typeof phpbbmenu == 'undefined' ? false : true);
	this.controlbar = fetch_object(this.editorid + '_controls');
	this.textobj = fetch_object(this.editorid + '_textarea');
	this.buttons = new Array();
	this.popups = new Array();
	this.fontstate = null;
	this.sizestate = null;
	this.colorstate = null;
	this.clipboard = '';
	this.disabled = false;
	this.history = new phpbb_History();
	this.influx = 0;

	// =============================================================================
	// phpbb_Text_Editor methods

	/**
	* Editor initialization wrapper
	*/
	this.init = function()
	{
		if (this.initialized)
		{
			return;
		}

		this.textobj.disabled = false;

		if (this.tempiframe)
		{
			this.tempiframe.parentNode.removeChild(this.tempiframe);
		}

		this.set_editor_contents(initial_text);

		this.set_editor_functions();

		this.init_controls();

		this.init_smilies(fetch_object(this.editorid + '_smiliebox'));

		if (typeof smilie_window != 'undefined' && !smilie_window.closed)
		{
			this.init_smilies(smilie_window.document.getElementById('smilietable'));
		}

		this.initialized = true;
	};

	/**
	* Check if we need to refocus the editor window
	*/
	this.check_focus = function()
	{
		if (!this.editwin.hasfocus)
		{
			this.editwin.focus();
			if (is_opera)
			{
				this.editwin.focus();
			}
		}
	}

	/**
	* Init button controls for the editor
	*/
	this.init_controls = function()
	{
		var controls = new Array();

		if (this.controlbar == null)
		{
			return;
		}

		var buttons = fetch_tags(this.controlbar, 'div');
		for (var i = 0; i < buttons.length; i++)
		{
			if (buttons[i].className == 'imagebutton' && buttons[i].id)
			{
				controls[controls.length] = buttons[i].id;
			}
		}
		for (var i = 0; i < controls.length; i++)
		{
			var control = fetch_object(controls[i]);

			if (control.id.indexOf(this.editorid + '_cmd_') != -1)
			{
				this.init_command_button(control);
			}
			else if (control.id.indexOf(this.editorid + '_popup_') != -1)
			{
				this.init_popup_button(control);
			}
		}

		set_unselectable(this.controlbar);
	};

	/**
	* Init Smilies
	*/
	this.init_smilies = function(smilie_container)
	{
		if (smilie_container != null)
		{
			var smilies = fetch_tags(smilie_container, 'img');
			for (var i = 0; i < smilies.length; i++)
			{
				if (smilies[i].id && smilies[i].id.indexOf('_smilie_') != false)
				{
					smilies[i].style.cursor = pointer_cursor;
					smilies[i].editorid = this.editorid;
					smilies[i].onclick = phpbb_Text_Editor_Events.prototype.smilie_onclick;
					smilies[i].unselectable = 'on';
				}
			}
		}
	}

	/**
	* Init command button (b, i, u etc.)
	*
	* @param	object	Current HTML button node
	*/
	this.init_command_button = function(obj)
	{
		obj.cmd = obj.id.substr(obj.id.indexOf('_cmd_') + 5);
		obj.editorid = this.editorid;
		this.buttons[obj.cmd] = obj;
		obj.state = false;
		obj.mode = 'normal';
		obj.onclick = obj.onmousedown = obj.onmouseover = obj.onmouseout = phpbb_Text_Editor_Events.prototype.command_button_onmouseevent;
	}

	/**
	* Init popup button (forecolor, fontname etc.)
	*
	* @param	object	Current HTML button node
	*/
	this.init_popup_button = function(obj)
	{
		obj.cmd = obj.id.substr(obj.id.indexOf('_popup_') + 7);

		if (this.popupmode)
		{
			phpbbmenu.register(obj.id, true);
			phpbbmenu.menus[obj.id].open_steps = 5;

			obj.editorid = this.editorid;
			obj.state = false;
			this.buttons[obj.cmd] = obj;

			if (obj.cmd == 'fontname')
			{
				this.fontout = fetch_object(this.editorid + '_font_out');
				this.fontout.innerHTML = obj.title;
				this.fontoptions = {'' : this.fontout};

				for (var option in fontoptions)
				{
					var div = document.createElement('div');
					div.id = this.editorid + '_fontoption_' + fontoptions[option];
					div.style.width = this.fontout.style.width;
					div.style.display = 'none';
					div.innerHTML = fontoptions[option];
					this.fontoptions[fontoptions[option]] = this.fontout.parentNode.appendChild(div);
				}
			}
			else if (obj.cmd == 'fontsize')
			{
				this.sizeout = fetch_object(this.editorid + '_size_out');
				this.sizeout.innerHTML = obj.title;
				this.sizeoptions = {'' : this.sizeout};

				for (var option in sizeoptions)
				{
					var div = document.createElement('div');
					div.id = this.editorid + '_sizeoption_' + sizeoptions[option];
					div.style.width = this.sizeout.style.width;
					div.style.display = 'none';
					div.innerHTML = sizeoptions[option];
					this.sizeoptions[sizeoptions[option]] = this.sizeout.parentNode.appendChild(div);
				}
			}

			obj._onmouseover = obj.onmouseover;
			obj._onclick = obj.onclick;
			obj.onmouseover = obj.onmouseout = obj.onclick = phpbb_Text_Editor_Events.prototype.popup_button_onmouseevent;

			phpbbmenu.menus[obj.id]._show = phpbbmenu.menus[obj.id].show;
			phpbbmenu.menus[obj.id].show = phpbb_Text_Editor_Events.prototype.popup_button_show;
		}
		else
		{
			this.build_select(obj);
		}
	}

	/**
	* Replace the popup controls with <select> menus for rubbish browsers
	*
	* @param	object	The popup control element
	*/
	this.build_select = function(obj)
	{
		var sel = document.createElement('select');
		sel.id = this.editorid + '_select_' + obj.cmd;
		sel.editorid = this.editorid;
		sel.cmd = obj.cmd;

		var opt = document.createElement('option');
		opt.value = '';
		opt.text = obj.title;
		sel.add(opt, is_ie ? sel.options.length : null);

		var opt = document.createElement('option');
		opt.value = '';
		opt.text = ' ';
		sel.add(opt, is_ie ? sel.options.length : null);

		switch (obj.cmd)
		{
			case 'fontname':
			{
				for (var i = 0; i < fontoptions.length; i++)
				{
					var opt = document.createElement('option');
					opt.value = fontoptions[i];
					opt.text = (fontoptions[i].length > 10 ? (fontoptions[i].substr(0, 10) + '...') : fontoptions[i]);
					sel.add(opt, is_ie ? sel.options.length : null);
				}

				sel.onchange = phpbb_Text_Editor_Events.prototype.formatting_select_onchange;
				break;
			}

			case 'fontsize':
			{
				for (var i = 0; i < sizeoptions.length; i++)
				{
					var opt = document.createElement('option');
					opt.value = sizeoptions[i];
					opt.text = sizeoptions[i];
					sel.add(opt, is_ie ? sel.options.length : null);
				}

				sel.onchange = phpbb_Text_Editor_Events.prototype.formatting_select_onchange;
				break;
			}

			case 'forecolor':
			{
				for (var i in coloroptions)
				{
					var opt = document.createElement('option');
					opt.value = i;
					opt.text = PHP.trim((coloroptions[i].length > 5 ? (coloroptions[i].substr(0, 5) + '...') : coloroptions[i]).replace(new RegExp('([A-Z])', 'g'), ' $1'));
					opt.style.backgroundColor = i;
					sel.add(opt, is_ie ? sel.options.length : null);
				}

				sel.onchange = phpbb_Text_Editor_Events.prototype.formatting_select_onchange;
				break;
			}

			case 'spellcheck':
			{
				for (var i in spellcheckoptions)
				{
					var opt = document.createElement('option');
					opt.value = i;
					opt.text = spellcheckoptions[i];
					sel.add(opt, is_ie ? sel.options.length : null);
				}
				
				sel.onchange = phpbb_Text_Editor_Events.prototype.formatting_select_onchange;
				break;
			}
		}

		while (obj.hasChildNodes())
		{
			obj.removeChild(obj.firstChild);
		}

		this.buttons[obj.cmd] = obj.appendChild(sel);
	}

	/**
	* Init menu controls for the editor
	*
	* @param	object	HTML menu node
	*/
	this.init_popup_menu = function(obj)
	{
		if (this.disabled)
		{
			return;
		}

		switch (obj.cmd)
		{
			case 'fontname':
			{
				var menu = this.init_menu_container('fontname', '200px', '250px', 'auto');
				this.build_fontname_popup(obj, menu);
				break;
			}
			case 'fontsize':
			{
				var menu = this.init_menu_container('fontsize', 'auto', 'auto', 'visible');
				this.build_fontsize_popup(obj, menu);
				break;
			}
			case 'forecolor':
			{
				var menu = this.init_menu_container('forecolor', 'auto', 'auto', 'visible');
				this.build_forecolor_popup(obj, menu);
				break;
			}
			case 'spellcheck':
			{
				var menu = this.init_menu_container('spellcheck', 'auto', 'auto', 'visible');
				this.build_spellcheck_popup(obj, menu);
				break;
			}
		}

		this.popups[obj.cmd] = this.controlbar.appendChild(menu);

		set_unselectable(menu);
	};

	/**
	* Init Menu Container DIV
	*
	* @param	string	Command string (forecolor, fontname etc.)
	* @param	string	CSS width for the menu
	* @param	string	CSS height for the menu
	* @param	string	CSS overflow for the menu
	*
	* @return	object	Newly created menu element
	*/
	this.init_menu_container = function(cmd, width, height, overflow)
	{
		var menu = document.createElement('div');

		menu.id = this.editorid + '_popup_' + cmd + '_menu';
		menu.className = 'phpbbmenu_popup';
		menu.style.display = 'none';
		menu.style.cursor = 'default';
		menu.style.padding = '3px';
		menu.style.width = width;
		menu.style.height = height;
		menu.style.overflow = overflow;

		return menu;
	}

	/**
	* Build Font Name Popup Contents
	*
	* @param	object	The control object for the menu
	* @param	object	The menu container object
	*/
	this.build_fontname_popup = function(obj, menu)
	{
		for (var n in fontoptions)
		{
			var option = document.createElement('div');
			option.innerHTML = '<span style="font-family:' + fontoptions[n] + '">' + fontoptions[n] + '</span>';
			option.className = 'ofont';
			option.style.textAlign = 'left';
			option.style.verticalAlign = 'middle';
			option.style.height = '20px';
			option.title = fontoptions[n];
			option.cmd = obj.cmd;
			option.controlkey = obj.id;
			option.editorid = this.editorid;
			option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = phpbb_Text_Editor_Events.prototype.menuoption_onmouseevent;
			option.onclick = phpbb_Text_Editor_Events.prototype.formatting_option_onclick;
			menu.appendChild(option);
		}
	}

	/**
	* Build Font Size Popup Contents
	*
	* @param	object	The control object for the menu
	* @param	object	The menu container object
	*/
	this.build_fontsize_popup = function(obj, menu)
	{
		for (var n in sizeoptions)
		{
			var option = document.createElement('div');
			option.innerHTML = '<span style="font-family:verdana;font-size:' + sizeoptions[n] + 'px">' + sizeoptions[n] + '</span>';
			option.className = 'osize';
			option.style.textAlign = 'center';
			option.title = sizeoptions[n];
			option.cmd = obj.cmd;
			option.controlkey = obj.id;
			option.editorid = this.editorid;
			option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = phpbb_Text_Editor_Events.prototype.menuoption_onmouseevent;
			option.onclick = phpbb_Text_Editor_Events.prototype.formatting_option_onclick;
			menu.appendChild(option);
		}
	}

	/**
	* Build ForeColor Popup Contents
	*
	* @param	object	The control object for the menu
	* @param	object	The menu container object
	*/
	this.build_forecolor_popup = function(obj, menu)
	{
		var colorout = fetch_object(this.editorid + '_color_out');
		colorout.editorid = this.editorid;
		colorout.onclick = phpbb_Text_Editor_Events.prototype.colorout_onclick;

		var table = document.createElement('table');
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.border = 0;

		var i = 0;
		for (var hex in coloroptions)
		{
			if (i % 12 == 0)
			{
				var tr = table.insertRow(-1);
			}
			i++;

			var div = document.createElement('div');
			div.style.backgroundColor = hex;

			var option = tr.insertCell(-1);
			option.style.textAlign = 'center';
			option.className = 'ocolor';
			option.appendChild(div);
			option.cmd = obj.cmd;
			option.editorid = this.editorid;
			option.controlkey = obj.id;
			option.title = coloroptions[hex];
			option.colorhex = hex;
			option.id = this.editorid + '_color_' + coloroptions[hex];
			option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = phpbb_Text_Editor_Events.prototype.menuoption_onmouseevent;
			option.onclick = phpbb_Text_Editor_Events.prototype.color_option_onclick;
		}

		menu.appendChild(table);
	}
	
	this.build_spellcheck_popup = function(obj, menu)
	{
		for (var n in spellcheckoptions)
		{
			var option = document.createElement('div');
			option.innerHTML = '<span id="spellcheck_'+n+'" style="font:'+((GOOGIE_CUR_LANG == n) ? "bold" : "normal")+' 12px verdana">' + spellcheckoptions[n] + '</span>';
			option.className = 'ospellchecklang';
			option.style.textAlign = 'center';
			option.title = spellcheckoptions[n];
			option.cmd = obj.cmd;
			option.spellchecklang = n;
			option.controlkey = obj.id;
			option.editorid = this.editorid;
			option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = phpbb_Text_Editor_Events.prototype.menuoption_onmouseevent;
			option.onclick = phpbb_Text_Editor_Events.prototype.spellcheck_option_onclick;
			menu.appendChild(option);
		}
		
	}


	/**
	* Menu Context
	*
	* @param	object	The menu container object
	* @param	string	The state of the control
	*/
	this.menu_context = function(obj, state)
	{
		if (this.disabled)
		{
			return;
		}

		switch (obj.state)
		{
			case true: // selected menu is open
			{
				this.set_control_style(obj, 'button', 'down');
				break;
			}

			default:
			{
				switch (state)
				{
					case 'mouseout':
					{
						this.set_control_style(obj, 'button', 'normal');
						break;
					}
					case 'mousedown':
					{
						this.set_control_style(obj, 'popup', 'down');
						break;
					}
					case 'mouseup':
					case 'mouseover':
					{
						this.set_control_style(obj, 'button', 'hover');
						break;
					}
				}
			}
		}
	};

	/**
	* Button Context
	*
	* @param	object	The button object
	* @param	string	Incoming event type
	* @param	string	Control type - 'button' or 'menu'
	*/
	this.button_context = function(obj, state, controltype)
	{
		if (this.disabled)
		{
			return;
		}

		if (typeof controltype == 'undefined')
		{
			controltype = 'button';
		}

		switch (obj.state)
		{
			case true: // selected button
			{
				switch (state)
				{
					case 'mouseover':
					case 'mousedown':
					case 'mouseup':
					{
						this.set_control_style(obj, controltype, 'down');
						break;
					}
					case 'mouseout':
					{
						this.set_control_style(obj, 'button', 'selected');
						break;
					}
				}
				break;
			}

			default: // not selected
			{
				switch (state)
				{
					case 'mouseover':
					case 'mouseup':
					{
						this.set_control_style(obj, controltype, 'hover');
						break;
					}
					case 'mousedown':
					{
						this.set_control_style(obj, controltype, 'down');
						break;
					}
					case 'mouseout':
					{
						this.set_control_style(obj, controltype, 'normal');
						break;
					}
				}
				break;
			}
		}
	};

	/**
	* Set Control Style
	*
	* @param	object	The object to be styled
	* @param	string	Control type - 'button' or 'menu'
	* @param	string	The mode to use, corresponding to the istyles array
	*/
	this.set_control_style = function(obj, controltype, mode)
	{
		if (obj.mode != mode)
		{
			obj.mode = mode;

			// construct the name of the appropriate array key from the istyles array
			istyle = 'pi_' + controltype + '_' + obj.mode;

			// set element background, color, padding and border
			if (typeof istyles != 'undefined' && typeof istyles[istyle] != 'undefined')
			{
				obj.style.background = istyles[istyle][0];
				obj.style.color = istyles[istyle][1];
				if (controltype != 'menu')
				{
					obj.style.padding = istyles[istyle][2];
				}
				obj.style.border = istyles[istyle][3];

				var tds = fetch_tags(obj, 'td');
				for (var i = 0; i < tds.length; i++)
				{
					switch (tds[i].className)
					{
						// set the right-border for popup_feedback class elements
						case 'popup_feedback':
						{
							tds[i].style.borderRight = (mode == 'normal' ? istyles['pi_menu_normal'][3] : istyles[istyle][3]);
						}
						break;

						// set the border colour for popup_pickbutton class elements
						case 'popup_pickbutton':
						{
							tds[i].style.borderColor = (mode == 'normal' ? istyles['pi_menu_normal'][0] : istyles[istyle][0]);
						}
						break;

						// set the left-padding and left-border for alt_pickbutton elements
						case 'alt_pickbutton':
						{
							if (obj.state)
							{
								tds[i].style.paddingLeft = istyles['pi_button_normal'][2];
								tds[i].style.borderLeft = istyles['pi_button_normal'][3];
							}
							else
							{
								tds[i].style.paddingLeft = istyles[istyle][2];
								tds[i].style.borderLeft = istyles[istyle][3];
							}
						}
					}
				}
			}
		}
	};

	/**
	* Format text
	*
	* @param	event	Event object
	* @param	string	Formatting command
	* @param	string	Optional argument to the formatting command
	*
	* @return	boolean
	*/
	this.format = function(e, cmd, arg)
	{
		e = do_an_e(e);

		if (this.disabled)
		{
			return false;
		}
		
		if(GOOGIE_SPELLCHECK_MODE)
		{
			return false;
		}

		if (cmd != 'redo')
		{
			this.history.add_snapshot(this.get_editor_contents());
		}

		if (cmd == 'switchmode')
		{
			switch_editor_mode(this.editorid);
			return;
		}
		else if (cmd.substr(0, 6) == 'resize')
		{
			this.resize_editor(parseInt(cmd.substr(9), 10) * (parseInt(cmd.substr(7, 1), 10) == '1' ? 1 : -1));
			return;
		}

		this.check_focus();

		if (cmd.substr(0, 4) == 'wrap')
		{
			var ret = this.wrap_tags(cmd.substr(6), (cmd.substr(4, 1) == '1' ? true : false));
		}
		else if (this[cmd])
		{
			var ret = this[cmd](e);
		}
		else
		{
			try
			{
				var ret = this.apply_format(cmd, false, (typeof arg == 'undefined' ? true : arg));
			}
			catch(e)
			{
				this.handle_error(cmd, e);
				var ret = false;
			}
		}

		if (cmd != 'undo')
		{
			this.history.add_snapshot(this.get_editor_contents());
		}

		this.set_context(cmd);

		this.check_focus();

		return ret;
	};

	/**
	* Insert Image
	*
	* @param	event	Event object
	* @param	string	(Optional) Image URL
	*
	* @return	boolean
	*/
	this.insertimage = function(e, img)
	{
		if (typeof img == 'undefined')
		{
			img = this.show_prompt(phpbbphrase['enter_image_url'], 'http://');
		}
		if (img = this.verify_prompt(img))
		{
			return this.apply_format('insertimage', false, img);
		}
		else
		{
			return false;
		}
	};

	/**
	* Wrap Tags
	*
	* @param	string	Tag to wrap
	* @param	boolean	Use option?
	* @param	string	(Optional) selected text
	*
	* @return	boolean
	*/
	this.wrap_tags = function(tagname, useoption, selection)
	{
		tagname = tagname.toUpperCase();

		switch (tagname)
		{
			case 'CODE':
			case 'HTML':
			case 'PHP':
			case 'SPOILER':
			{
				this.apply_format('removeformat');
			}
			break;
		}

		if (typeof selection == 'undefined')
		{
			selection = this.get_selection();
			if (selection === false)
			{
				selection = '';
			}
			else
			{
				selection = new String(selection);
			}
		}

		if (useoption === true)
		{
			var option = this.show_prompt(construct_phrase(phpbbphrase['enter_tag_option'], ('[' + tagname + ']')), '');
			if (option = this.verify_prompt(option))
			{
				var opentag = '[' + tagname + '=' + option + '' + ']';
			}
			else
			{
				return false;
			}
		}
		else if (useoption !== false)
		{
			var opentag = '[' + tagname + '=' + useoption + '' + ']';
		}
		else
		{
			var opentag = '[' + tagname + ']';
		}

		var closetag = '[/' + tagname + ']';
		var text = opentag + selection + closetag;

		this.insert_text(text, opentag.phpbblength(), closetag.phpbblength());

		return false;
	};
	

	/**
	* Handle Error
	*
	* @param	string	Command name
	* @param	event	Event object
	*/
	this.handle_error = function(cmd, e)
	{
	};

	/**
	* Show JS Prompt and filter result
	*
	* @param	string	Text for the dialog
	* @param	string	Default value for the dialog
	*
	* @return	string
	*/
	this.show_prompt = function(dialogtxt, defaultval)
	{
		return PHP.trim(new String(prompt(dialogtxt, defaultval)));
	};

	/**
	* Verify the return value of a javascript prompt
	*
	* @param	string	String to be checked
	*
	* @return	mixed	False on fail, string on success
	*/
	this.verify_prompt = function(str)
	{
		switch(str)
		{
			case 'http://':
			case 'null':
			case 'undefined':
			case 'false':
			case '':
			case null:
			case false:
				return false;

			default:
				return str;
		}
	};



	/**
	* Resize Editor
	*
	* @param	integer	Number of pixels by which to resize the editor
	*/
	this.resize_editor = function(change)
	{
		var newheight = parseInt(this.editbox.style.height, 10) + change;

		if (newheight >= 100)
		{
			this.editbox.style.height = newheight + 'px';

			// remember the setting for next time
			if (change % 99 != 0)
			{
				var expires = new Date(); 
				expires.setTime( expires.getTime() + (86400000 * 365) );
				set_cookie('editor_height', newheight,expires,cookie_path,cookie_domain);
			}
		}
	};

	/**
	* Destroy Popup
	*/
	this.destroy_popup = function(popupname)
	{
		this.popups[popupname].parentNode.removeChild(this.popups[popupname]);
		this.popups[popupname] = null;
	}

	/**
	* Destroy Editor
	*/
	this.destroy = function()
	{
		// reset all buttons to default state
		for (var i in this.buttons)
		{
			this.set_control_style(this.buttons[i], 'button', 'normal');
		}

		// destroy popups
		for (var menu in this.popups)
		{
			this.destroy_popup(menu);
		}

		if (this.fontoptions)
		{
			for (var i in this.fontoptions)
			{
				if (i != '')
				{
					this.fontoptions[i].parentNode.removeChild(this.fontoptions[i]);
				}
			}
			this.fontoptions[''].style.display = '';
		}

		if (this.sizeoptions)
		{
			for (var i in this.sizeoptions)
			{
				if (i != '')
				{
					this.sizeoptions[i].parentNode.removeChild(this.sizeoptions[i]);
				}
			}
			this.sizeoptions[''].style.display = '';
		}
	};

	this.disable_editor = function(text)
	{
		if (typeof text != 'undefined')
		{
			this.editbox.value = text;
		}
		this.editbox.disabled = true;

		this.disabled = true;
	};

	this.enable_editor = function(text)
	{
		if (typeof text != 'undefined')
		{
			this.editbox.value = text;
		}
		this.editbox.disabled = false;

		this.disabled = false;
	};

	/**
	* Writes contents to the <textarea>
	*
	* @param	object	<textarea>
	* @param	string	Initial text
	*/
	this.write_editor_contents = function(text)
	{
		this.textobj.value = text;
	}

	/**
	* Put the text into the editor
	*/
	this.set_editor_contents = function(initial_text)
	{
		var iframe = this.textobj.parentNode.getElementsByTagName('iframe')[0];
		if (iframe)
		{
			this.textobj.style.display = '';
			this.textobj.style.width = iframe.style.width;
			this.textobj.style.height = iframe.style.height;

			iframe.style.width = '0px';
			iframe.style.height = '0px';
			iframe.style.border = 'none';
		}

		this.editwin = this.textobj;
		this.editdoc = this.textobj;
		this.editbox = this.textobj;
		this.spellobj = this.textobj;

		if (typeof initial_text != 'undefined')
		{
			this.write_editor_contents(initial_text);
		}

		this.editdoc.editorid = this.editorid;
		this.editwin.editorid = this.editorid;

		this.history.add_snapshot(this.get_editor_contents());
	};

	/**
	* Set the CSS style of the editor
	*/
	this.set_editor_style = function()
	{
	};

	/**
	* Init Editor Functions
	*/
	this.set_editor_functions = function()
	{
		if (this.editdoc.addEventListener)
		{
			this.editdoc.addEventListener('keypress', phpbb_Text_Editor_Events.prototype.editdoc_onkeypress, false);
		}

		this.editwin.onfocus = phpbb_Text_Editor_Events.prototype.editwin_onfocus;
		this.editwin.onblur = phpbb_Text_Editor_Events.prototype.editwin_onblur;
	};

	/**
	* Set Context
	*/
	this.set_context = function()
	{
	};

	/**
	* Apply formatting
	*/
	this.apply_format = function(cmd, dialog, argument)
	{
		switch (cmd)
		{
			case 'bold':
			case 'italic':
			case 'underline':
			case 'strike':
			{
				this.wrap_tags(cmd.substr(0, 1), false);
				return;
			}

			case 'justifyleft':
			case 'justifycenter':
			case 'justifyjustify':
			case 'justifyright':
			{
				this.wrap_tags(cmd.substr(7), false);
				return;
			}

			case 'indent':
			{
				this.wrap_tags(cmd, false);
				return;
			}

			case 'fontname':
			{
				this.wrap_tags('font', argument);
				return;
			}

			case 'fontsize':
			{
				this.wrap_tags('size', argument);
				return;
			}

			case 'forecolor':
			{
				this.wrap_tags('color', argument);
				return;
			}
			
			case 'spellcheck':
			{
				this.wrap_tags('spell', argument);
				return;
			}

			case 'createlink':
			{
				var sel = this.get_selection();
				if (sel)
				{
					this.wrap_tags('url', argument);
				}
				else
				{
					this.wrap_tags('url', argument, argument);
				}
				return;
			}

			case 'insertimage':
			{
				this.wrap_tags('img', false, argument);
				return;
			}

			case 'removeformat':
			{
					return;
			}
			
			default:
			{
				if(cmd !== 'unlink') {
					this.wrap_tags(cmd, argument);
				}
				return;

			}
			

		}
	};

	this.undo = function()
	{
		this.history.add_snapshot(this.get_editor_contents());
		this.history.move_cursor(-1);
		if ((str = this.history.get_snapshot()) !== false)
		{
			this.editdoc.value = str;
		}
	};

	this.redo = function()
	{
		this.history.move_cursor(1);
		if ((str = this.history.get_snapshot()) !== false)
		{
			this.editdoc.value = str;
		}
	};

	/**
	* Strip a simple tag...
	*/
	this.strip_simple = function(tag, str, iterations)
	{
		var opentag = '[' + tag + ']';
		var closetag = '[/' + tag + ']';

		if (typeof iterations == 'undefined')
		{
			iterations = -1;
		}

		while ((startindex = PHP.stripos(str, opentag)) !== false && iterations != 0)
		{
			iterations --;
			if ((stopindex = PHP.stripos(str, closetag)) !== false)
			{
				var text = str.substr(startindex + opentag.length, stopindex - startindex - opentag.length);
				str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
			}
			else
			{
				break;
			}
		}

		return str;
	};

	/**
	* Strip a tag with an option
	*/
	this.strip_complex = function(tag, str, iterations)
	{
		var opentag = '[' + tag + '=';
		var closetag = '[/' + tag + ']';

		if (typeof iterations == 'undefined')
		{
			iterations = -1;
		}

		while ((startindex = PHP.stripos(str, opentag)) !== false && iterations != 0)
		{
			iterations --;
			if ((stopindex = PHP.stripos(str, closetag)) !== false)
			{
				var openend = PHP.stripos(str, ']', startindex);
				if (openend !== false && openend > startindex && openend < stopindex)
				{
					var text = str.substr(openend + 1, stopindex - openend - 1);
					str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
				}
				else
				{
					break;
				}
			}
			else
			{
				break;
			}
		}

		return str;
	};

	/**
	* Remove Formatting
	*/
	this.removeformat = function(e)
	{
		var simplestrip = new Array('b', 'bold', 'i', 'italic', 'u', 'underline', 's', 'strike', 'r', 'rainbow', 'sub', 'sup', 'left', 'right', 'center', 'justify');
		var complexstrip = new Array('font', 'color', 'size', 'align', 'move', 'marq');

		var str = this.get_selection();
		if (str === false)
		{
			return;
		}

		// simple stripper
		for (var tag in simplestrip)
		{
			str = this.strip_simple(simplestrip[tag], str);
		}

		// complex stripper
		for (var tag in complexstrip)
		{
			str = this.strip_complex(complexstrip[tag], str);
		}

		this.insert_text(str);
	};

	/**
	* Insert Link
	*/
	this.createlink = function(e, url)
	{
		this.prompt_link('url', url, phpbbphrase['enter_link_url'], 'http://');
	};

	/**
	* Remove Link
	*/
	this.unlink = function(e)
	{
		var sel = this.get_selection();
		sel = this.strip_simple('url', sel);
		sel = this.strip_complex('url', sel);
		this.insert_text(sel);
	};

	/**
	* Insert Email Link
	*/
	this.email = function(e, email)
	{
		this.prompt_link('email', email, phpbbphrase['enter_email_link'], '');
	};

	/**
	* Insert Smilie
	*/
	this.insert_smilie = function(e, smilietext)
	{
		this.check_focus();

		smilietext = ' ' + smilietext + ' ';

		return this.insert_text(smilietext, smilietext.length, 0);
	};

	/**
	* Wrapper for Link / Email Link insert
	*/
	this.prompt_link = function(tagname, value, phrase, iprompt)
	{
		if (typeof value == 'undefined')
		{
			value = this.show_prompt(phrase, iprompt);
		}
		if ((value = this.verify_prompt(value)) !== false)
		{
			if (this.get_selection())
			{
				this.apply_format('unlink');
				this.wrap_tags(tagname, value);
			}
			else
			{
				this.wrap_tags(tagname, value, value);
			}
		}
		return true;
	};

	/**
	* Insert Ordered List
	*/
	this.insertorderedlist = function(e)
	{
		this.insertlist(phpbbphrase['insert_ordered_list'], '1');
	};

	/**
	* Insert Unordered List
	*/
	this.insertunorderedlist = function(e)
	{
		this.insertlist(phpbbphrase['insert_unordered_list'], '');
	};

	/**
	* Insert List
	*/
	this.insertlist = function(phrase, listtype)
	{
		var opentag = '[LIST' + (listtype ? ('=' + listtype) : '') + ']\n';
		var closetag = '[/LIST]';

		if (txt = this.get_selection())
		{
			var regex = new RegExp('([\r\n]+|^[\r\n]*)(?!\\[\\*\\]|\\[\\/?list)(?=[^\r\n])', 'gi');
			txt = opentag + PHP.trim(txt).replace(regex, '$1[*]') + '\n' + closetag;
			this.insert_text(txt, txt.phpbblength(), 0);
		}
		else
		{
			this.insert_text(opentag + closetag, opentag.length, closetag.length);

			while (listvalue = prompt(phpbbphrase['enter_list_item'], ''))
			{
				listvalue = '[*]' + listvalue + '\n';
				this.insert_text(listvalue, listvalue.phpbblength(), 0);
			}
		}
	};

	/**
	* Outdent
	*/
	this.outdent = function(e)
	{
		var sel = this.get_selection();
		sel = this.strip_simple('indent', sel, 1);
		this.insert_text(sel);
	};

	/**
	* Get Editor Contents
	*/
	this.get_editor_contents = function()
	{
		return this.editdoc.value;
	};

	/**
	* Get Selected Text
	*/
	this.get_selection = function()
	{
		if (typeof(this.editdoc.selectionStart) != 'undefined')
		{
			return this.editdoc.value.substr(this.editdoc.selectionStart, this.editdoc.selectionEnd - this.editdoc.selectionStart);
		}
		else if (document.selection && document.selection.createRange)
		{
			return document.selection.createRange().text;
		}
		else if (window.getSelection)
		{
			return window.getSelection() + '';
		}
		else
		{
			return false;
		}
	};

	/**
	* Paste HTML
	*/
	this.insert_text = function(text, movestart, moveend)
	{
		this.check_focus();

		if (typeof(this.editdoc.selectionStart) != 'undefined')
		{
			var opn = this.editdoc.selectionStart + 0;

			this.editdoc.value = this.editdoc.value.substr(0, this.editdoc.selectionStart) + text + this.editdoc.value.substr(this.editdoc.selectionEnd);

			if (movestart === false)
			{
				// do nothing
			}
			else if (typeof movestart != 'undefined')
			{
				this.editdoc.selectionStart = opn + movestart;
				this.editdoc.selectionEnd = opn + text.phpbblength() - moveend;
			}
			else
			{
				this.editdoc.selectionStart = opn;
				this.editdoc.selectionEnd = opn + text.phpbblength();
			}
		}
		else if (document.selection && document.selection.createRange)
		{
			var sel = document.selection.createRange();
			sel.text = text.replace(/\r?\n/g, '\r\n');

			if (movestart === false)
			{
				// do nothing
			}
			else if (typeof movestart != 'undefined')
			{
				sel.moveStart('character', -text.phpbblength() +movestart);
				sel.moveEnd('character', -moveend);
			}
			else
			{
				sel.moveStart('character', -text.phpbblength());
			}
			sel.select();
		}
		else
		{
			// failed - just stuff it at the end of the message
			this.editdoc.value += text;
		}
	};

	/**
	* Prepare Form For Submit
	*/
	this.prepare_submit = function(subjecttext, minchars)
	{
		return validatemessage(this.textobj.value, subjecttext, minchars);
	}

	// =============================================================================
	// Safari / Old Opera Standard Editor Only
	// =============================================================================
	if (is_saf || (is_opera && (!opera.version || opera.version() < 8)))
	{
		/**
		* Insert List for Safari and older Opera
		*/
		this.insertlist = function(phrase, listtype)
		{
			var opentag = '[LIST' + (listtype ? ('=' + listtype) : '') + ']\n';
			var closetag = '[/LIST]';

			this.insert_text(opentag);

			while (listvalue = prompt(phpbbphrase['enter_list_item'], ''))
			{
				listvalue = '[*]' + listvalue + '\n';
				this.insert_text(listvalue);
			}

			this.insert_text(closetag);
		};
	}
	
	this.init();
}

// =============================================================================
// Editor event handler functions

/**
* Class containing editor event handlers
*/
function phpbb_Text_Editor_Events()
{
}

/**
* Handles a click on a smilie in the smiliebox
*/
phpbb_Text_Editor_Events.prototype.smilie_onclick = function(e)
{
	phpbb_Editor[this.editorid].insert_smilie(e,
		this.alt,
		this.src,
		this.id.substr(this.id.lastIndexOf('_') + 1)
	);

	if (typeof smilie_window != 'undefined' && !smilie_window.closed)
	{
		smilie_window.focus();
	}

	return false;
};

/**
* Handles a mouse event on a command button
*/
phpbb_Text_Editor_Events.prototype.command_button_onmouseevent = function(e)
{
	e = do_an_e(e);

	if (e.type == 'click')
	{
		phpbb_Editor[this.editorid].format(e, this.cmd, false, true);
	}

	phpbb_Editor[this.editorid].button_context(this, e.type);
};

/**
* Handles a mouse event on a popup controller button
*/
phpbb_Text_Editor_Events.prototype.popup_button_onmouseevent = function(e)
{
	e = do_an_e(e);

	if (e.type == 'click')
	{
		this._onclick(e);
		phpbb_Editor[this.editorid].menu_context(this, 'mouseover');
	}
	else
	{
		phpbb_Editor[this.editorid].menu_context(this, e.type);
	}
};

/**
* Overrides the show() function from the phpbbmenu system
*
* @param	object	Control object
* @param	boolean	Show instantly?
*/
phpbb_Text_Editor_Events.prototype.popup_button_show = function(obj, instant)
{
	if (typeof phpbb_Editor[obj.editorid].popups[obj.cmd] == 'undefined' || phpbb_Editor[obj.editorid].popups[obj.cmd] == null)
	{
		phpbb_Editor[obj.editorid].init_popup_menu(obj);
	}
	this._show(obj, instant);
};

/**
* Handles a selection from a formatting <select> menu
*/
phpbb_Text_Editor_Events.prototype.formatting_select_onchange = function(e)
{
	var arg = this.options[this.selectedIndex].value;
	if (arg != '')
	{
		phpbb_Editor[this.editorid].format(e, this.cmd, arg);
	}
	this.selectedIndex = 0;
};

/**
* Handles a selection from the smilies <select> menu
*/
phpbb_Text_Editor_Events.prototype.smilieselect_onchange = function(e)
{
	if (this.options[this.selectedIndex].value != '')
	{
		phpbb_Editor[this.editorid].insert_smilie(e,
			this.options[this.selectedIndex].value,
			this.options[this.selectedIndex].smiliepath,
			this.options[this.selectedIndex].smilieid
		);
	}
	this.selectedIndex = 0;
};


/**
* Handles a mouse event on a menu option
*/
phpbb_Text_Editor_Events.prototype.menuoption_onmouseevent = function(e)
{
	e = do_an_e(e);
	phpbb_Editor[this.editorid].button_context(this, e.type, 'menu');
};

/**
* Handles a click on a formatting option in the font/size menus
*/
phpbb_Text_Editor_Events.prototype.formatting_option_onclick = function(e)
{
	phpbb_Editor[this.editorid].format(e, this.cmd, this.firstChild.innerHTML);
	phpbbmenu.hide();
};

/**
* Handles a click on a color option in the color menu
*/
phpbb_Text_Editor_Events.prototype.color_option_onclick = function(e)
{
	fetch_object(this.editorid + '_color_bar').style.backgroundColor = this.colorhex;
	phpbb_Editor[this.editorid].format(e, this.cmd, this.colorhex);
	phpbbmenu.hide();
};

/**
* Handles a click on the color instant-select button
*/
phpbb_Text_Editor_Events.prototype.colorout_onclick = function(e)
{
	e = do_an_e(e);
	phpbb_Editor[this.editorid].format(e, 'forecolor', fetch_object(this.editorid + '_color_bar').style.backgroundColor);
	return false;
};


/**
* Handles a click on a spellcheck option in the specllcheck menu
*/
phpbb_Text_Editor_Events.prototype.spellcheck_option_onclick = function(e)
{
	
	fetch_object('spellcheck_'+GOOGIE_CUR_LANG).style.font = "normal 12px verdana";
	this.firstChild.style.font="bold 12px verdana";
	if(GoogieSpell.prototype.setCurrentLanguage)
	GoogieSpell.prototype.setCurrentLanguage(this.spellchecklang);
	else alert('Fehler: GoogieSpell wurde nicht korrekt eingebaut.');
	phpbbmenu.hide();
};


/**
* Sets editwin.hasfocus = true on focus
*/
phpbb_Text_Editor_Events.prototype.editwin_onfocus = function(e)
{
	this.hasfocus = true;
};

/**
* Sets editwin.hasfocus = false on blur
*/
phpbb_Text_Editor_Events.prototype.editwin_onblur = function(e)
{
	this.hasfocus = false;
};

/**
* Sets context and hides menus on mouse clicks in the editor
*/
phpbb_Text_Editor_Events.prototype.editdoc_onmouseup = function(e)
{
	phpbb_Editor[this.editorid].set_context();
	if (phpbb_Editor[this.editorid].popupmode)
	{
		phpbbmenu.hide();
	}
};

/**
* Sets context on key presses in the editor
*/
phpbb_Text_Editor_Events.prototype.editdoc_onkeyup = function(e)
{
	phpbb_Editor[this.editorid].set_context();
};

/**
* Handle a keypress event in the editor window
*/
phpbb_Text_Editor_Events.prototype.editdoc_onkeypress = function(e)
{
	if (e.ctrlKey)
	{
		switch (String.fromCharCode(e.charCode).toLowerCase())
		{
			case 'b': cmd = 'bold'; break;
			case 'i': cmd = 'italic'; break;
			case 'u': cmd = 'underline'; break;
			case 's': cmd = 'strike'; break;
			default: return;
		}

		e.preventDefault();
		phpbb_Editor[this.editorid].apply_format(cmd, false, null);
		return false;
	}
	else if (e.keyCode == 9)
	{
		// first lets try post icon, then submit, then just let it proceed making the tab
		var firsticon = fetch_object('rb_iconid_0');
		if (firsticon != null)
		{
			firsticon.focus();
		}
		else if (fetch_object(this.editorid + '_save') != null)
		{
			fetch_object(this.editorid + '_save').focus();
		}
		else if (fetch_object('qr_submit') != null)
		{
			fetch_object('qr_submit').focus();
		}
		else
		{
			return;
		}
		e.preventDefault();
	}
};

/**
* Stop resizing of images in IE
*/
phpbb_Text_Editor_Events.prototype.editdoc_onresizestart = function(e)
{
	if (e.srcElement.tagName == 'IMG')
	{
		return false;
	}
};

/**
* Save editor contents to textarea so if we hit back / forward its not lost
* Only appears to work with Firefox at the moment
*/
function save_iframe_to_textarea()
{
	for (var editorid in phpbb_Editor)
	{
		if (phpbb_Editor[editorid].wysiwyg_mode && phpbb_Editor[editorid].initialized)
		{
			phpbb_Editor[editorid].textobj.value = phpbb_Editor[editorid].get_editor_contents();
		}
	}
}

if (window.attachEvent)
{
	window.attachEvent('onbeforeunload', save_iframe_to_textarea);
}
else if(window.addEventListener)
{
	window.addEventListener('unload', save_iframe_to_textarea, true);
}



// #############################################################################
// Generic global editor variables

/**
* Define which buttons are context-controlled
*
* @var	array	Context controls
*/
var contextcontrols = new Array(
	'bold',
	'italic',
	'underline',
	'strike',
	'justifyleft',
	'justifycenter',
	'justifyjustify',
	'justifyright',
	'insertorderedlist',
	'insertunorderedlist'
);

var spellcheckoptions = new Array();
spellcheckoptions = {"da": "Dansk", "de": "Deutsch", "en": "English",
                       "es": "Espa&#241;ol", "fr": "Fran&#231;ais", "it": "Italiano", 
                       "nl": "Nederlands", "pl": "Polski", "pt": "Portugu&#234;s",
                       "fi": "Suomi", "sv": "Svenska"};


/**
* Define available color name options - keyed with hex value
*
* @var	array	Color options
*/
var coloroptions = new Array();
coloroptions = {
'#000000' : 'black',
'#FFFAFA' : 'snow', 
'#F8F8FF' : 'ghostwhite', 
'#F0F8FF' : 'aliceblue', 
'#FFFAF0' : 'floralwhite', 
'#FFF0F5' : 'lavenderblush', 
'#FFF5EE' : 'seashell', 
'#F5FFFA' : 'mintcream', 
'#F0FFFF' : 'azure', 
'#F0FFF0' : 'honeydew', 
'#FDF5E6' : 'oldlace', 
'#FAF0E6' : 'linen', 
'#F5F5F5' : 'whitesmoke', 
'#E6E6FA' : 'lavender', 
'#FFFFE0' : 'lightyellow', 
'#FFFACD' : 'lemonchiffon', 
'#FAFAD2' : 'lightgoldenrodyellow', 
'#FFF8DC' : 'cornsilk', 
'#FAEBD7' : 'antiquewhite', 
'#FFEFD5' : 'papayawhip', 
'#FFE4B5' : 'moccasin', 
'#FFDEAD' : 'navajowhite', 
'#F5DEB3' : 'wheat', 
'#D2B48C' : 'tan', 
'#DEB887' : 'burlywood', 
'#CD853F' : 'peru', 
'#F4A460' : 'sandybrown', 
'#D2691E' : 'chocolate', 
'#A0522D' : 'sienna', 
'#8B4513' : 'saddlebrown', 
'#E0FFFF' : 'lightcyan', 
'#ADD8E6' : 'lightblue', 
'#B0C4DE' : 'lightsteelblue', 
'#4682B4' : 'steelblue', 
'#7FFFD4' : 'aquamarine', 
'#00CED1' : 'darkturquoise', 
'#40E0D0' : 'turquoise', 
'#48D1CC' : 'mediumturquoise', 
'#66CDAA' : 'mediumaquamarine', 
'#8FBC8F' : 'darkseagreen', 
'#20B2AA' : 'lightseagreen', 
'#5F9EA0' : 'cadetblue', 
'#008B8B' : 'darkcyan', 
'#2F4F4F' : 'darkslategray', 
'#AFEEEE' : 'paleturquoise', 
'#B0E0E6' : 'powderblue', 
'#87CEEB' : 'skyblue', 
'#87CEFA' : 'lightskyblue', 
'#00BFFF' : 'deepskyblue', 
'#6495ED' : 'cornflowerblue', 
'#1E90FF' : 'dodgerblue', 
'#4169E1' : 'royalblue', 
'#0000CD' : 'mediumblue', 
'#00008B' : 'darkblue', 
'#191970' : 'midnightblue', 
'#7B68EE' : 'mediumslateblue', 
'#6A5ACD' : 'slateblue', 
'#483D8B' : 'darkslateblue', 
'#F5F5DC' : 'beige', 
'#EEE8AA' : 'palegoldenrod', 
'#F0E68C' : 'khaki', 
'#BDB76B' : 'darkkhaki', 
'#00FF7F' : 'springgreen', 
'#00FA9A' : 'mediumspringgreen', 
'#98FB98' : 'palegreen', 
'#90EE90' : 'lightgreen', 
'#ADFF2F' : 'greenyellow', 
'#7CFC00' : 'lawngreen', 
'#7FFF00' : 'chartreuse', 
'#9ACD32' : 'yellowgreen', 
'#32CD32' : 'limegreen', 
'#3CB371' : 'mediumseagreen', 
'#2E8B57' : 'seagreen', 
'#228B22' : 'forestgreen', 
'#6B8E23' : 'olivedrab', 
'#556B2F' : 'darkolivegreen', 
'#006400' : 'darkgreen', 
'#FFDAB9' : 'peachpuff', 
'#FFA07A' : 'lightsalmon', 
'#FA8072' : 'salmon', 
'#E9967A' : 'darksalmon', 
'#F08080' : 'lightcoral', 
'#CD5C5C' : 'indianred', 
'#FF7F50' : 'coral', 
'#FF6347' : 'tomato', 
'#FF4500' : 'orangered', 
'#DC143C' : 'crimson', 
'#B22222' : 'firebrick', 
'#A52A2A' : 'brown', 
'#8B0000' : 'darkred', 
'#FFA500' : 'orange', 
'#FF8C00' : 'darkorange', 
'#FFD700' : 'gold', 
'#DAA520' : 'goldenrod', 
'#B8860B' : 'darkgoldenrod', 
'#DCDCDC' : 'gainsboro', 
'#D3D3D3' : 'lightgrey', 
'#A9A9A9' : 'darkgray', 
'#778899' : 'lightslategray', 
'#708090' : 'slategray', 
'#696969' : 'dimgray', 
'#FFB6C1' : 'lightpink', 
'#BC8F8F' : 'rosybrown', 
'#FF69B4' : 'hotpink', 
'#DB7093' : 'palevioletred', 
'#FF1493' : 'deeppink', 
'#D8BFD8' : 'thistle', 
'#EE82EE' : 'violet', 
'#BA55D3' : 'mediumorchid', 
'#8B008B' : 'darkmagenta', 
'#8A2BE2' : 'blueviolet', 
'#9400D3' : 'darkviolet', 
'#9932CC' : 'darkorchid', 
'#9370DB' : 'mediumpurple', 
'#4B0082' : 'indigo', 
'#FFE4E1' : 'mistyrose', 
'#FFC0CB' : 'pink', 
'#DDA0DD' : 'plum', 
'#DA70D6' : 'orchid', 
'#C71585' : 'mediumvioletred'
};
/*
	var r = 0, g = 0, b = 0, col=0;
	var numberList = new Array(7);
	numberList[0] = "00";
	numberList[1] = "33";
	numberList[2] = "66";
	numberList[3] = "99";
	numberList[4] = "CC";
	numberList[5] = "FF";

	for(r = 0; r < 6; r++)
	{
		for(g = 0; g < 6; g++)
		{
			for(b = 0; b < 6; b++)
			{
				color = '#' + String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
				coloroptions[color] = color;
				col++;
			}
		}
	}
*/
var fontoptions = new Array("Arial", "Arial Black", "Arial Narrow", "Book Antiqua", "Century Gothic", "Comic Sans MS", "Courier New", "Fixedsys", "Franklin Gothic Medium", "Garamond", "Georgia", "Impact", "Lucida Console", "Lucida Sans Unicode", "Microsoft Sans Serif", "Palatino Linotype", "System", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana");
var sizeoptions = new Array(10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36);
var smilieoptions = new Array(); smilieoptions = { 'Standard Smilies' : {} };

var istyles = new Array(); 
		istyles = { 
		"pi_button_down" : [ "#FFF3C3", "#333333", "0px", "1px groove #666666" ], 
		"pi_button_hover" : [ "#FFECA1", "#222222", "0px", "1px solid #666666" ], 
		"pi_button_normal" : [ "#FFBA79", "#000", "0", "1px solid #666666" ], 
		"pi_button_selected" : [ "#FFF3C3", "#333333", "0px", "1px groove #666666" ], 
		"pi_menu_down" : [ "#FFF3C3", "#333333", "0px", "1px groove #666666" ], 
		"pi_menu_hover" : [ "#FFECA1", "#222222", "0px", "1px solid #666666" ], 
		"pi_menu_normal" : [ "#FFBA79", "#222222", "0px", "1px solid #666666" ], 
		"pi_popup_down" : [ "#FFF3C3", "#333333", "0px", "1px groove #666666" ]
		};


var smiliewindow_x = 240;
var smiliewindow_y = 280;

var ignorequotechars = 1;

// #############################################################################
// phpbb_History
// #############################################################################

function phpbb_History()
{
	this.cursor = -1;
	this.stack = new Array();
}

// =============================================================================
// phpbb_History methods

phpbb_History.prototype.move_cursor = function(increment)
{
	var test = this.cursor + increment;
	if (test >= 0 && this.stack[test] != null && typeof this.stack[test] != 'undefined')
	{
		this.cursor += increment;
	}
};

phpbb_History.prototype.add_snapshot = function(str)
{
	if (this.stack[this.cursor] == str)
	{
		return;
	}
	else
	{
		this.cursor++;
		this.stack[this.cursor] = str;

		if (typeof this.stack[this.cursor + 1] != 'undefined')
		{
			this.stack[this.cursor + 1] = null;
		}
	}
};

phpbb_History.prototype.get_snapshot = function()
{
	if (typeof this.stack[this.cursor] != 'undefined' && this.stack[this.cursor] != null)
	{
		return this.stack[this.cursor];
	}
	else
	{
		return false;
	}
};



