// Email.js version 5
/*
http://www.bronze-age.com/nospam/
http://www.bronze-age.com/nospam/encode.html

To use the script to protect email links in a web page you need to carry out the following steps:

In the HEAD section of the web page, add the following line:

<script language="javascript" src="/scripts/email.js"></script>
You must be careful to specify the correct path to the email.js file - here I've assumed you've saved it into a top-level "scripts" directory in your site.

Now, every email link must be converted to a script call. For instance, a link such as:

<a href="mailto:nobody@fake.address9z.com">Mr Nobody</a>
Needs to be recoded as:

<script type="text/javascript" language="javascript">mail2("nobody","fake.address9z",0,"","Mr Nobody")</script>
or
<script type="text/javascript" language="javascript">mail2("info","coolbytes",10,"","info@coolbytes.co.uk");</script>

The number field is the index of the top domain.

For script disabled sites:
<noscript><p>
Please note that email addresses on this site are protected to avoid abuse by spammers.
You will need a JavaScript-enabled browser to see the email addresses.
</noscript>

*/
var tld_ = new Array()
tld_[0] = "com";
tld_[1] = "org";
tld_[2] = "net";
tld_[3] = "ws";
tld_[4] = "info";
tld_[10] = "co.uk";
tld_[11] = "org.uk";
tld_[12] = "gov.uk";
tld_[13] = "ac.uk";
var topDom_ = 13;
var m_ = "mailto:";
var a_ = "@";
var d_ = ".";

function mail(name, dom, tl, params)
{
	var s = e(name,dom,tl);
	document.write('<a href="'+m_+s+params+'">'+s+'</a>');
}
function mail2(name, dom, tl, params, display)
{
	document.write('<a href="'+m_+e(name,dom,tl)+params+'">'+display+'</a>');
}
function e(name, dom, tl)
{
	var s = name+a_;
	if (tl!=-2)
	{
		s+= dom;
		if (tl>=0)
			s+= d_+tld_[tl];
	}
	else
		s+= swapper(dom);
	return s;
}
function swapper(d)
{
	var s = "";
	for (var i=0; i<d.length; i+=2)
		if (i+1==d.length)
			s+= d.charAt(i)
		else
			s+= d.charAt(i+1)+d.charAt(i);
	return s.replace(/\?/g,'.');
}
