function postFormInsert(SelectionText,prefix,suffix,URL) 
{
 var formatStart = SelectionText.selectionStart;
 var formatEnd = SelectionText.selectionEnd;
  if (navigator.appVersion.indexOf("MSIE")!=-1) 
  {
   SelectionText.focus();
   var selection = document.selection.createRange();
   if (selection.text) 
   {
    if (prefix.substring(0,5) == '<a hr' || prefix.substring(0,5) == '<img ')
    {
     if (selection.text.substring(0,4) != 'http')
     {
      selection.text = prefix + 'http://' + selection.text + suffix;
     }
     else
     {
      selection.text = prefix + selection.text + suffix;
     }
    }
    else
    {
     selection.text = prefix + selection.text + suffix;
    }
    selection.moveStart('character', 0);
    selection.moveEnd('character', 0);
    selection.select();
   } 
   else 
   {
    selection.text = prefix + URL + suffix;
    selection.moveStart('character', -suffix.length);
    selection.moveEnd('character', -suffix.length);
    selection.select();
   }
  }
  else 
  {
   if (formatStart == formatEnd) 
   {
    SelectionText.value = SelectionText.value.substring(0, formatStart) + prefix + URL + suffix + SelectionText.value.substring(formatEnd, SelectionText.value.length);
    SelectionText.focus(); 
    SelectionText.setSelectionRange(formatEnd + prefix.length + URL.length, formatEnd + prefix.length + URL.length);
    var lockScrolling = SelectionText.scrollTop;
    SelectionText.scrollTop = lockScrolling;
   } 
   else 
   {
    if (prefix.substring(0,5) == '<img ')
    {
     if (SelectionText.value.substring(0,4) != 'http')
     {
      SelectionText.value = SelectionText.value.substring(0, formatStart) + prefix + 'http://' + SelectionText.value.substring(formatStart,formatEnd) + suffix + SelectionText.value.substring(formatEnd, SelectionText.value.length);
     }
     else
     {
      SelectionText.value = SelectionText.value.substring(0, formatStart) + prefix + SelectionText.value.substring(formatStart,formatEnd) + suffix + SelectionText.value.substring(formatEnd, SelectionText.value.length);
     }
    }
    else
    {
     SelectionText.value = SelectionText.value.substring(0, formatStart) + prefix + SelectionText.value.substring(formatStart,formatEnd) + suffix + SelectionText.value.substring(formatEnd, SelectionText.value.length);
    }
    SelectionText.setSelectionRange(formatEnd + prefix.length + URL.length + suffix.length, formatEnd + prefix.length + URL.length + suffix.length);
    SelectionText.focus();
    var lockScrolling = SelectionText.scrollTop;
    SelectionText.scrollTop = lockScrolling;
   }
  }
  return false;
}

//code taken from http://www.reconn.us/demo/character_counter.html
function CountLeft(field, count, max) 
{
 if (field.value.length > max)
 {
  field.value = field.value.substring(0, max);
 }
 else
 {
  count.value = max - field.value.length;
 }
}
