﻿function EHttpRequest(fCallSuccessback, fCallFailback, mode, restype) {
	this.m_HttpRequest = createXMLHttpRequest();
	this.m_bAsyncFlag = mode;
	if (restype) this.m_iResType = restype;
	else this.m_iResType = 2;
	this.Post = EHttpRequest_Post;
	this.Get = EHttpRequest_Get;
	this.m_fCallSuccessback = fCallSuccessback;
	this.m_fCallFailback = fCallFailback;
};
function EHttpRequest_Get(dst, para) {
	var now = new Date();
	var rnd = Math.floor(Math.random() * 100000);
	var ptm = now.getSeconds().toString() + rnd.toString() + now.getMinutes().toString();
	para += "&ptrm=" + ptm.toString();
	var http = this;
	function tm_back() {
		if (http.m_HttpRequest.readyState == 4) {
			if (http.m_HttpRequest.status == 200) {
				if (http.m_iResType == 1) http.m_fCallSuccessback(http.m_HttpRequest.responseText);
				else http.m_fCallSuccessback(http.m_HttpRequest.responseXML);
			} else {
				http.m_fCallFailback(4, http.m_HttpRequest.status);
			};
		} else {
			http.m_fCallFailback(http.m_HttpRequest.readyState);
		};
	};
	if (this.m_HttpRequest == undefined) {
		this.m_HttpRequest = createXMLHttpRequest();
	};
	this.m_HttpRequest.onreadystatechange = tm_back;
	this.m_HttpRequest.open("GET", dst + "?" + para, this.m_bAsyncFlag);
	this.m_HttpRequest.setRequestHeader("Content_Type", "application/x-www-form-urlencoded;charset=utf-8");
	this.m_HttpRequest.setRequestHeader("Cache-Control", "no-cache");
	this.m_HttpRequest.send("");
};
function EHttpRequest_Post(dst, para) {
	var http = this;
	function tm_back() {
		if (http.m_HttpRequest.readyState == 4) {
			if (http.m_HttpRequest.status == 200) {
				if (http.m_iResType == 1) http.m_fCallSuccessback(http.m_HttpRequest.responseText);
				else http.m_fCallSuccessback(http.m_HttpRequest.responseXML);
			} else {
				http.m_fCallFailback(4, http.m_HttpRequest.status);
			};
		} else {
			http.m_fCallFailback(4, http.m_HttpRequest.status);
		};
	};
	this.m_HttpRequest.onreadystatechange = tm_back;
	this.m_HttpRequest.open("POST", dst, this.m_bAsyncFlag);
	this.m_HttpRequest.setRequestHeader("Content_Length", para.length);
	this.m_HttpRequest.setRequestHeader("Content_Type", "application/x-www-form-urlencoded;charset=utf-8");
	this.m_HttpRequest.send(para);
};
function getXMLPrefix() {
	if (getXMLPrefix.prefix) return getXMLPrefix.prefix;
	var prefixes = ["MSXML3", "MSXML2", "MSXML", "Microsoft"];
	var obj, obj2;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			obj = new ActiveXObject(prefixes[i] + ".XmlHttp");
			return getXMLPrefix.prefix = prefixes[i];
		} catch(ex) {};
	};
	throw new Error('您没有安装XML解析器,请使用INTERNET EXPLORE 5以上的浏览器.');
};
function createXMLHttpRequest() {
	var j = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
	var k = null;
	try {
		k = new XMLHttpRequest()
	} catch(e) {
		for (var m = 0; m < j.length; m++) try {
			k = new ActiveXObject(j[m]);
			break;
		} catch(e) {
			alert(e.message + 'error');
		};
	};
	if (k != null) return k;
	else return false;
};
