/*
 Author: Shawn Stedman - www.pixelwisedesign.com/blog/
 Version: 1.0
 Date: 2-18-2009
 Description:  This code obfuscates email addresses from spambots using HTML numeric
               character references, JavaScript and CSS.
               A spambot would have to:
			     1) Be able to parse JavaScript
			     2) Decode HTML numeric character references to regular characters
				 3) Remove the hidden <span>
				 ...And still recognize it as an email address
 Issues:       If JavaScript is not enabled, email address is not accessible.
               With a screen reader or no CSS support, the NOSPAM block will appear.
 Enhancements: Encode to entities at random
               Integrate with server side language and add auto <noscript>
*/

// Encode strings as HTML numeric character references
function charEncode( theString ) {
  var encodedString = '';

  for ( i=0 ; i < theString.length ; i++ ) {
    encodedString = encodedString + '&#' + theString.charCodeAt(i) + ';';
  }

  return encodedString;
}

// Linked email address
function emailLink( name, domain ) {
  var mailto = '&#109;&#97;&#105;&#108;&#116;&#111;&#58;'; // 'mailto:'
  var nospam = 'nonexistentemailaddress.com '; // or 'NOSPAM' or '@#$)(*' or anystring
  
  document.write( '<a href=\"' + mailto + charEncode(name) + '@' + charEncode(domain) + '\" rel=\"nofollow\">' + charEncode(name) + '@<span class=\"nospam\">' + nospam + '</span>' + charEncode(domain) + '</a>' );
}

// Printed email address, with no link
function emailNoLink( name, domain ) {
  var nospam = 'nonexistentemailaddress.com '; // or 'NOSPAM' or '@#$)(*' or anystring
  
  document.write( charEncode(name) + '@<span class=\"nospam\">' + nospam + '</span>' + charEncode(domain) );
}

// Linked email address with link text other than email address
function emailLinkText( name, domain, linkText ) {
  var mailto = '&#109;&#97;&#105;&#108;&#116;&#111;&#58;'; // 'mailto:'
  
  document.write( '<a href=\"' + mailto + charEncode(name) + '@' + charEncode(domain) + '\" rel=\"nofollow\">' + linkText + '</a>' );
}