/*------------------------------------------------------------------------------
  This file is released under the LGPL license. See more about LGPL at
  http://www.gnu.org/copyleft/lesser.html
  I take no responsibility of any kind related to the usage of this script.

  author:    Dominique Stender <dstender@dominiquestender.de>
  copyright: 2003; All rights reserved

//---- what it does ------------------------------------------------------------
  Use this JavaScript to obfuscate your email links from spambots. As of now
  I'm not aware of any spambot that is capable of interpreting JavaScript, thus
  the links generated through this script are clickable to any JavaScript
  enabled browser (as mostly all are) but invisible for spambots. It's not very
  likely that any spambot will be able to interprete JavaScript in the near
  future.

//---- usage -------------------------------------------------------------------
  All you have to to is to include this script (or only the rot13() function
  if you care) into the pages where you'll paste the generated JavaScript code
  into.

  When viewed with a JavaScript enabled browser the user will see a clickable
  link, just like he is used to. However spambots (and browsers with JavaScript
  disabled) will not be able to see/click the link.

//----------------------------------------------------------------------------*/

  function rot13(s_string) {
    var s_charset = "abcdefghijklmABCDEFGHIJKLM#+-12345nopqrstuvwxyzNOPQRSTUVWXYZ@.,67890";
    var s_rot13 = "";

    var n_charsetlen = s_charset.length;
    var n_stringlen = s_string.length;

    for (var i = 0; i < n_stringlen; i++) {
      var s_char  = s_string.substring(i, i + 1);
      var n_pos   = s_charset.indexOf(s_char);
      if (n_pos >= 0) {
        n_pos  = (n_pos + n_charsetlen / 2) % n_charsetlen;
        s_char = s_charset.substring(n_pos, n_pos + 1);
      }
      s_rot13 += s_char;
    }

    return s_rot13;
  }



  function make_linkcode(s_mailaddress, s_linktext) {
    var s_html = rot13('<A HREF="ma' + 'ilt' + 'o:' + s_mailaddress + '">' + s_linktext + '</A>');

    return '<SCRIPT language="Javascript" type="text/javascript">document.write(rot13('
           + "'"
           + s_html
           + "')"
           + ');</SCRIPT>';
  }