/*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...
*/


neoarchaic.MailSwap = function(username, domain){
	//Check for ie 5.5 and exclude it from the script
	if (!document.getElementById){
		return;
	}
	this.defUsername = username;
	this.defDomain = domain;
	this.addLoadEvents();
}

neoarchaic.protoObj = {
	className: "MailSwap",
		
	init: function(){
		if (this.isInit) return;
		this.isInit = true;
		this.mailSwap();
	},
	
	//Loop through all the elements with a classmane of "mailSwap"
	//and convert them into proper mailto: links
	mailSwap: function(){
		// 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
				this.swapLink(a);
			}
		}
	},
	
	//This function does the actual swapping of the original html
	swapLink: function(a, username, domain){
		username = username != undefined ? username : this.defUsername;
		domain  = domain != undefined ? domain : this.defDomain;
		var email = username+"@"+domain;
		a.innerHTML = email;
		a.href = "mailto:"+email;
	},
	
	//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
	mailTo: function(id, username, domain){
		if (!document.getElementById){
			return;
		}
		var a = document.getElementById(id);
		if (a != null){
			this.swapLink(a, username, domain);
		}
	}
}
	
neoarchaic.Core.extend(neoarchaic.MailSwap, null, neoarchaic.protoObj);
delete neoarchaic.protoObj;

neoarchaic.Core.newObject("mail_swap", "MailSwap", "taichidublin", "eircom.net");



