/*
 * javascript support functions
 *
 */

var _hasXMLHTTP         = false;
var _timeoutAdjustment  = 0;        // timeout adjustment... (was W)... gets adjusted over time...

function conditionalRedirect(PsQuestion, PsUrl) {
    if (confirm(PsQuestion)) {
        document.location = PsUrl;
    }
}

function pingTo(PsUrl) {
    LoPingback = getXMLHTTP();

    if(LoPingback && LoPingback.readyState != 0) {
        LoPingback.abort()
    }

    LoPingback.open("GET", PsUrl, true);
    LoPingback.send(null);
}

function openHelpwindow(PsHelpID) {
    url = "/help.php?ID=" + PsHelpID;

    LoWindow = window.open(url, "helpwin","toolbar=no,location=no,menubar=no,channelmode=0,status=no,left=15,top=15,height=375,width=375");
}

function myfunc(dtmSelected) {
    window.location = "/notes.php?DATE=" + dtmSelected;
}

function mymfunc(mnt) {
    window.location = "/index.php?MNTH=" + mnt;
}

function editNotetypes(PsNotecombo) {
    url = "/notetypes.php?FLD="+ PsNotecombo;

    LoWindow = window.open(url, "typewin", "toolbar=no,location=no,menubar=no,channelmode=0,status=no,height=400,width=500");
}

function editLocations() {
    url = "/locations.php";

    LoWindow = window.open(url, "locwin", "toolbar=no,location=no,menubar=no,channelmode=0,status=no,height=400,width=500");
}

function getDateWin(PsDatefield) {
    url = "/getdate.php?FLD=" + PsDatefield;

    LoWindow = window.open(url, "datewin","toolbar=no,location=no,menubar=no,channelmode=0,status=no,height=250,width=230");
}

function fillDivFromURL(PsURL, PsID, PsTimeout) {
    var _xmlHttp = null;
    var LoElem = document.getElementById(PsID);

    if (getXMLHTTP()) {
        _hasXMLHTTP = true;
    }
    else {
        _hasXMLHTTP = false;
    }

    if(_xmlHttp && _xmlHttp.readyState != 0) {
        _xmlHttp.abort()
    }

    _xmlHttp = getXMLHTTP();

    if (_xmlHttp) {
        _xmlHttp.open("GET", PsURL, true);

        // Note that this function will ONLY be called when we get a complete
        // response back from server!!

        _xmlHttp.onreadystatechange =
            function() {
                if (LoElem) {
                    if (_xmlHttp.readyState == 4 && _xmlHttp.responseText) {
                        // Change the DIV to reflect our info
                        LoElem.innerHTML = _xmlHttp.responseText;

                        // It worked and we want it repeated
                        if (PsTimeout) {
                            LsFunction = "fillDivFromURL('" + PsURL + "', '" + PsID + "', " + PsTimeout + ")";

                            setTimeout(LsFunction, PsTimeout);
                        }
                    }
                }
                else {
                    alert ("Unknown element: " + PsID);
                }
            };

        _xmlHttp.send(null);
    }
}

function getXMLHTTP() {
    var A = null;

    try {
        A = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
        try {
            A = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc) {
            A = null;
        }
    }

    if (!A && typeof XMLHttpRequest != "undefined") {
        A = new XMLHttpRequest();
    }

    return (A);
}

function testOnload() {
    var LoElem = document.getElementById("mail");

    if (LoElem) {
        getMail();
    }
}
