markup = {};

markup.addCode = function(code)
{
  var obj = document.getElementById('post_content');
  var Tag = '<' + code + '>';
  var fTag = '</' + code + '>';
	  
  if (code == "a")
  {
	Tag = '<a href="">';
  }
  else if (code == "img")
  {
	Tag = '<img src="">';
	fTag = '';
  }

  
  obj.focus(); 

  if (document.selection && document.selection.createRange)  // Internet Explorer 
  { 
	sel = document.selection.createRange(); 
	if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag; 
  } 

  else if (typeof(obj) != "undefined")  // Firefox 
  { 
	var longueur = parseInt(obj.value.length); 
	var selStart = obj.selectionStart; 
	var selEnd = obj.selectionEnd; 
	
	obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur); 
  } 
  else 
  {
	obj.value += Tag + fTag; 
  }
  
  obj.focus(); 
}
