/* 
Simple Javascript Email Obfuscator

To use, just create an empty span tag with the class "email"
and then set the id to the name at your domain you want to use.

EXAMPLE:
    <code>&lt;span id="test1" class="email"&gt;&lt;/span&gt;</code>
    
RESULTS IN:
    <code>test1@mydomain.com</code>

NOTES:
  - You can make the email addresses linked by sending "true" to the
    function (default is unlinked).
  
  - You can also send a second param which indicates the domain to use
    (will default to your current domain).
  
  - In order to use this script. you must call it from body's onload attribute.

    <code>&lt;body onload="fixEmail(true,'mydomain.com');"&gt;</code>
    
    
Jonathan Cross :: 2009

*/
function fixEmail(isLink,dom){
  if (isLink) {
	  isLink = 1;
  }else{
	  isLink = 0;
  }
  if (dom) {
	  var domain = dom;
  }else if (document.domain){
		regex = /[^.]+[.][A-z][A-z]+$/i;
		var domain = regex.exec(document.domain)[0];
  }else{
		var domain = "test.com";
	}
  if(document.getElementsByTagName) {
		var atSign = "&#064;";
		var mt = "mailto"+":";
		var spans = document.getElementsByTagName('span');
		for (var i=0;i<spans.length;i++){
			s=spans[i];
			if (s.className != null && s.className == "email") {
				e=s.id + atSign + domain;
				if (isLink) {
					e="<a href='" + mt + e + "'>" + e + "</a>";
				}
				s.innerHTML = e;
			}
		}
  }
}
