// Email.js
/* This script is used to obscure email links from spam harvesters.

USAGE:
In the HEAD section of the web page, add the following line:   
<script language="javascript" src="/ScriptLibrary/email.js"></script>		
Edit the src path to reflect the directory where you've copied this file.   

On the page where you would have your standard 'mailto:' link, use the following instead:	
<script type="text/javascript">mail2("username","domainname",0,"?subject=Whatever","Click Here To Send Email")</script>
	
There are five parameters to configure:
1) The email user name. (The name preceeding the @ sign)
2) The domain name of the email address. (After the @ sign)
3) A number specifying which top-level domain to use. (.com, .org, .net. - see numeric array in the code)
4) A default subject for the email (ex. "?subject=Some Subject". You can also leave this empty like so, "")
5) The text of the link. (The text to be displayed on the web page)

Sometimes you might want to code a link in which the email address itself is shown as the visible text.
To do this, simply call mail() rather than mail2(). In this case, only the first four parameters are needed.
*/
   
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,'.');
}