/*
    General JS functions
*/

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

function fillDivFromURL(PsURL, PsID) {
    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) {
        LoElem.innerHTML = "<span style='color: orange;'>Testing...</span>";

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

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

                    // It worked and we want it repeated
                    iNumTesting--;
                    addTester();
                }
            };

        _xmlHttp.send(null);
    }
}

function addTester() {
    if (arProxTest.length > iNowTesting && iNumTesting < 8) {
        fillDivFromURL("/proxycheck.php?LIVE=1&IP=" + arProxTest[iNowTesting][1] + "&PORT=" + arProxTest[iNowTesting][2], "prox" + arProxTest[iNowTesting][0]);
        iNumTesting++;
        iNowTesting++;
        
        addTester();
    }
}

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);
}