var httpRequest = null;
var callBackFunction = null;

function getXMLHttpRequest()
{
	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;
	}
}

function ajax_request(url, params, inicallBack)
{
	var method = "POST"
	httpRequest = getXMLHttpRequest();
	var httpMethod = method ? method : 'POST';
	if (httpMethod != 'GET' && httpMethod != 'POST') {
		httpMethod = 'POST';
	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;

	if (httpMethod == 'GET' && httpParams != null) {
		httpUrl = httpUrl + "?" + httpParams;
	}

	callBackFunction = inicallBack;

	httpRequest.onreadystatechange = callResultFunction;
	httpRequest.open(httpMethod, httpUrl, true);
	httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
	httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}

function callResultFunction() {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			callBackFunction(httpRequest.responseText);
		} else {
			alert("Error Code "+ httpRequest.status);
		}
	}
}
/*
readyState
0: open()함수가 아직 호출되지 않은 상태
1: send()함수가 아직 호출되지 않은 상태
2: send()가 끝난 상태(IE에서는 아직 헤더와 status를 사용할 수 없다)
3: receiving-처리중(IE에서는 아직 데이터를 제대로 받을 수 없는 상태)
4: loaded-모든 데이터를 받을 수 있는 상태

responseText: 응답 데이터를 문자열로 저장하는 속성
responseXML: 응답 테이터를 XML(DOM)형식으로 저장하는 속성

status:서버로부터 응답받은 HTTP 상태코드
200: 정상(OK)
400: Page Not Found - 클라이언트의 잘못된 요청
500: Internal Server Error - 서버측 오류
*/
