
function insertTag(startTag,endTag,isImage)
{
	var d = document.form.body;
	var start,end;
	start = d.selectionStart;
	end = d.selectionEnd;
	if ((end > start) || isImage) 
	{
		selection=d.value.slice(start, end);
		before = d.value.substr(0,start);
		after = d.value.substr(end, d.value.length - end);
		d.value = before + startTag + selection + endTag + after;
		d.setSelectionRange(start, end + startTag.length + endTag.length);
	}
	else
	{
		d.setSelectionRange(start,end);
		d.focus();
	}
}

function bold()
{
	insertTag("<b>","</b>");
}
function italic()
{
	insertTag("<i>","</i>");
}
function blockquote()
{
	insertTag("<blockquote>","</blockquote>");
}
function link()
{
	var href="";
	href = prompt("URL:","");
	if (href!=null && href.length > 11 && href.substr(0,7) == "http://")
	{
		insertTag("<a href='" + href + "' target=_blank>","</a>");
	}
	else 
	{
		document.form.body.focus(); 
	}
}

function remoteImage()
{
	var href = prompt("Image URL:","");
	if (href!=null && href.length > 11 && href.substr(0,7) == "http://")
	{
		var align = prompt('Align left, right, or center?', 'right');
		var d = document.form.body;
		var imageLink;
		if (align=='center')
		{
			imageLink = "<div style='text-align:center'><img src='" + href + "' width=200 border=0></div>";
		}
		else
		{
			imageLink = "<img src='" + href + "' width=200 border=0 align=" + align + ">";
		}
		insertTag(imageLink, "", true);
	}
	else 
	{
		alert("Sorry, invalid URL.");
		document.form.body.focus(); 
	}
}	

