var ajax = new Object();
ajax.xhr = new Object();

//var ajax = {};
//ajax.xhr = {};

// Request Å¬·¡½ºÀÇ »ý¼ºÀÚ (°´Ã¼ÀÇ »ý¼º°ú µ¿½Ã¿¡ send() ÇÔ¼ö¸¦ È£Ãâ
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.5.0");
			}
			catch (e)
			{
				try
				{
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e1)
				{
					return null;
				}
			}
		}
		else if(window.XMLHttpRequest)
		{
			return new XMLHttpRequest();
		}
		else
		{
			return null;
		}
	},

	send : function()
	{
		// req ÇÁ·ÎÆÛÆ¼¿¡ XMLHttpRequest °´Ã¼¸¦ ÀúÀå
		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;
		}

		this.req.open(httpMethod,httpUrl,true);
		this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		var request = this;
		// XMLHttpRequest °´Ã¼ÀÇ readyState °ªÀÌ ¹Ù²ð ¶§
		// ÀÌ°´Ã¼(Request °´Ã¼)ÀÇ onStateChange ÇÔ¼ö È£Ãâ
		this.req.onreadystatechange = function()
		{
			request.onStateChange.call(request);
		}

		this.req.send(httpMethod == 'POST' ? httpParams : null);

	},
	
	// ÀÌ°´Ã¼ÀÇ callback ÇÁ·ÎÆÛÆ¼¿¡ ÇÒ´çµÈ ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù.
	// ÀÌ¶§ ÀÎÀÚ·Î this.req °´Ã¼¸¦(XMLHttpRequest °´Ã¼¸¦) Àü´ÞÇÑ´Ù.
	onStateChange : function()
	{
		this.callback(this.req);
	}

}