//  ------------------------------------------------------------------------ //
//              HCTCommerce - HardCoreTec E-Commerce System                  //
//                     Copyright (c) 2004 HardCoreTec                        //
//                 Developer and Creator Nicolas P�lmann                    //
//                     <http://www.hardcoretec.com/>                         //
//  ------------------------------------------------------------------------ //
//  This file is a component of the HardCoreTec E-Commerce System.           //
//                                                                           //
//  You may not change or alter any portion of this document and it's        //
//  system without having the creators acknowledgement and agreement.        //
//                                                                           //
//  ------------------------------------------------------------------------ //

function addsmiley(textbox, shortcut) {

  if (typeof(textbox.caretPos) != "undefined" && textbox.createTextRange)
  {

    // Attempt to create a text range (IE).
    var caretPos = textbox.caretPos;

    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? shortcut + ' ' : shortcut;
    caretPos.select();

  }
  else if (typeof(textbox.selectionStart) != "undefined")
  {

    // Mozilla text range replace.
    var begin = textbox.value.substr(0, textbox.selectionStart);
    var end = textbox.value.substr(textbox.selectionEnd);
    var scrollPos = textbox.scrollTop;

    textbox.value = begin + shortcut + end;

    if (textbox.setSelectionRange)
    {
      textbox.focus();
      textbox.setSelectionRange(begin.length + text.length, begin.length + text.length);
    }

    textbox.scrollTop = scrollPos;

  }
  else
  {

    // Just put it on the end
    textbox.value += shortcut;
    textbox.focus(textbox.value.length - 1);

  }

}
