/***********************************************************
*  xhttp module [FHL] : do not edit this function  *
***********************************************************/
if (typeof(rstVal) == 'undefined') {
	var rstVal = null; //data
}
if (typeof(rstMsg) == 'undefined') {
	var rstMsg = null; //msg
}

function setXHR(method, url, async, uid, pwd, docType,isJson, params, callback){
	//method:(GET,POST), url:address, async:(true,false), uid:user id, pwd:user pwd, params : parameter, isJason : (true,false), callback : process function
	var resType = "responseText";
	if(docType == "xml") resType = "responseXML";
	if(params == "") params = null;
	if(async == "") async = true;
	//alert("function is called with parameters : " + params);
	var xObj = {
		xhttp:null,
		create:function() {
			try{
				if (window.XMLHttpRequest) {
					xObj.xhttp = new XMLHttpRequest();
					if (docType == 'xml' && xObj.xhttp.overrideMimeType) {
						xObj.xhttp.overrideMimeType('text/xml');
					}
				} else if (window.ActiveXObject){
					xObj.xhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} catch(e) {
				alert(e);
			}
			/** set handler **/
			xObj.baseCallBack = function(arg){//base handler
				alert("[has no callback function]\r\n" + arg);
			}			
			if (callback) {
				xObj.setResult = callback;
			} else {
				xObj.setResult = xObj.baseCallBack;	
			}
		},
		//force to abort
		timer:window.setTimeout( function() {xObj.xhttp.abort();}, 25000 )
	}
	xObj.create();
	//alert("run : " + url);
	try {xObj.xhttp.open(method,url,async);} catch(err) {alert("xhttp open : " + err);return;}
	
	if (xObj.xhttp != null) {
		xObj.xhttp.onreadystatechange = function() {
			
			if (xObj.xhttp.readyState == 4) {
				clearTimeout(xObj.timer);
				if (xObj.xhttp.status == 200) {					
					
					if (docType == 'xml' && app==0) {
						if(window.ActiveXObject) xObj.xhttp[resType].loadXML(xObj.xhttp.responseText);
					}
					if (isJson) {
						try {
							xObj.setResult( eval("("+xObj.xhttp[resType]+")") );
							//alert(xObj.xhttp[resType]);
						} catch (err) {
							//alert("isJson : " + err);
							return;
						}
					} else {xObj.setResult(xObj.xhttp[resType]);}
				} else {
					var isErrCode = xObj.xhttp.status;
					if (isErrCode == 403) {
						alert("access denied.  ");
						xObj.setResult(null);
					} else if (isErrCode == 404) {
						alert("file is not found  ");
						xObj.setResult(null);
					} else {//aboart
						//alert("Error while loading : [code : "+ isErrCode +"]");
						xObj.setResult(null);
						//delete xObj.xhttp;
					}
				}
			}
		}
	} else {
		alert('XMLHTTP Object is null');
		return;
	}

	if (method == "POST") xObj.xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	//if(method == "POST") xObj.xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	//try {xObj.xhttp.send(params);} catch(err){alert(err);}
	try {xObj.xhttp.send(params);} catch(err) {alert("send prams : " + err);}
}
