/*
 * Ajax library
 *
 * @author Seokhee Choi, dantes98@gmail.com
 * @version 1.1, since 2008/03/20
 * 메소드의 이름 변경
 */

/** 브라우저에 맞게 XmlHttpRequest 를 반환한다. */

function createXmlRequest()
{
	if(window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else
	{
		if(window.XMLHttpRequest)
			return new XMLHttpRequest();
	}
	return null;
}

function $(id)
{
	return document.getElementById(id);
}

function $W(id, content)
{
	var obj = $getId(id);
	if(obj != null)
		obj.innerHTML = content;
}

function $A(id, content)
{
	var obj = $getId(id);
	if(obj != null)
	{
		obj.innerHTML += content;
	}
}

function $getHTML(id)
{
	var obj = $getId(id);
	if(obj != null)
		return obj.innerHTML;
	return null;
}

function $GET(uri, action)
{
	
	var obj = createXmlRequest();
	obj.onreadystatechange = function(){

		// 4 : loaded, 200 : response OK
		if(obj.readyState == 4 && obj.status == 200)
		{
			if(typeof(action) == 'function')
			{
				action(obj.responseText);
			}
			else
			{
				if(typeof(action) == 'string')
				{
					var result = obj.responseText;
					eval(action);
				}
			}
		}
	};
	obj.open('get', uri);
	obj.send(null);
}

