/**
 * This script is created by Ahn Tuan Nguyen Dao and Peter Heino Bøg
 * contact: atdao /at/ cs /dot/ aau /dot/ dk and peterbog /at/cs /dot/ aau /dot/ dk
 */ 

/**
 * Print an email link
 * Usage:
 * <span id="%%ID%%">Default text</span><script type="text/javascript">protectEmail('%%DOMAIN%%', '%%NAME%%', '%%ID%%');</script>
 *
 * @param domain    The domain of the email (after @)
 * @param name      The name of the email (before @)
 * @param id        The id of the span tag whithin the email link should be created
 * @param linkclass The class of the <a> tag, can be empty
 */
function protectEmail(domain, name, id, linkclass) {
    // Find the span we want to play with
    objSpan = document.getElementById(id);
    
    // Remove all its children (so we're sure any default text is gone)
    while( objSpan.hasChildNodes() ) {
        objSpan.removeChild( objSpan.lastChild );
    }
    
    // Create the email address
    mail = name + "@" + domain;
    
    // Create an anchor object
    objLink = document.createElement('a');
    objLink.href = "mailto:" + mail;
    objLink.innerHTML = mail;
    if(linkclass!="") {
        objLink.className = linkclass;
    }

    // add the newly created anchor
    objSpan.appendChild(objLink);
}
