/*******************************

*** Email Munging JavaScript ***

** Version 1.0 | January 2008 **

********************************

For free distribution 

Written by Satyadarshin
Contact: satyadarshin@fwbo.org

*******************************/

/***********
Instructions
============

This Javascript substitutes a "clickable" email address (a hyperlink that will automatically open up the user's email software) for a a munged email address (a line of plain text).

Please follow these instructions carefully.

_____________________
Munging: what and why
=====================

Email harvesting software scans webpages for lines of text that contain email addresses. These are easy to spot because email addresses follow very obvious patterns.
"Munging" breaks up an email address into a pattern less recognizable by roving software, by removing the code that makes the address "clickable" and substituting characters like "@" and "." for the words "at" and "dot".
The idea is that the human user can interpret the text as being an email address and that they can then hand type the complete address into their email software.
In practice, though, this may not happen: the user may not work out what they need to do, or simply may not bother. It also looks unprofessional.

----------
JavaScript
==========

The route round this is to use JavasScript to create the email address, thereby removing the vulnerable text from the webpage in toto.
The downside to that solution is that if JavaScript functionality is turned off or unavaialable in the receiving Web browser, the user will see nothing at all. 
This script effects a comprimise. 
If the Javascript fails, the user will still see a munged email address and some explanatory text, like this:
	
	programmer[replace with an "at"]satyadarshin[replace with a "dot"]com
	(This email address has been "munged" to stop it being harvested by email spammers.)

Not pretty! But very workable. 
Another dimension to this script is that there is *no JavaScript in the webpage itself*. There will be a _reference_ to this document (yes, the one you're reading!) in the <head> section of your webpage, but that's it. The script will work in any page that contains both the link (reference) to this document and the munged HTML below.

___________________
What you need to do
===================

1/ Mung me bad!
---------------

The JavaScript needs to know what to switch with what.

Open the document that contains the email address you need to deal with. (Make sure you can see the HTML code). Locate the address and delete it *along with any of the HTML code that made it clickable* (anything staring with <a and ending in </a> )
You are going to replace the text in your webpage with the following HTML code (NOTE: *all* of the HTMl code must go in). Paste it into the space the email address used to be.  
Replace the highlit words, below, with the components of your email address:

											    +++++++																   ++++++																																																														+++
<span id="email_address"><span class="fauxlink">mailbox</span>[replace with an "at"]<span class="fauxlink">domain</span>[replace with a "dot"]<span class="fauxlink">tld</span><br />(This email address has been "munged" to stop it being harvested by email spammers.)</span></p>
												+++++++																   ++++++																																																														+++

So, for example, if your email address is programmer@satyadarshin.com, replace the words "mailbox", "domain" and "tld" with "programmer", "satyadarshin" and "com".
Copy and paste that into wherever the email address appears. (but remember every page that has the munged text, above, must also contain the link to the JavaScript, below.)


2/ Edit the JavaScript to also know the components of your email address 
------------------------------------------------------------------------

If you have a look further down (in the JavaScript code itself) you'll see a set of "variables" that need editing in just the samw way your HTML snippet above did.  


3/ connect the javaScript to the webpage
----------------------------------------
In the <head> section of your HTML document (that is, your webpage) insert the following code:

	<script type="text/javascript" src="MungEmail.js"></script>

Put this file (yes, the one you're reading!) into the same folder (directory) as the webpage with the target email address and the above reference.


4/ Open up the page in a webbrowser
__________________________________

Bingo! You'll probably see a brief flash of munged text as the switch occurs, but you should actualy see an clickable link to an email address.
				

/********************
The JavaScript itself
=====================

This section of the script checks that the receiving Web brower will understand the whole program.
If the web browser doiesn't the script will terminate, and the web browser will simply display the munged email address.

***/

window.onload = function insertPseudoProtocol() {						// switches munged email addresses for mailto: email addresses
	if (document.getElementsByTagName) {								// check that UA understands this method
		if (document.getElementById) {									// check that UA understands this method
		
			/***
			
			This section of the code tracks down the munged email address in your webpage. (It's catully looking for the "hooks" in the HTML code snippet, above.)
			
			***/

			if (document.getElementById("email_address")) { 	
				$munged = document.getElementById("email_address");		// get <p> element with id email_address
				while ($munged.childNodes[0]) {							// cycle through all of $munged's children	
					$munged.removeChild($munged.childNodes[0]);			// delete $munged's children
				}
				
				/***
				
				The next three lines of code contain the components that recreate your email address.
				This is the section YOU MUST EDIT for the script to perform hte switch.
				REPLACE the words "mailbox", "domain" and "tld" with the corresponding elements of your email address. (This is the same as you did in the HTML code, above.)
				For example:
					programmer@satyadarshin.com is broken down into "programmer", "satyadarshin" and "com"
				If your address has multiple dot separators ( e.g. web.design@internet.elf.co.uk) you could keep it simple and do this:
					"web.design", "internet.elf" and "co.uk"
				
				***/
				
				var $piece1 = "ash";
				var $piece2 = "helpingchange";
				var $piece3 = "co";
				var $piece4 = "uk";
				
				/***
				
				This next section creates the fake email address
				
				***/
				
				var $pieces = $piece1 + "@" + $piece2 + "." + $piece3 + "." + $piece4;		// construct an email address
				var $jigsaw = "mailto:" + $pieces;						// add the pseudo-protocol
				var $substitute = document.createElement("a");			//create the anchor
				$substitute.setAttribute("href",$jigsaw);				//insert an href attribute and pseudo-protocol
				var $text = document.createTextNode($pieces);			// create the link text
				$substitute.appendChild($text);							// insert the link text into the node tree
				$munged.appendChild($substitute); 						// insert the anchor into the node tree
			}; 
		}	
	}
}
