/*JavaScript Document
mailSwap.js: Adds a layer of security from spam-bot crawlers, by swapping the html of links 
marked with "mailSwap" classname with a proper mailto link. The original link in the html should be a safe subtitute, for example:
<a class="mailSwap" href="contact.htm">info at neo-archaic.net<a> 
The result is that the html is reasonably secure from spam bots, but a human user with JavaScript enabled 
will view and interact with the actual link to the website. 
Providing a link tho a page with a php contact form in the original html linke will cater for users without JavaScript, 
but the forms are not spam proof either...
*/

var defUsername = "ab";
var defDomain = "babydr.us";

//Loop through all the elements with a classmane of "mailSwap"
//and convert them into proper mailto: links
function mailSwap(){
	// Fetch all the a elements in the document.
	var links = document.getElementsByTagName('a');		

	// Loop through the a elements in reverse order for speed.		
	for (var i = links.length; i != 0; i--) {			
		// Pull out the element for this iteration.
		var a = links[i-1];
		//Use only the links with "mailSwap" class
		if (a.className && a.className.indexOf('mailSwap') != -1){
			//replace the link's html
			swapLink(a, defUsername, defDomain);
		}
	}
}

//This function can be used to add ad-hoc email adresses in the body of the html, 
//by calling the function and passing an id of the link to be swapped
function mailTo(id, username, domain){
	var a = document.getElementById(id);
	swapLink(a, username, domain);
}

//This function does the actual swapping of the original html
function swapLink(a, username, domain){
	username = username != undefined ? username : defUsername;
	domain  = domain != undefined ? domain : defDomain;
	var email = username+"@"+domain;
	a.innerHTML = email;
	a.href = "mailto:"+email;
}



//Initiate the function without conflicting with the window.onload event of any preceding scripts
var mailTempFunc = window.onload;
window.onload = function(){
	if (typeof (mailTempFunc) == "function"){
		try{
			mailTempFunc();
		} catch(e){}
	}
	mailSwap();
}