//v0.1 31/10/06 James Gray

// Code starting with KB: from Keith Brunton's ASCIIMath Customisations

// Altered 25/5/06 James Gray: added a wait on AMdisplay so quick typing isn't disrupted by slow display area update.  See key1 and key2 below.

// This script allows customisations of ASCIIMath - it must appear after the script tag
// that imports ASCIIMathML.js and ASCIIMathMLeditor.js

// for simple symbol inclusions, use this syntax
newcommand("!<=","\u2270");
newcommand("!>=","\u2271");

// KB: added new definitions for times - overrides the older defn - try a*b and a*.b
// JG: commented out KB's times definition because didn't override defn when using IE
//AMsymbols = AMsymbols.concat([{input:"*", tag:"mo", output:"\u00D7", tex:"times", ttype:CONST}])
//AMsymbols = AMsymbols.concat([{input:"*.", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST}])

// JG: added new definitions of inverse trig functions as these are standard in Open Uni courses
AMsymbols = AMsymbols.concat([{input:"cosec",  tag:"mo", output:"cosec", tex:null, ttype:UNARY, func:true}])
AMsymbols = AMsymbols.concat([{input:"arcsin",  tag:"mo", output:"arcsin", tex:null, ttype:UNARY, func:true}])
AMsymbols = AMsymbols.concat([{input:"arccos",  tag:"mo", output:"arccos", tex:null, ttype:UNARY, func:true}])
AMsymbols = AMsymbols.concat([{input:"arctan",  tag:"mo", output:"arctan", tex:null, ttype:UNARY, func:true}])


// KB: don't allow double-blank to delimit asciimath - more hassle than its worth
doubleblankmathdelimiter = false;

// KB: default colour of maths
// mathcolor="darkblue";

// KB: explicitly hide style
displaystyle=true;


var key1 = false;
var key2 = false;        

// KB: 06/10/05 modified this to take input and output nodes as parameters
// to allow more than one 'editor' place on a page
// JG: Added the variables key1 and key2.  Key1 is true when a key has been pressed, key2 is true
// if another key is pressed before the timout occurs.  This allows you to type fast without the display
// updating (which slows the typing down).
function AMdisplay(now) {
    if(!now){
        if(!key1 && !key2) {
            key1 = true;
            setTimeout("AMdisplay(true);", 250);
        } else if (key1 && !key2) {
            key2 = true;
        }
    }
    if(now){
        if (key1 && key2){
            key2 = false;
            setTimeout("AMdisplay(true);", 250);
        } else if (!key2){
            key1 = false;
            if (document.getElementById("inputText") != null) {
                var str = document.getElementById("inputText").value;
                var outnode = document.getElementById("outputNode");
                var newnode = AMcreateElementXHTML("div");
                newnode.setAttribute("id","outputNode");
                outnode.parentNode.replaceChild(newnode,outnode);
                outnode = document.getElementById("outputNode");
                var n = outnode.childNodes.length;
                for (var i = 0; i < n; i++)
                    outnode.removeChild(outnode.firstChild);
                outnode.appendChild(document.createComment(str+"``"));
                AMprocessNode(outnode,true);
            }
        }
    }
}

