//Simple Richtext 
function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart && myField.selectionStart != '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue 
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}


function hrule(form)
	{insertAtCursor(document.form2.HtmlTextArea, "<hr size=\"1\">");}
	//{form2.HtmlTextArea.value= form2.HtmlTextArea.value+"<hr size=\"1\">";}

function underlineText(ul)
{
 var ulText=prompt("enter text", "");
	if (ulText !=null && ulText !="" && ulText !=" ")
	{
	insertAtCursor(document.form2.HtmlTextArea, '[u]'+ulText+'[/u]');}
	//document.form2.HtmlTextArea.value=document.form2.HtmlTextArea.value+" <u>"+ulText+"</u>"; }
}

function boldText(bt)
{
 var boldText=prompt("enter bold text", "");
	if (boldText !=null && boldText !="" && boldText !=" ")
	{
	insertAtCursor(document.form2.HtmlTextArea, '[b]'+boldText+'[/b]');}
	//document.form2.HtmlTextArea.value=document.form2.HtmlTextArea.value+" <b>"+boldText+"</b>"; }
}

function italicText(em)
{
 var italText=prompt("italicize text", "");
	if (italText !=null && italText !="" && italText !=" ")
	{
	insertAtCursor(document.form2.HtmlTextArea, '[i]'+italText+'[/i]');}
	//document.form2.HtmlTextArea.value=document.form2.HtmlTextArea.value+" <em>"+italText+"</em>"; }
}

function addLink(lt)
{
var urllink = prompt("Url for the link:", "http://");
var linktext = prompt("Text for the link:", "");
	if (linktext !=null && linktext !="" && linktext !=" " && urllink !=null && urllink !="" && urllink !="http://")
	{insertAtCursor(document.form2.HtmlTextArea, '[url='+urllink+']'+linktext+'[/url]');}
	//{ document.form2.HtmlTextArea.value=document.form2.HtmlTextArea.value+" <a href=\""+urllink+"\">"+linktext+"</a>";}
}

function addEmail(eml)
{
var mllink = prompt("Email Address:", "");
var linktext = prompt("Text for the link:", "");
	if (linktext !=null && linktext !="" && linktext !=" " && mllink !=null && mllink !="" && mllink !=" ")
	{insertAtCursor(document.form2.HtmlTextArea, '[url=mailto:'+mllink+']'+linktext+'[/url]');}
	//{ document.form2.HtmlTextArea.value=document.form2.HtmlTextArea.value+" <a href=\"mailto:"+mllink+"\">"+linktext+"</a>";}
}

function previewHTML(form) {
	var txt = form.HtmlTextArea.value;
	win = window.open(", ", 'popup', 'width=400,height=300,scrollbars=yes,toolbar = no, status = no');
	txt=txt.replace(/(\n)/gi, "<br>");
	win.document.write("" + txt + "");
}