function InsertText(oText, sText)
{
/*
	if(oText.createTextRange && oText.caretPos)
	{
		var iPos = oText.caretPos;
		iPos.text = iPos.text.charAt(iPos.text.length - 1) == ' ' ? iPos.text + sText + ' ' : iPos.text + sText;
		oText.focus();
	}
	else
	{
		oText.value  += sText;
		oText.focus();
	}
*/
    AroundText(oText, sText, '')
}

function AroundText(oText, sOpen, sClose)
{
	var sSel = document.selection.createRange().text;
	if(!sSel)
	{
		oText.value += sOpen + sClose;
		oText.focus();
		return;
	}
	document.selection.createRange().text = sOpen + sSel + sClose;
	oText.focus();
}

function insertTag(field, tag)
{
    AroundText( field.parentNode.nextSibling, '<'+tag+'>', '</'+tag+'>' );
}

function makeLink(field)
{
    var sInput = prompt("Please enter a fully qualified URL to link to...", "http://"); 
    if(sInput)
    {
        target = ( sInput.substring(0,24) != 'http://www.aokevents.com')?' target="_aok/"':''; 
        AroundText(field.parentNode.nextSibling, '<a href="' + sInput + '"' + target + '>','</a>');
    }
}

function makeEmail(field)
{
    var sInput = prompt("Please enter an email address to link to...", "sales@aokevents.com");
    if(sInput)
    {
        AroundText(field.parentNode.nextSibling, '<a href="mailto:' + sInput + '">','</a>');
    }
}

function makeImage(field)
{
    var sInput = prompt("Please enter a fully qualified URL of the iamge you want to insert...", "http://"); 
    if(sInput)
    {
        InsertText(field.parentNode.nextSibling, '<img src="' + sInput + '" align="left" vspace="10" hspace="10" />');
    }
}

