function AddText(text) {
	if (document.commentor.comment.createTextRange && document.commentor.comment.caretPos) {
		var caretPos = document.commentor.comment.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		setfocus();
	}else {
		document.commentor.comment.value  += text;
		setfocus();
	}
}


function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function setfocus() {
	document.commentor.comment.focus();
}


function bold() {
	txt=prompt("Please enter the text that should be bolded.","Text");
	if (txt!=null) {
		AddTxt="<b>"+txt+"</b>";
		AddText(AddTxt);
	}
}

function italicize() {
	txt=prompt("Please enter the text that should be italicised.","Text");
	if (txt!=null) {
		AddTxt="<i>"+txt+"</i>";
		AddText(AddTxt);
	}
}



function hyperlink() {
	txt2=prompt("What name should be shown?\nIf this Field is blank the URL would be visible",""); 
	if (txt2!=null)	{
		txt=prompt("Please enter the URL for the hyperlink.","http://");
		if (txt!=null)	{
			if (txt2=="") {
				AddTxt="<a href=\""+txt+"\">"+txt+"</a>";
				AddText(AddTxt);
			}else {
				AddTxt="<a href=\""+txt+"\">"+txt2+"</a>";
				AddText(AddTxt);
			}
		}
	}
}




function underline() {
	txt=prompt("Please enter the text that should be underlined.","Text");     
	if (txt!=null) {
		AddTxt="<u>"+txt+"</u>";
		AddText(AddTxt);
	}
}
