Handler.add(window, "load", replaceEmailLinks);

// search for spans with class 'e-mail' and replace
// them with <a href="mailto:..."> type of links.
function replaceEmailLinks() {
    // get all e-mail spans
    var emailSpans = getElementsByClass("e-mail", document, "span");

    // replace each of them with link
    each(emailSpans, emailSpanToLink);
}

function emailSpanToLink(emailSpan) {
    // get the text inside span
    var text = emailSpan.firstChild.nodeValue;

    // split the text into two parts
    // at the location where the @-sign should be
    var parts = text.split(" ät ", 2);
    var name = parts[0];
    var domain = parts[1];

    // combine the parts to make actual e-mail address
    var email = name + "@" + domain;

    // create a href=mailto: element that links to this address
    var emailLink = document.createElement("a");
    emailLink.href = "mailto:" + email;
    emailLink.appendChild(document.createTextNode(email));

    // substitute the span with our new link element
    var parentElement = emailSpan.parentNode;
    parentElement.replaceChild(emailLink, emailSpan);
}

