//AJAX 공통함수 
var httpRequest = null;
var httpRequest2 = null;
var httpRequest3 = null;
var httpRequest4 = 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;
	}
}
/***************************************************
//AJAX 공통함수 
//파라메터 
1. url : 실행할 URL
2. params : URL에 같이 보낼 파라메터
3. callback : 데이터를 받은 후에 실행될 콜백 함수
4. method : GET/POST
5. sync : true/false = 동기/비동기 방식 선택
***************************************************/
function sendRequest(url, params, callback, method, sync) {
	httpRequest = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';
	if (httpMethod != 'GET' && httpMethod != 'POST') {	httpMethod = 'GET';	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if (httpMethod == 'GET' && httpParams != null) 	httpUrl = httpUrl + "?" + httpParams;
	//sync 인자가 true이면 AJAX 통신이 끝나기 전에 다음 코드가 실행되고 False 이면 AJAX 통신이 끝난 후에 다음 코드를 실행 한다.
	httpRequest.open(httpMethod, httpUrl, sync);
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	//응답이 있을때마다 callback 함수가 호출된다.
	httpRequest.onreadystatechange = callback;
	httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}

function sendRequest2(url, params, callback, method, sync) {
	httpRequest2 = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';
	if (httpMethod != 'GET' && httpMethod != 'POST') {	httpMethod = 'GET';	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if (httpMethod == 'GET' && httpParams != null) 	httpUrl = httpUrl + "?" + httpParams;
	//sync 인자가 true이면 AJAX 통신이 끝나기 전에 다음 코드가 실행되고 False 이면 AJAX 통신이 끝난 후에 다음 코드를 실행 한다.
	httpRequest2.open(httpMethod, httpUrl, sync);
	httpRequest2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	//응답이 있을때마다 callback 함수가 호출된다.
	httpRequest2.onreadystatechange = callback;
	httpRequest2.send(httpMethod == 'POST' ? httpParams : null);
}

function sendRequest3(url, params, callback, method, sync) {
	httpRequest3 = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';
	if (httpMethod != 'GET' && httpMethod != 'POST') {	httpMethod = 'GET';	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if (httpMethod == 'GET' && httpParams != null) 	httpUrl = httpUrl + "?" + httpParams;
	//sync 인자가 true이면 AJAX 통신이 끝나기 전에 다음 코드가 실행되고 False 이면 AJAX 통신이 끝난 후에 다음 코드를 실행 한다.
	httpRequest3.open(httpMethod, httpUrl, sync);
	httpRequest3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	//응답이 있을때마다 callback 함수가 호출된다.
	httpRequest3.onreadystatechange = callback;
	httpRequest3.send(httpMethod == 'POST' ? httpParams : null);
}

function sendRequest4(url, params, callback, method, sync) {
	httpRequest4 = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';
	if (httpMethod != 'GET' && httpMethod != 'POST') {	httpMethod = 'GET';	}
	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if (httpMethod == 'GET' && httpParams != null) 	httpUrl = httpUrl + "?" + httpParams;
	//sync 인자가 true이면 AJAX 통신이 끝나기 전에 다음 코드가 실행되고 False 이면 AJAX 통신이 끝난 후에 다음 코드를 실행 한다.
	httpRequest4.open(httpMethod, httpUrl, sync);
	httpRequest4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	//응답이 있을때마다 callback 함수가 호출된다.
	httpRequest4.onreadystatechange = callback;
	httpRequest4.send(httpMethod == 'POST' ? httpParams : null);
}

//AJAX 요청 샘플
function exampleAjaxRequest() {
	var url = "/pages/ajax/numberRequest.html";
	var params = "phoneNum="+phoneNum+"&regNo="+regNo+"&telecom="+telecom;
	sendRequest(url, params, exampleCallBackFunction, "POST", false);
}
//AJAX 콜백 함수 샘플
function exampleAjaxCallBack() {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {			completeDiv.innerHTML=httpRequest.responseText.trim();	}
		else if (httpRequest.status == 204){		completeDiv.innerHTML="";								}//데이터가 존재하지 않을 경우
	}
}