// mail2() function call:
// The email name: i.e. the bit before the @ sign
// The second-level domain of the email address: this is the bit after the @ sign, but with the top level domain (".com" or ".co.uk" etc) stripped off.
// A number specifying which top-level domain to use.
// The fourth parameter allows you to specify a default subject for the email, by passing e.g. "?subject=Changeringing", but normally you'll just need the empty string "".
// Finally, the text of the link, i.e. the name to be displayed to the user in the web page.
//
// Sometimes you might want to code a link in which the email address itself is shown as the visible text, e.g. nobody@fake.address9z.com.
// To do this, simply call mail() rather than mail2(). Only the first four parameters are needed.
// Link Generator: http://bronze-age.com/nospam/encode.html

var tld_ = new Array()
tld_[0] = "com";
tld_[1] = "org";
tld_[2] = "net";
tld_[3] = "ws";
tld_[4] = "info";
tld_[10] = "com.au";
tld_[11] = "org.au";
tld_[12] = "gov.au";
tld_[13] = "ac.au";
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,'.');
}

