/*-----Ajax_V2.01版本（多浏览器支持）-----
* 作者：袁琳(monkey-lin@163.com)
*
* 功能说明：AJAX核心程序，支持IE、Firefox、Opera。
*
* 版本说明：
* 
* ·修改为需要调用ajax.send()方法才可以执行发送
* 
* ·调试信息可正常使用
*
* ·可自定义返回函数名称（a或B.a）
*****************************************/
var Ajax=function(){
	
	//--------内部配制参数--------
	this.localhost	="/";					//设置URL参数总地址（默认为网站绝对地址）
	this.setType	=true;					//设置传输方式（true：异步 false：同步）
	this.pageCode	="gb2312";				//字符编码
	this.method		="GET";					//传送方式（GET/POST）
	
	//----SOAP及POST参数----
	this.webMethod	=null;					//Soap参数：Web方法（不为空时开启SOAP发送方式）
	this.argObj		=null;					//参数对象（Soap对象及Post）
	
	//----调试参数----
	this.isDebug	=false;					//设置是否开启[错误调试]
	this.showState	=true;					//设置是否开启[动态数据获取]提示
	
	//----外部调用通用参数----
	this.rtnFunObj	=null;					//设置返回处理XML的函数对象
	this.rtnFunName	=null;					//设置返回处理XML的函数名
	this.url		=null;					//相对地址及参数
	this.showObj	=null;					//显示提示的对象
	this.Outurl=null;						//外部链接不加localhost
}

	//**********发送XML数据请求**********//
    Ajax.prototype.send=function(){
		var XMLRequest 	=this.createXMLRequest();
		var showState	=this.showState;
		var isDebug		=this.isDebug;
		var url			=this.url;
		var showObj		=this.showObj;
		var rtnFunObj	=this.rtnFunObj;
		var rtnFunName	=this.rtnFunName;
		var Outurl   =this.Outurl;
		XMLRequest.onreadystatechange = function(){
			
			//判断信息返回状态
			if(XMLRequest.readyState<4){
				if(showState){checkState(showObj);}
				
			//------信息返回成功------	
			}else if(XMLRequest.readyState==4){			
				if(XMLRequest.status == 200){
					if(rtnFunObj!=null&&rtnFunName!=null){
						rtnFunObj.returnFunction=rtnFunName;
						rtnFunObj.returnFunction(XMLRequest.responseXML);
					}else if(rtnFunName!=null){
						rtnFunName(XMLRequest.responseXML);
					}
				//------页面不正常------
				}else{
					if(isDebug){alert("您所请求的页面["+url+"]有异常。");}
				}
			}
		}
		if(this.Outurl!=null)
		{
			XMLRequest.open(this.method,this.Outurl,this.setType);
		}
		else
		{
			XMLRequest.open(this.method,this.localhost+this.url,this.setType);
		}
		XMLRequest.setRequestHeader("Content-Type", "text/xml;charset="+this.pageCode);	
		XMLRequest.setRequestHeader("If-Modified-Since","0");
		if(this.isDebug){prompt("[错误调试已开启]下面是出错的地址信息",this.url);}
		XMLRequest.send(this.argObj);
	}
	
	//**********创建XMLHttpRequest对象**********//
	Ajax.prototype.createXMLRequest=function(){
	
		//初始化、指定处理函数、发送请求的函数
		var http_request = false;
		
		//开始初始化XMLHttpRequest 对象
		if(window.XMLHttpRequest){
			
			//Mozilla 浏览器
			http_request = new XMLHttpRequest();
			if(http_request.overrideMimeType){
				
				//设置MiME 类别
				http_request.overrideMimeType("text/xml");
			}
			
		// IE 浏览器选择XML版本
		}else if(window.ActiveXObject){ 
			try{//------ 创建XML3.0版本
				http_request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
			}catch(e){
				try{//------创建XML2.0版本
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e){
					try{//------创建XML1.0版本
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){}
				}
			}
		}
		if(!http_request){ 
		
			//----异常，创建对象实例失败
			alert("不能创建XMLHttpRequest 对象实例.");
			return false;
		}else{
			return http_request;
		}
	}

	//**********设置状态提示信息**********
	function checkState(docContent){
		docContent.innerHTML="<table width='100%' cellpadding='0' cellspacing='0'>";
		docContent.innerHTML+="<tr><td align='center' valign='middle'>数据读取中...</td></tr></table>";
	}
