var oTextBox;

function AddText(NewCode) 
{	
	if (oTextBox.createTextRange && oTextBox.caretPos) {
		var caretPos = oTextBox.caretPos;
		caretPos.text = NewCode;
	}
	else
	{
		if (oTextBox.selectionEnd >= 0 && oTextBox.setSelectionRange)
      { 
			var textLength = oTextBox.textLength; 
			var selStart = oTextBox.selectionStart;
			var selEnd = oTextBox.selectionEnd;
			var s1 = (oTextBox.value).substring(0, selStart); 
			var s2 = (oTextBox.value).substring(selEnd, textLength); 
			oTextBox.value = s1 + NewCode + s2;
			oTextBox.setSelectionRange(selStart + NewCode.length, selStart + NewCode.length); 
		}
		else
		{
			oTextBox.value += NewCode;
		}
	}
	oTextBox.focus();	
}

function storeCaret(ftext) 
{
	if (ftext.createTextRange) 
	{
		ftext.caretPos = document.selection.createRange().duplicate();
	}	
}

function getText() 
{
	if (oTextBox.createTextRange && oTextBox.caretPos) 
	{
		return oTextBox.caretPos.text;
	}
	else
	{
		if (oTextBox.selectionEnd && (oTextBox.selectionStart | oTextBox.selectionStart == 0)) 
		{ 
	      return oTextBox.value.slice(oTextBox.selectionStart, oTextBox.selectionEnd);
		}
		else
		{
			return '';
		}
   } 
}

function insertsmilie(smilieface) 
{
   AddText(smilieface);
}
                      
function bold() 
{
	var text = getText();
	AddTxt="[b]" + text + "[/b]";
	AddText(AddTxt);
}

function italicize() 
{
	var text = getText();
	AddTxt="[i]" + text + "[/i]";
	AddText(AddTxt);
}

function underline() 
{
	var text = getText();
	AddTxt="[u]" + text + "[/u]";
	AddText(AddTxt);
}

function strike() 
{
	var text = getText();
	AddTxt="[s]" + text + "[/s]";
	AddText(AddTxt);	
}

function left() 
{
	var text = getText();
	AddTxt="[left]" + text + "[/left]";
	AddText(AddTxt);
}

function center() 
{
	var text = getText();
	AddTxt="[center]" + text + "[/center]";
	AddText(AddTxt);
}

function right() 
{
	var text = getText();
	AddTxt="[right]" + text + "[/right]";
	AddText(AddTxt);
}

function hr() 
{
	var text = getText();
	AddTxt="[hr]" + text;
	AddText(AddTxt);
}

function hyperlink() 
{
	var text = getText();
	AddTxt="[url]" + text + "[/url]";
	AddText(AddTxt);
}