var xmlHttp = false;
try {
	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		xmlHttp = false;
	}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}

function asynSubmit(url, data, submit_method, processResponse) {
	xmlHttp.open(submit_method.toUpperCase(),
			submit_method.toUpperCase() == "GET" ? encodeURI(url + "?" + data)
					: url, true);
	xmlHttp.onreadystatechange = processResponse;
	xmlHttp.setRequestHeader("Cache-Control", "no-cache");
	if (submit_method.toUpperCase() == "POST") {
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.send(encodeURI(data));
	} else
		xmlHttp.send(null);
}

function asynSubmit(url, data, submit_method, callbackMethod, params) {
	xmlHttp.open(submit_method.toUpperCase(),
			submit_method.toUpperCase() == "GET" ? encodeURI(url + "?" + data)
					: url, true);
	xmlHttp.onreadystatechange = function() {
		processResponse(callbackMethod, params);
	};
	xmlHttp.setRequestHeader("Cache-Control", "no-cache");
	if (submit_method.toUpperCase() == "POST") {
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.send(encodeURI(data));
	} else
		xmlHttp.send(null);
}

function processResponse(callbackMethod, params) {
	if (xmlHttp.readyState == 4)
		eval(callbackMethod)(params);
}

function generateAJAXResponseHTML(domNodes) {
	var nodeHtml = '';
	for ( var i = 0; i < domNodes.length; i++) {
		nodeHtml += domNodes[i].nodeValue;
	}
	return nodeHtml;
}

function processError(status, response) {

	var msg;

	if (status == 404)
		msg = "对不起，您所访问的页面不存在或已经被删除！";
	else if (status == 500)
		msg = "内部错误调试中，请稍后再试！";
	else if (status == 403)
		location.href = '/user/login';
	else {
		eval(response);
		msg = error_message;
	}
	show_error(msg);
}

function getErrorMessage(status, response) {

	var msg;

	if (status == 404)
		msg = "对不起，您所访问的页面不存在或已经被删除！";
	else if (status == 500)
		msg = "内部错误调试中，请稍后再试！";
	else if (status == 403)
		location.href = '/user/login';
	else {
		eval(response);
		msg = error_message;
	}
	return msg;
}

function initVarMap(varMap) {
	var data = "";
	if (varMap && null != varMap) {
		for ( var name in varMap) {
			if (varMap[name] != null) {
				if (data == "")
					data = name + '=' + varMap[name];
				else
					data += '&' + name + '=' + varMap[name];
			}
		}
	}
	return data;
}
