/*
** $Id: fixmail.js,v 1.1 2007/03/15 14:43:45 rr Exp $
** Robert Rothenberg <rr at cs dot st-andrews dot ac dot uk >

** looks for <span class="fix">some guy at example dot com</span>
** and changes it usable mailto link.

** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.

*/

function correctMail() {

  if (!document.getElementsByTagName) return;

  var mailtos = document.getElementsByTagName("span");

  for (var i=0; i<mailtos.length; i++) {
    var mail = mailtos[i];

    if (mail.getAttribute("class") == "fix") {

      addr = mail.firstChild.nodeValue;

      addr = addr.replace(/\W+(at(\W*sign)?)\W+/gi, "@");
      addr = addr.replace(/\W+(dot)\W+/gi, ".");

      addr = addr.replace(/\s+/g, "");

      var a = document.createElement("a");
      a.appendChild(document.createTextNode(addr));
      a.setAttribute("href", "mailto:"+addr);

      mail.replaceChild(a, mail.firstChild);
    }

  }
  return 1;
}


{

  if (window.onload == null)
    window.onload = function() { correctMail(); }
  else {
    var c = window.onload;
    window.onload = function() { (c)(); correctMail(); }
  }
}

