/** ABC - Ajax Basic Call
 * @author  Andrea Giammarchi
 * @site        www.devpro.it */
ABC = (function(ABC){
    return  function(data, url, async, user, pass){
        var time    = new Date,
            abc     = ABC(),
            send    = [],
            key     = null;
        if(data){
            for(key in data)
                if(typeof data[key] !== "function" && data.hasOwnProperty(key)){
                    if(data[key] instanceof Array)
                        for(var i = 0; i < data[key].length; i++)
                            send.push(encodeURIComponent(key).concat("[]=", encodeURIComponent(data[key][i])));
                    else
                        send.push(encodeURIComponent(key).concat("=", encodeURIComponent(data[key])));
                }
            key = 0 < send.length ? send.join("&") : null;
        };
        abc.open(
            key !== null ? "POST" : "GET",
            url,
            async = async === undefined ? true : !!async,
            user !== undefined && user,
            pass !== undefined && pass
        );
        abc.setRequestHeader("If-Modified-Since", "Mon, 26 Jul 1997 05:00:00 GMT");
        abc.setRequestHeader("Cache-Control", "no-cache");
        abc.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        if(key !== null)
            abc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        if(async)
            abc.onreadystatechange= function(){
                if(abc.readyState === 4 && data){
                    key = /^(2|3)[0-9]{2}$/.test(abc.status) ? "onLoad" : "onError";
                    if(typeof data[key] === "function")
                        data[key](abc, new Date - time);
                }
            };
        abc.send(key);
        return  abc;
    };
})(this.XMLHttpRequest ?
    function(){return new XMLHttpRequest;} :
    function(){return new ActiveXObject("Microsoft.XMLHTTP");}
);
