var ajax = {};
ajax.xhr = {};

String.prototype.trim = function()
{
 return this.replace(/(^\s*)|(\s*$)/gi, "");
}

ajax.xhr.Request = function(url, params, callback, method) {
    this.url = url;
    this.params = params;
    this.callback = callback;
    this.method = method;
    this.send();
}
ajax.xhr.Request.prototype = {
    getXMLHttpRequest: function() {
        if (window.ActiveXObject) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e1) { return null; }
            }
        } else if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else {
            return null;
        }
    },
    send: function() {
        this.req = this.getXMLHttpRequest();

        var httpMethod = this.method ? this.method : 'GET';
        if (httpMethod != 'GET' && httpMethod != 'POST') {
            httpMethod = 'GET';
        }
        var httpParams = (this.params == null || this.params == '') ?
                         null : this.params;

        var httpUrl = this.url;
        if (httpMethod == 'GET' && httpParams != null) {
            httpUrl = httpUrl + "?" + httpParams;
        }

        //alert( "httpUrl" + httpUrl);
        this.req.open(httpMethod, httpUrl, true);
        this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        //this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=EUC-KR');
        //this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
        //this.req.setRequestHeader('Content-Type', 'charset=EUC-KR');
        //this.req.setRequestHeader('Content-Type', 'text/plain;charset=euc-kr');
        var request = this;
        this.req.onreadystatechange = function() {
            request.onStateChange.call(request);
        }
        //alert("PostParams[" + httpParams + "]");
        this.req.send(httpMethod == 'POST' ? httpParams : null);
    },
    onStateChange: function() {
        this.callback(this.req);
    }
}
