/*
	noSpam.js
	
	Description:
	
		Obfuscate email addresses (and links) from spambots. Converts a span in 
		the form of
			<span class="electronic-mail">user[AT]domain[D0T]com</span>
		into
			<a href="mailto:user@domain.com">user@domain.com</a>
		at runtime using client-side processing with the DOM. Browsers without 
		JavaScript or DOM support will see the readable, but unclickable, span 
		shown above.


	Revision History:
	
		??/??/?? - Created by jj, from logic.net
		??/??/?? - Updated by Justin Makeig from Berkeley
		12/30/04  - Modified by Brendan Hargreaves '06 for the Residential Council
					webpage.  Not much changed in terms of content, mostly just
					legibility (and added some comments).
		
	Original source:
	
		http://lojjic.net/blog/20030828-142754.rdf.html
	
	Special Thanks:
	
		To brown.dailyjolt.com for originally modifying this free script (thus, 
		providing the link)
		
*/

function noSpam() {
	/* If you cannot grab the tags, just return */
	if(!document.getElementsByTagName) return;
	
	/* Make array of all <span> tag entries.  Changed to span tag for increased
		speed (could make array of all elements by changing SPAN to *) */
	var allElts = document.getElementsByTagName('SPAN');
	
	/* IE5 Hack */
	if(allElts.length == 0 && document.all) 
		allElts = document.all; //hack for IE5
	
	/* Loop through array of SPANs */
	for(var i=0; i<allElts.length; i++) {
		var elt = allElts[i];
		var className = elt.className || elt.getAttribute("class") || elt.getAttribute("className");
	/* If SPAN entry has class attribute of "electronic-mail", then replace
		the inner html */
	if(className && className.match(/\belectronic-mail\b/)
		&& elt.firstChild.nodeType == 3) {
			var addr = elt.firstChild.nodeValue;
			/* All the variations that it can find and replace */
			addr = addr.replace(/[ \[\{\(\|\/\\]at[ \]\}\)\|\/\\]/i, "@")
			.replace(/[ \[\{\(\|\/\\](dot|period)[ \]\}\)\|\/\\]/gi, ".");
			var lnk = document.createElement("a");
			lnk.setAttribute("href","mailto:"+addr);
			lnk.appendChild(document.createTextNode(addr));
			elt.replaceChild(lnk, elt.firstChild);
    }
  }
}