	function storeCaret(_input) {
		if (typeof (_input.createTextRange) != "undefined") {
			_input._caretPos = document.selection.createRange().duplicate();
		}
	}

	function fmtTxt(_commentBoxID,_leftStr,_rightStr,_midStr) {
		_input = $(_commentBoxID);
		_input.focus();

		if ((typeof _input._caretPos != undefined) && (_input.createTextRange)) {
			// IE
			var _caretPos = _input._caretPos;
			_selection = ((_midStr == "") || (typeof _midStr == "undefined")) ? _caretPos.text : _midStr;

			var _length = _selection.length;
			var _bias = 0;
			if (_selection.charAt(_selection.length - 1) == " ") {
				// There a trailing space:
				_caretPos.text = (_leftStr + _selection.substring(0,(_selection.length - 1)) + _rightStr + " ");
				_bias = 1;
			} else {
				// No trailing space...
				_caretPos.text = (_leftStr + _selection + _rightStr);
			}

			if (_length == 0) {
				_caretPos.moveStart("character",(_rightStr.length * -1));
				_caretPos.moveEnd("character",(_rightStr.length * -1));
			} else {
				_caretPos.moveStart("character",((_rightStr.length + _length) * -1));
				_caretPos.moveEnd("character",((_rightStr.length + _bias) * -1));
			}
			_caretPos.select();
		} else if (typeof _input.selectionStart != undefined) {
			// FF
			var _begin = _input.value.substr(0,_input.selectionStart);
			var _selection;

			if ((_midStr == "") || (typeof _midStr == "undefined")) {
				_selection = _input.value.substr(_input.selectionStart,(_input.selectionEnd - _input.selectionStart));
			} else {
				_selection = _midStr;
			}

			var _end = _input.value.substr(_input.selectionEnd);
			var _newCursorPos = _input.selectionStart;
			var _scrollPos = _input.scrollTop;

			if (_selection.charAt(_selection.length - 1) == " ") {
				// There a trailing space:
				_selection = _selection.substring(0,(_selection.length - 1));
				_rightStr += " ";
			}
			_input.value = (_begin + _leftStr + _selection + _rightStr + _end);

			if (_input.setSelectionRange) {
				if (_selection.length == 0) {
					_input.setSelectionRange((_newCursorPos + _leftStr.length),(_newCursorPos + _leftStr.length));
				} else {
					_input.setSelectionRange((_newCursorPos + _leftStr.length),(_newCursorPos + _leftStr.length + _selection.length));
				}
				_input.focus();
			}
			_input.scrollTop = _scrollPos;
		} else {
			_input.value += (_leftStr + _rightStr);
			_input.focus();
		}
	}

	function fmtTxtURL(_commentBoxID) {
		var _input = $(_commentBoxID);
		var _insText = "";

		if ((typeof (_input._caretPos) != "undefined") && (_input.createTextRange)) {
			_insText = _input._caretPos.text;
		} else if (typeof (_input.selectionStart) != "undefined") {
			_insText = _input.value.substr(_input.selectionStart,(_input.selectionEnd - _input.selectionStart));
		}

		_url = prompt("Input the destination for this Link","http://");
		if ((_url != null) && (_url != "")) {
			_text = prompt("Input the Title of this Link",_insText);

			if ((_url.indexOf("http://") != 0) && (_url.indexOf("https://") != 0)) {
				_url = ("http://" + _url);
			}
			if (_text == "") {
				_text = _url;
			}
			if ((_url != "http://") && (_url != null) && (_url != "undefined")) {
				fmtTxt(_commentBoxID,"<a href=\"" + _url + "\" target=\"_blank\">","</a>",_text);
			}
		} else {
			_input.focus();
		}
	}

	function fmtTxtImage(_commentBoxID) {
		var _input = $(_commentBoxID);
		var _imgSrc = "";

		_imgSrc = prompt("Input the link where the image is hosted:","http://");
		if ((_imgSrc != null) && (_imgSrc != "")) {
			if ((_imgSrc.indexOf("http://") != 0) && (_imgSrc.indexOf("https://") != 0)) {
				_imgSrc = ("http://" + _imgSrc);
			}

			if ((_imgSrc != "http://") && (_imgSrc != null) && (_imgSrc != "undefined")) {
				fmtTxt(_commentBoxID,"<img src=\"","\" />",_imgSrc);
			}
		} else {
			_input.focus();
		}
	}

	function fmtTxtUnderline(_commentBoxID) {
		// Because nesting 3 sets of quotes in HTML is unpossible:
		fmtTxt(_commentBoxID,"<span style=\"text-decoration: underline;\">","</span>");
	}