/*
 * Mailify(link)
 * link: A reference to a link tag to "mailify"
 *
 * This function extracts a mailto: link from the href of the passed link tag.
 * The link's href must have been encoded in the following fashion:
 * - "http://www." in place of "mailto:"
 * - "*" in place of "@"
 * This encoding results in an href string like so: http://www.andy*tidball.net, which looks a lot like a normal URL
 */
function Mailify(link) {
	link.href = ExtractMailLink(link.href);
}

/*
 * ExtractMailLink(URL)
 * URL: A string representing an encoded mailto: URL (see Mailify for encoding scheme)
 *
 * This function extracts a normal mailto: URL from the encoded URL passed in and returns it
 */
function ExtractMailLink(address) {
	if (address.indexOf("*") == -1) {
		return address;
	}
	if (address.indexOf("http://www.") == 0) {
		address = address.substr(11);
	}
	if (address.indexOf("http://") == 0) {
		address = address.substr(7);
	}
	if (address.charAt(address.length-1) == "/") {
		address = address.substr(0,address.length-1);
	}
	address = address.replace(/\*/, "@");
	address = address.replace(/!/, ".");
	if (address.indexOf("mailto:") == -1) {
		address = "mailto:" + address;
	}
	return address;
}