function init() {
  // init global variables
  ta = document.getElementById("txaBody");

  if(ta.selectionStart != undefined) { // has support for DOM2 Ranging in textarea 
    ta.addEventListener("keypress", shortCuts, true); // add listener
  }
}

function shortCuts(evt) {
  if (evt.ctrlKey != true) return;
	if (evt.shiftKey != true) return;

  if(evt.charCode == 65 || evt.charCode == 97) ahrefThis();
  if(evt.charCode == 116 || evt.charCode == 84) italicThis();
	if(evt.charCode == 66 || evt.charCode == 98) boldThis();
  
  // didn't bother implementing the post and deleteMe stuff
}

function boldThis() {
  tag("b");
}

function italicThis(from) {
  tag("i");
}




function tag(tag) {
  start = ta.selectionStart;
  end = ta.selectionEnd;

  // Split before, sel, after and insert tags in between 
  
  before = (ta.value).substring(0, start);
  sel = (ta.value).substring(start, end);
  after = (ta.value).substring(end, ta.textLength);

  ta.value = before + "<" + tag + ">" + sel + "</" + tag + ">" + after;
  
  // focus
  ta.focus();
  ta.selectionStart = end + 5 + (tag.length * 2);
  ta.selectionEnd = ta.selectionStart; 
}

function ahrefThis() {
	var strHref = prompt("Enter the URL you want to link to:","http://")
	if (strHref != null) {
    start = ta.selectionStart;
    end = ta.selectionEnd;
  
    // Split before, sel, after and insert tags in between 
    
    before = (ta.value).substring(0, start);
    sel = (ta.value).substring(start, end);
    after = (ta.value).substring(end, ta.textLength);
  
    ta.value = before + "<a href=\"" + strHref +  "\">" + sel + "</a>" + after;
    
    // focus
    ta.focus();
    ta.selectionStart = end + 15 + strHref.length;
    ta.selectionEnd = ta.selectionStart; 

  

		document.selection.createRange().text = "<a href=\"" + my_link + "\">" + str + "</a>";
	}
	return;
}
