// Website von Voila Bern
// Copyright (C) 2005 Voila Bern

// Originally written for the website of the Cevi-Jungschar Boll-Stettlen

// The JavaScript code for this is very much inspired from http://www.crossover.ch
// . Many thanks to Thomas Bettler!
function add_email_link(name, domain, where_id, linktext, linkclass) {
  // Compute the email address
  var email_address = name + String.fromCharCode(64) + domain;

  // delete any previous childnodes in where_id
  // There might be a spam save version of the email address
  while (document.getElementById(where_id).hasChildNodes()) {
    document.getElementById(where_id).removeChild(document.getElementById(where_id).firstChild);
  }

  // Create the link element
  var a_node = document.createElement("a");
  // The href attribute
  var href_attribute = document.createAttribute("href");
  href_attribute.nodeValue = "mailto:" + email_address;
  a_node.setAttributeNode(href_attribute);
  // a class attribute for the link
  var class_attribute = document.createAttribute("class");
  class_attribute.nodeValue = linkclass;
  a_node.setAttributeNode(class_attribute);

  // Text of the link
  // If empty, we use the email address
  if (linktext == "") linktext = email_address;
  var a_text = document.createTextNode(linktext);
  a_node.appendChild(a_text);

  // Attach the new link to the document.
  document.getElementById(where_id).appendChild(a_node);
}

