

function insertAtcursor(myField, thetag) {


if(thetag === "Underline"){thetag = '<u></u>';tagCenter = 3; }
if(thetag === "Bold"){thetag = "<b></b>";tagCenter = 3;}
if(thetag === "Italic"){thetag = "<i></i>";tagCenter = 3;}
if(thetag === "BR"){thetag = "<br />";tagCenter = 6;}
if(thetag === "center"){thetag = "<center></center>";tagCenter = 8;}
if(thetag === "blockquote"){thetag = "<blockquote></blockquote>";tagCenter = 12;}
if(thetag === "P"){thetag = "<p></p>";tagCenter = 3;}
if(thetag === "HR"){thetag = "<hr />";tagCenter = 6;}
if(thetag === "Link"){thetag = '<a href="http://www.somebodyswebsite.com">somebodyswebsite</a>';tagCenter = 42; }


if (document.selection) {
myField.focus();

sel = document.selection.createRange();
sel.text = thetag;

myField.focus();

}


else if (myField.selectionStart || myField.selectionStart == '0') {



var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;

myField.value = myField.value.substring(0, startPos)+ thetag+ myField.value.substring(endPos, myField.value.length);
myField.focus();
myField.setSelectionRange(startPos+tagCenter,endPos+tagCenter);


} else {


myField.value += thetag+tagCenter;

}

}



