/* Demung e-mails script */

function demungEmails() {
	var anchors = $('A');
	var numAnchors = anchors.length;
	var currAnchor;
	for (var i = 0; i < anchors.length; i++) {
		currAnchor = anchors[i];
		if (currAnchor.href.match(/^mailto:/i)) {
			currAnchor.href = currAnchor.href.replace(/--a--/i,'@')
			currAnchor.href = currAnchor.href.replace(/([?&]|\&amp;)body=replace%20--a--%20in%20the%20to%20address%20with%20@/i,'')
			demungEmailsText(currAnchor);
		}
	}
}

function demungEmailsText (node) {
	var alphaspans = $('SPAN', node);
	var currnode;
	for (var i = 0; i < alphaspans.length; i++) {
		currnode = alphaspans[i];
		if (currnode.nodeType == 1) {
			if ((currnode.hasChildNodes()) && (currnode.childNodes.length == 1)) {
				childnode = currnode.childNodes[0];
				if ((childnode.nodeType == 3) && (childnode.nodeValue == " ")) {
					childnode.nodeValue = "@";
					break;
				}
			}
		}
	}
}


$(function () {
	demungEmails();
});

