// ========== REQUEST ====================================================================================================

var Request = new Object();

Request.send = function(url, method, callback, data, urlencoded) {
    var req;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status < 400) {// only if "OK"
                (method=="POST") ? callback(req) : callback(req,data);
            } else {
				var err = window.open("","","width=500,height=500");
				err.document.write("["+url+","+data+"]\n"+req.responseText);
                alert(" There was a problem loading data :\n" + req.status+ "/" + req.statusText);
            }
        }
    }
    if (method=="POST") {
        req.open("POST", url, true);
        if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.send(data);
    } else {
        req.open("GET", url, true);
        req.send(null);
    }
    return req;
}

Request.sendPOST = function(url, data, callback) {
    Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
    return Request.send(url, "GET", callback, args);
}