function removeClass(el,theClass) {
    var curClass = " "+el.className+" "
    var targetClass = " "+theClass+" "
    var location = curClass.indexOf(targetClass)
    if (location >= 0) {
        curClass = curClass.substring(0,location)
                     + " "
                     + curClass.substring(location+targetClass.length);
        if (curClass.charAt(0) == ' ') {
            curClass = curClass.substring(1)
        }
        if (curClass.charAt(curClass.length - 1) == ' ') {
            curClass = curClass.substring(0, curClass.length - 1)
        }
        el.className = curClass
    }
}

function hasClass(el,theClass) {
    return ((" "+el.className+" ").indexOf(" "+theClass+" ") >= 0)
}

function textValue(el) {
  var nodeList = el.childNodes;
  var result = "";
  for (var i=0; i<nodeList.length; ++i) {
    var child = nodeList.item(i);
    if (child.nodeType == 3) { // Node.TEXT_NODE = 3 in DOM
    	result += child.data;
    }
  }

  return result;
}

function fixEmail() {
  var nodeList = document.getElementsByTagName("a");
  var parent = null;

  for (var i=0; i<nodeList.length; ++i) {
    var el = nodeList.item(i);
    if (hasClass(el,"email")) {
      var imgList = el.getElementsByTagName("img");
      if (imgList.length > 0) {
        var imgNode = imgList.item(0);
        var t = document.createTextNode("@");
        el.replaceChild(t,imgNode);
        el.href = "mailto:" + textValue(el);
      }
    }
  }
}
