(function() {
    var currentHandler = window.onerror;
    window.onerror = function(e, file, line) {
        var hash = getHash(e, file, line);
        if (containsHash(hash))
            return false;

        addHash(hash);
        var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
        xhr.open('POST', 'report_client_error.spbin');
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.setRequestHeader("ClientLogger", "true");
        xhr.send(params({ message: e, file_path: file, line: line }));

        if (currentHandler) {
            currentHandler();
        }
        return false;
    }

    var globalHash = [];

    function getHash(e, file, line) {
        return e.toString() + file.toString() + line.toString();
    }

    function addHash(hash) {
        globalHash[hash] = true;
    }

    function containsHash(hash) {
        return globalHash[hash];
    }

    function params(a) {
        var s = [];

        for (var j in a) {
            s.push(encodeURIComponent(j) + "=" + encodeURIComponent(a[j]));
        }
        // Return the resulting serialization
        return s.join("&").replace(/%20/g, "+");
    }


})();




// xhr.send('error=' + e + ';file=' + file + ";line=" + line);
