function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function safeEmail() {
    
    // Verify methods
    if (
        !document.getElementById ||
        !document.createElement ||
        !document.createTextNode ||
        !document.replaceChild
    ) return false;

    // Get all elements with class="email_address" then loop
    var divs = getElementsByClass('email_address', document, '*');
    for (var i = 0; i < divs.length; i++) {
    
        // Get text, remove child
        var child = divs[i].childNodes[0];
        var url = child.nodeValue;
        
        // Parse address
        url = url.replace('(at)', '@');
        url = url.replace('(dot)', '.');
        url = url.replace(/ /g, '');
        
        // Create anchor element
        var anchor = document.createElement('a');
        anchor.setAttribute('href', 'mailto:' + url);
        
        // Create anchor's text node
        var anchor_text = document.createTextNode(url);
        anchor.appendChild(anchor_text);
        
        // Replace
        divs[i].replaceChild(anchor, child);
    }
}

addLoadEvent(safeEmail);
