<!--

/// Custom code

var caret = new CaretControl();

function writeImgTag(code) {
	caret.input = document.getElementById("body");
	caret.InsertText(code);
}
function writeBBTag(code) {
	// Example "code" argument is: "[B][/B]"
	caret.input = document.getElementById("body");
	var selection = caret.GetSelection();
	var pos = caret.GetPosition();
	caret.SetSelection( code.substring(0, code.length/2) + selection + code.substring(code.length/2) );
	caret.SetSelectionRange(pos + code.length/2, pos + code.length/2 + selection.length);
}
function writeImageTag() {
	caret.input = document.getElementById("body");
	var url = window.prompt("Enter the URL of the image you want to display:", caret.GetSelection());
	if(url)
	{
		var selection = url;
		var pos = caret.GetPosition();
		caret.SetSelection("[IMG]"+selection+"[/IMG]");
		caret.SetPosition(pos + 11 + selection.length);
	}
}
function writeVideoTag() {
	caret.input = document.getElementById("body");
	var url = window.prompt("Enter the URL of the video you want to display:", caret.GetSelection());
	if(url)
	{
		var selection = url;
		var pos = caret.GetPosition();
		caret.SetSelection("[YOUTUBE]"+selection+"[/YOUTUBE]");
		caret.SetPosition(pos + 19 + selection.length);
	}
}
function writeURLTag() {
	var url = window.prompt("Enter the URL you want to link to:", "http://");
	if(url)
	{
		caret.input = document.getElementById("body");
		var selection = caret.GetSelection() ? caret.GetSelection() : url;
		var pos = caret.GetPosition();
		caret.SetSelection("[URL=\""+url+"\"]"+selection+"[/URL]");
		caret.SetSelectionRange(pos + 8 + url.length, pos + 8 + url.length + selection.length);
	}
}
function writeMailTag() {
	var url = window.prompt("Enter the E-mail address you want to add:", "");
	if(url)
	{
		caret.input = document.getElementById("body");
		var selection = caret.GetSelection() ? caret.GetSelection() : url;
		var pos = caret.GetPosition();
		caret.SetSelection("[MAIL=\""+url+"\"]"+selection+"[/MAIL]");
		caret.SetSelectionRange(pos + 9 + url.length, pos + 9 + url.length + selection.length);
	}
}
function writeListTag() {
		caret.input = document.getElementById("body");
		var selection = caret.GetSelection();
		var pos = caret.GetPosition();
		var list = "";
		if(selection.length > 0)
		{
			var items = selection.replace(/((\r?)\n)+/g, "\n").split("\n");
			for(var i = 0; i < items.length; i++)
				//if(items[i].length > 0)
					list += "\n[*]"+items[i]+"";
		}
		else list += "\n[*]";
		caret.SetSelection("");
		caret.SetSelection("[LIST]"+list+"\n[/LIST]");
		caret.SetPosition(pos + 6 + list.length);
		//var end = caret.input.value.lastIndexOf("[/LIST]", pos + list + 8);
		//caret.SetPosition(end - 1);
}

//-->