/*
Email Safe Linker
FairSky Pages Component
-----------------------
Copyright 2004 Joshua Paine
Created by Joshua Paine of FairSky Networks <http://fairsky.us/>
Contact at <http://fairsky.us/contact>
Updated 2004-10-20

The latest version should be available at
<http://demo.fairsky.us/javascript/email.html>

You may copy, reuse, or produce derivative works of this code
only under the terms of the Linky License v0.1 or later.
The Linky License can be found at <http://fairsky.us/linky>.
The main points of the license are:
	1) Do not alter or remove this notice.
	2) Notify me of your usage through one of the means listed
	   at <http://fairsky.us/contact>.
*/

function fspEmail()
{
	var text, a, email, epat, atpat, dotpat;
	epat = /^\s*(\S+(\s+dot\s+\S+)*\s+at\s+\S+(\s+dot\s+\S+)+)\s*$/;
	atpat = /\s+at\s+/g;
	dotpat = /\s+dot\s+/g;
	if(this.tagName && this.attributes && this.childNodes && this.childNodes[0] && this.childNodes[0].nodeValue && this.parentNode && this.parentNode.insertBefore && document.createElement && this.parentNode.removeChild)
	{
		if(this.tagName.toUpperCase()=='A')
		{
			text = this.href;
			if(text.search('mailto:')==0)
			{
				text = text.substr(7);
				text = text.replace(/\%20/g,' ');
				if(epat.test(text))
				{
					text = text.replace(atpat,'@');
					text = text.replace(dotpat,'.');
					this.href = 'mailto:'+text;
				}
			}
		}
		else if(this.tagName.toUpperCase()=='B')
		{
			text = this.childNodes[0].nodeValue;
			if(epat.test(text))
			{
				text = text.replace(atpat,'@');
				text = text.replace(dotpat,'.');
				a = document.createElement('a');
				a.href = 'mailto:'+text;
				text = document.createTextNode(text);
				a.appendChild(text);
				this.parentNode.insertBefore(a,this);
				this.style.display = 'none';
			}
		}
		
	}
}

document.register('b',null,fspEmail,'load',false);
document.register('a',null,fspEmail,'load',false);