// Ready state: 0 -- uninitialized, 1 -- loading, 2 -- loaded, 3 -- interactive, 4 -- complete
// Status: 200 -- OK, 404 -- Not Found, and so on...
//var xmlHttpRequest;

function createXMLHTTPRequest() {
	var xmlHttp = null;
	if (window.XMLHttpRequest) {
//		alert('make XMLHttpRequest-object');
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
//			alert('make ActiveXObject:Microsoft.XMLHTTP-object');
//			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
//			xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
//			alert('DEBUG-333');
		} catch(ex) {
			xmlHttp = null;
		}
	}
//	alert('createXMLHTTPRequest(): xmlHttp: ' + xmlHttp);
	return xmlHttp;
}


function callbackXML() {
//	alert('default-callback: empty');
//	if (xmlHttp != null && xmlHttp.readyState == 4) {
//		if (xmlHttp.status == 200) {
//			// return xml-response
//			alert('default-callback function!!!');
//			return xmlHttp.responseXML;
//		}
//	}
//	return null;
}

function requestPOST(url, content) {
	if (content == null) return requestGET(url);
	return requestPOST(url, content, callbackXML);
}

function requestPOST(url, content, fncCallBack) {
	if (content == null) return requestGET(url, asynch);
	return requestPOST(url, content, fncCallBack, null);
}

function requestPOST(url, content, fncCallBack, asynch) {
	if (content == null) return requestGET(url, asynch, fncCallBack);
	var xmlHttp = createXMLHTTPRequest();
//	alert('requestPOST(url="'+url+'", content="'+content+'", asynch='+asynch+': xmlHttp is null? ' + (xmlHttp == null));
	if (xmlHttp != null) {
		if (asynch == null) xmlHttp.open("POST", url, true);
		else xmlHttp.open("POST", url, asynch);
//		alert('requestPOST("'+url+'", content="'+content+'"');
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = fncCallBack;
		xmlHttp.send(content);
//		alert('requestPOST(): send...');
	}
//	xmlHttpRequest = xmlHttp;
	return xmlHttp;
}

function requestGET(url) {
	return requestGET(request, url, callbackXML);
}

function requestGET(url, fncCallBack) {
	return requestGET(url, fncCallBack, true);
}

function requestGET(url, fncCallBack, asynch) {
	var xmlHttp = createXMLHTTPRequest();
//	alert('requestGET(url="'+url+'", asynch='+asynch+': xmlHttp is null? ' + (xmlHttp == null));
	if (xmlHttp != null) {
		if (asynch == null) asynch = true;
		xmlHttp.open("GET", url, asynch);
		xmlHttp.onreadystatechange = fncCallBack;
		xmlHttp.send(null);
	}
//	xmlHttpRequest = xmlHttp;
	return xmlHttp;
}