/*
Copyright 2004 Joshua Paine
Contact 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.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' && this.childNodes[0].nodeValue)
		{
			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);