
//********************************************************//
//	XMLHttpRequest
//  작성자 : 정병태
//  작성일 : 2007-01-27
//********************************************************//

var REQ;

// newXMLHttpRequest()
// 새로운 리퀘스트 생성
function newXMLHttpRequest () {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e1) {
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
			}
		}
	}
	return xmlreq;
}

// sendRequest(method,url,param)
// 동기식 리퀘스트 요청
function sendRequest(method,url,param) {
	REQ = newXMLHttpRequest();
	REQ.open(method, url, false);
	REQ.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	REQ.send(param);
}

// sendRequestfunction(method,url,param,func)
// 리퀘스트 요청 후 완료되면 processRequest 함수를 통해 지정된 함수 호출
function sendRequestFunction (method,url,param,func) {
	REQ = newXMLHttpRequest();
	REQ.onreadystatechange = function() {processRequest(func)};
	REQ.open(method, url, true);
	REQ.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	REQ.send(param);
}

// sendRequestHandler(method,url,param,handler)
// 리퀘스트 요청 후 완료되면 지정된 헨들러 호출
function sendRequestHandler (method,url,param,handler) {
	REQ = newXMLHttpRequest();
	REQ.onreadystatechange = handler;
	REQ.open(method, url, true);
	REQ.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	REQ.send(param);
}

// sendRequestHandler(method,url,param,handler)
// sendRequestfunction 함수의 리퀘스트 요청이 완료되면 지정된 함수 호출
function processRequest(func) {
	if (REQ.readyState == 4) {
		if (REQ.status == 200) {
			hideLoading();
			func();
		} else {
			hideLoading();
			alert("There was a problem retrieving the XML data:\n" +
			REQ.statusText);
		}
	} else if(REQ.readyState < 4) {
		showLoading();
	}
}

function showLoading() {
	var roadObj = document.getElementById("boardroading");
	roadObj.style.display = "block";
}

function hideLoading(){
	var  roadObj = document.getElementById("boardroading");
	roadObj.style.display = "none";
}
