/********
 ****** (C) Wipplinger EDV Dienstleistungen 1999 - 2007
 **** All Rights Reserved
 ** Confidential
 *
 *
 * PROJECT:      CaveSeekers
 * AUTHOR:       Jürgen L. Wipplinger
 * LANGUAGE:     Java Script
 * DATE:         10.10.2007
 * STATE:        STILL CRITICAL
 *
 ******************************************************************************/

 /**
  * Just some helperfunctions
  */

 /**
  * This mighty method inserts the given smiley code into the also given 
  * html text clTextField field. crazy.
  */
  
function insertSmiley(clTextField, iSmiley) 
{
  clTextField.focus();
  strSmiley = "@"+iSmiley;
    
  /* Internet Explorer */
  if(typeof document.selection != 'undefined') 
  {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = strSmiley;
      
    /* Adjust new caretposition */
    range = document.selection.createRange();
    range.select();
  }
  /* Firefox */
  else if(typeof clTextField.selectionStart != 'undefined')
  {
  
    var start = clTextField.selectionStart;
    var end = clTextField.selectionEnd;
    var insText = clTextField.value.substring(start, end);
    clTextField.value = clTextField.value.substr(0, start) + strSmiley + clTextField.value.substr(end);

    /* Adjust new caretposition */
    var pos;
    if (insText.length == 0) 
    {
      pos = start + strSmiley.length;
    } 
    else 
    {
      pos = start + strSmiley.length + insText.length;
    }
    clTextField.selectionStart = pos;
    clTextField.selectionEnd = pos;
  }
  /* all the others */
  else
  {
   alert("Browser zu schlecht.");
  }
}