﻿// JavaScript to insert emoticon-code into textarea

function setsmil(ktery,content) 
{
  var areas = document.getElementsByTagName('textarea');
  for (var i = 0; ar = areas[i]; i++) 
  {
    if (ar && ar.getAttribute('id') == ktery) 
    {
      // Insert the code
      /* IE */
      if (document.selection) 
      {
        ar.focus();
        cursor = document.selection.createRange();
        cursor.text = content;
   
      } 
      else if (ar.selectionStart || ar.selectionStart == "0") 
      { /* Gecko-based engines: Mozilla, Camino, Firefox, Netscape */
      
        var startPos  = ar.selectionStart;
        var endPos    = ar.selectionEnd;
        var body      = ar.value;
        ar.value = body.substring(0, startPos) + content + body.substring(endPos, body.length);
   
      } 
      else 
      { /* Worst case scenario: browsers that don't know about cursor position, Safari, OmniWeb, Konqueror */
        ar.value += content;
      }
    } 
    
  }
}