
// use this:  <SCRIPT SRC="oa.js" LANGUAGE="JavaScript"></SCRIPT>

// <SCRIPT SRC="oa.js">  not required here/wont work


    /* show or hide and object
    ex:
    <IMG SRC="images/cmdDebug.gif" onClick='oatoggle(OAPOPUP);' STYLE="cursor: hand">
    <SPAN ID="OAPOPUP" style= "z-index: 1; cursor: hand; position: absolute; visible: false; display: none;" onClick='oahide(OAPOPUP);' >
    */
    function oaToggle(obj) {
        if (obj.style.display == "none") {
            obj.style.display = "";
        }
        else {
            obj.style.display = "none";
        }
    }

    function oaShow(obj) {
        obj.style.display = "";
    }

    function oaHide(obj) {
        obj.style.display = "none";
    }


    function oaPrint() {
        this.focus();
        this.print();
    }


    function oaSubmit() {
        oaSubmit("");
    }

    function oaSubmit(cmd) {
        oaSubmitAll(top);
        if (cmd != '') {
            var action = document.forms[0].action;
            if (action.indexOf('?') < 0) action += "?";
            else action += "&";
            document.forms[0].action = action + cmd + '.oa=1';
        }
        document.forms[0].submit();
    }

    var oaChanged = false;

    /** called by onSubmit() and oaSubmit() to submit all other forms before this one is submitted. */
    function oaSubmitAll(frm) {
        if (frm.location == null) return;
        if (frm.location == "") return;
        
        var b = (frm.setOA != null);
        if (b) {
            b = frm.oaChanged;
            if (b || frm == this) {
                b = (frm.document.forms.length > 0);
                if (b) {
                    frm.setOA();
                }
            }
        }

        var x = frm.frames.length;
        var i = 0;
        for ( ; i<x; i++) {
            oaSubmitAll(frm.frames[i]);
        }
        if (b && frm != this) {
            var action = frm.document.forms[0].action;
            if (action.indexOf('?') < 0) action += "?";
            else action += "&";
            frm.document.forms[0].action = action + 'oasubmitonly=1';
            frm.document.forms[0].submit();
            this.document.forms[0].oasubmitonlycount.value += "X";
        }
    }



    /** send window information with submit. OAForm uses this to process request. */
    function setOA() {
        var y;
        if (document.layers) y = window.pageYOffset;
        else y = document.body.scrollTop;
        if (document.layers) x = window.pageXOffset;
        else x = document.body.scrollLeft;
        document.forms[0].oatop.value = y;
        document.forms[0].oaleft.value = x;
        document.forms[0].oatarget.value = document.forms[0].target;
        document.forms[0].oawindowpath.value = getWindowPath();
        return y;
    }

    /** path of frames and urls.  Used by OASession.setRequest() to update frames. */
    function getWindowPath() {
        var vpath = "";
        var vloc = "";
        var win = window;
        for (var i=0;;i++) {
            if (i > 0) {
                vpath = ";" + vpath;
                vloc = "oav;" + vloc;
            }
            vpath = win.name + vpath;

            var s = win.location + "";

            var pos;
            pos = s.lastIndexOf("/");
            if (pos < 0) {
                pos = s.lastIndexOf("\\");
                if (pos < 0) pos = -1;
            }
            if (pos >= 0) s = s.substr(pos+1);

            vloc = s + vloc;
            if (win == top) break;
            win = win.parent;
        }
        return vpath + "|" + vloc ;
    }




    // OAString functions ==========================================
    function oaStrip(value, chars) {
        return oaStripChars(value, chars, false);
    }
    function oaAccept(value, chars) {
        return oaStripChars(value, chars, true);
    }


    function oaStripChars(value, chars, bKeepChars) {
        var s = "";
        var x = value.length;
        var i = 0;
        for ( ; i<x; i++) {
            var c = value.charAt(i);
            if (bKeepChars) {
                if (chars.indexOf(c) >= 0) s += c;
            }
            else {
                if (chars.indexOf(c) < 0) s += c;
            }
        }
        return s;
    }

    function oaMask(value, mask) {
        return oaMask(value, mask, false);
    }

    function oaMask(value, mask, bRightJustified) {
        var s = "";
        var i = 0;
        var x = value.length;

        var i2 = 0;
        var x2 = mask.length;

        if (bRightJustified) {

            var cnt = 0;
            for ( ; i2<x2; i2++) {
                var ch = mask.charAt(i2);
                if (ch == '#') cnt++;
            }

            if (cnt > x) {
                value = oaPad(value, cnt, false, ' ');
                x = value.length;
            }
            i2 = 0;
        }

        for ( ; i2<x2; i2++) {
            var c = mask.charAt(i2);
            if (c == '#') {
                if (i < x) {
                    s += value.charAt(i);
                    i++;
                }
            }
            else s += c;
        }
        return s;
    }

    function oaPad(value, amount, bPadRight, charPad) {
        var w = value.length;
        var x = amount - w;
        if (x <= 0) return value;
        var s = "";
        for (i=0; i<x; i++) s += charPad;

        if (bPadRight) value += s;
        else value = s + value;
        return value;
    }

    function oaToTitleCase(s) {
        var x = s.length;
        if (x == 0) return s;

        if (s != s.toUpperCase() && s != s.toLowerCase()) return s;

        var b = true;
        var newValue = "";
        for (i=0; i<x; i++) {
            var ch = s.charAt(i);
            if (oaIsLetter(ch)) {
                if (b) ch = ch.toUpperCase();
                else ch = ch.toLowerCase();
                b = false;
            }
            else b = true;
            newValue += ch;
        }
        return newValue;
    }

    var reLetter = /^[a-zA-Z]$/
    function oaIsLetter(c) {
        return reLetter.test(c)
    }








// MISC *******************

// Display prompt string s in status bar.
function prompt (s)
{   window.status = s
}

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.
function warnInvalid (theField, s)
{   theField.focus();
    theField.select();
    alert(s);
    return false
}



//</SCRIPT>  not required/wont work

