// array which holds the currently opened tags
var tags = new Array();

// currently selected text
var text = "";

// text which is to be added to the post
var AddTxt = "";

// form object that has to be used
var mesg_board = "";

function validatePost(tform, subjectVal, minLength, maxLength)
{
	return validatemessage(tform.message.value, tform.title.value, minLength, maxLength, tform);
}

function editInit()
{
	editor_init();
}

// function to initialize the editor
function editor_init()
{
	if (editor_loaded)
	{
		// editor is already loaded, don't try to load it again, as that would be bad m'kay.
		return;
	}

	mesg_board = document.forms.adpost;
}


function getActiveText()
{
	setfocus();
	if (!is_ie || (is_ie && !document.selection))
	{
		return false;
	}

	var sel = document.selection;
	var rng = sel.createRange();
	rng.colapse;
	if (rng != null && (sel.type == "Text" || sel.type == "None"))
	{
		text = rng.text;
	}
	if (mesg_board.message.createTextRange)
	{
		mesg_board.message.caretPos = rng.duplicate();
	}

	return true;
}

function AddText(NewCode)
{
	if (mesg_board.message.createTextRange && mesg_board.message.caretPos)
	{
		var caretPos = mesg_board.message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	}
	else
	{
		mesg_board.message.value += NewCode;
	}
	setfocus();
	getActiveText();
	AddTxt = "";
}

function setfocus()
{
	mesg_board.message.focus();
}

function closetag()
{
	getActiveText();
	setfocus();
}

function closeall()
{
	getActiveText();
	setfocus();
}

