function renderMathML(tgt, source) {
  srcout = '<?xml version="1.0"?>'
         + '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN"'
         + ' "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">'
         + '<?xml-stylesheet type="text/xsl" href="mathml.xsl"?>'
         + source;  
  var req = new XMLHttpRequest();
  req.open("GET", "mathml.xsl", false);
  req.overrideMimeType("text/xml");
  req.send(null);
  processor = new XSLTProcessor();
  processor.importStylesheet(req.responseXML);
  var frag = processor.transformToFragment((new DOMParser()).parseFromString(srcout, 'application/xml'),document);
  while (tgt.lastChild) tgt.removeChild(tgt.lastChild);
  tgt.appendChild(frag);
}
function domath() {
  allapplets = document.getElementsByTagName("applet");
  for (i=0; i<allapplets.length; i++)
    if (allapplets[i].hasAttribute("archive") && allapplets[i].getAttribute("archive")=="mathtrans.jar") 
      a = allapplets[i];
  allapplets = document.getElementsByTagName("object");
  for (i=0; i<allapplets.length; i++)
    if (allapplets[i].hasAttribute("type") && allapplets[i].getAttribute("type")=="application/x-java-applet" &&
        allapplets[i].hasAttribute("archive") && allapplets[i].getAttribute("archive")=="mathtrans.jar") 
      a = allapplets[i];
  a.setAttribute("height","0");
  a.setAttribute("width","0");
  alldivs = document.getElementsByTagName("div");
  for (i=0; i<alldivs.length; i++)
    if (alldivs[i].hasAttribute("class") && alldivs[i].getAttribute("class").toLowerCase()=="math") {
      a.setBlockDisplay("true");
      renderMathML(alldivs[i],a.mmlOut(alldivs[i].textContent));
    }
  allspans = document.getElementsByTagName("span");
  for (i=0; i<allspans.length; i++)
    if (allspans[i].hasAttribute("class") && allspans[i].getAttribute("class").toLowerCase()=="math") {
      a.setBlockDisplay("false");
      renderMathML(allspans[i],a.mmlOut(allspans[i].textContent));
    }
}
document.getElementsByTagName("body")[0].setAttribute("onload","domath()");


