function XMLProxy()
{
	this.isAsync = false;//是否异步，默认同步
	this.xmlhttp = null;//传输协议
	this.xmlDoc = null;//XML文档
	this.method = "post";//提交方式
	
	this.initProxy = function()
	{
		this.xmlDoc = new ActiveXObject("MSXML2.DOMDOCUMENT");
		this.xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
	};
	
	this.onGetResponse = function(xmldocument)
	{
		//TODO:未实现
	};
	
	this.send = function(url,data)
	{		
		this.xmlhttp.Open(this.method,url,this.isAsync);	
		this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		
		if(!this.isAsync)//若为同步
		{
			this.xmlhttp.send(data);
			var Res = this.xmlhttp.responseText;
			Res = Res.replace(/&#x0;/g,"");
			this.xmlDoc.loadXML(Res);			
			return this.xmlDoc;
		}
		else//若为异步
		{
			var proxy = this;
			this.xmlhttp.onreadystatechange = function()
			{
				if(proxy.xmlhttp.readyState == 4)
				{
					var Res = proxy.xmlhttp.responseText;
					Res = Res.replace(/&#x0;/g," ");
					Res = Res.replace(/&#xc;/g," ");
					proxy.xmlDoc.loadXML(Res);
					proxy.onGetResponse(proxy.xmlDoc);
				}      									
			}
			
			this.xmlhttp.send(data);
		}
	};
	
	this.initProxy();	
}

function getMsgCtn(_actionId)
{
	var xmlDoc = new ActiveXObject("MSXML2.DOMDOCUMENT");
	xmlDoc.async = false;
	xmlDoc.loadXML("<message type=\"request\" actionId=\""+_actionId+"\"></message>");
	return xmlDoc;
}

//检查resultSet中的errorCode和ErrorMessage，并显示
//showMsgFlag value:
//0:show both error and successs message
//1:only show error message
//2:only show success message
//3: no message will be shown
function checkResponse(xmlDom,showMsgFlag,showXml)
{
	if(showXml != undefined && showXml == 1)
	{		
		window.top.location.href="../Mindex.aspx";
	}
		
	if(showMsgFlag == undefined)
	{
		showMsgFlag = 0;
	}

	if(xmlDom.xml == "")
	{
		//alert("服务器没有响应");
		return "XXXX";
	}
	
	var node = xmlDom.selectSingleNode("//message/resultSet");
	if(node == null)
	{
		alert("返回数据报文不完整！");
		return "XXXX";
	}
	
	try
	{
		if(node.getAttribute("errorFlag") == "7777")
		{
			//alert("您还没有登陆，或者过长时间没有操作\r\n请重新登陆");
			window.top.location.href="index.aspx";
			return;
		}		
		if((showMsgFlag == 0 || showMsgFlag == 1) && node.getAttribute("errorFlag") != "0000")
		{
			if(node.getAttribute("errorMessage") == "你还没有登录系统，请登录！")
			{
				window.top.location.href="../Mindex.aspx";				
			}
			else 
			{
				if(node.getAttribute("errorFlag") == "1004" || node.getAttribute("errorFlag") == "1002" || node.getAttribute("errorFlag") == "1003")
				{
					//
				}
				else
				{
					alert("系统错误：["+node.getAttribute("errorFlag")+"]"+node.getAttribute("errorMessage"));
				}
			}
			
		}		
		else if((showMsgFlag == 0 || showMsgFlag == 2) && xmlDom.documentElement.childNodes.length >= 1)
		{
			alert(node.getAttribute("errorMessage"));
			//window.top.location.href="../Mindex.aspx";
		}
	}
	catch(e)
	{
		alert("获取resultSet数据错误！");
		return "XXXX";
	}
	
	return node.getAttribute("errorFlag");	
}

//检查resultSet中的errorCode和ErrorMessage，并显示
function checkErrFlag(xmlDom,showMsg)
{
	return checkResponse(xmlDom,showMsg);	
}

//模糊查询 正则表达式 匹配符
function ReplaceSS(ss)
{
  var r, re;
 // var ss = "The   quick brown fox jumped fox the fox yellow fox.";
  re = / +/g;
  r = ss.replace(re, "%");
  return(r);
}

function ReplaceXml(xmlDoc)
{
	var re = /&lt;+/g;
	xmlDoc = xmlDoc.replace(re,"<");
	re = /&gt;+/g;
	xmlDoc = xmlDoc.replace(re,">");
	re = /&quot;+/g;
	xmlDoc = xmlDoc.replace(re,"\"");
	
	return xmlDoc;
}






