﻿function InsertText(text) { 
	var obj = document.getElementById("posting_content");
	if (obj) 
	{ 
		obj.value += text + " ";  
		obj.focus(); 
	}  
	return false; 
}

function FormatText(tag) 
{
	var txtarea = document.getElementById("posting_content");

	if ((clientVer >= 4) && is_ie && is_win)
	{
		var theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = '[' + tag + ']' + theSelection + '[/' + tag + ']';
			txtarea.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, '[' + tag + ']', '[/' + tag + ']');
		return;
	}	
}

function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}
