initSymbols();

keyspressed = 20;

function node2string(in_node,indent)
{
   var str = "";
   var children = in_node.childNodes.length;
   if(in_node.nodeType == 1)
   {
       var name = in_node.nodeName.toLowerCase(); // (IE fix)
       str = "\n" + indent + "<" + name;
       for(var i=0; i < in_node.attributes.length; i++)
           if (in_node.attributes[i].nodeValue!="italic" &&
               in_node.attributes[i].nodeValue!="" &&  //stop junk attributes
               in_node.attributes[i].nodeValue!="inherit" && // (mostly IE)
               in_node.attributes[i].nodeValue!=undefined)
               str += " "+in_node.attributes[i].nodeName+"="+
                     "\""+in_node.attributes[i].nodeValue+"\"";
       if (name == "math") 
           str += " xmlns=\"http://www.w3.org/1998/Math/MathML\"";
       str += ">";
       for(var n_index=0; n_index < children; n_index++)
       {
           str += node2string(in_node.childNodes[n_index], indent+"  ");
       }
       if (name != "mo" && name != "mi" && name != "mn") str += "\n"+indent;
       str += "</" + name + ">";
   }
   else if(in_node.nodeType == 3)
       str = in_node.nodeValue;

   return str;
} 

function display() {
  var str = document.getElementById("inputText").value;
  var outnode = document.getElementById("outputNode");
  var n = outnode.childNodes.length;
  for (var i=0; i<n; i++)
    outnode.removeChild(outnode.firstChild);
  outnode.appendChild(document.createTextNode(str));
  processNode(outnode);
  var outMathML = document.getElementById("outputMathML");
  outMathML.value = node2string(outnode,"");
}

function changeColumns(n) {
  var node = document.getElementById("inputText");
  node.setAttribute("cols",n);
}
