﻿function Ajax()
{
	var _xmlHttp;
	var _para="";
	var _handleFunc;
	var _msgWnd=window.createPopup();
	var _Timer;
	this.AddPara=function(str_para)
	{
		_para+=(str_para+"&");
	}
	
	this.SetServerFunc=function(func)
	{
		_handleFunc=func;
	}
	
	this.startRequest=function ()
	{
		_xmlHttp =window.ActiveXObject?(new ActiveXObject("Microsoft.XMLHTTP")):(new XMLHttpRequest());
		_xmlHttp.onreadystatechange = handleStateChange;
		_para+=("Rnd="+Math.random());
		try{
			if(this.method=="POST")
			{
				_xmlHttp.open(this.method,this.requestPage, true);
				_xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				_xmlHttp.send(_para);
			}else{
				_xmlHttp.open(this.method, this.requestPage+"?"+_para, true);
				_xmlHttp.send(null);
			}
			_Timer=setTimeout(showMsgWnd, 500 )
		}catch(exception){
			alert("Page Not Exist!");
		}
	}

	showMsgWnd=function()
	{
		_msgWnd.document.body.innerHTML="数据请求中...";
		_msgWnd.show(screen.width/2-150,screen.height/2,150,40);
	}
	
	handleStateChange=function(){	
		if(_xmlHttp.readyState == 4){	
			clearTimeout(_Timer);
			_msgWnd.hide();
			if (_xmlHttp.status == 200 || _xmlHttp.status == 0){
				if(_handleFunc)
				{
					_handleFunc(_xmlHttp.responseXML);
				}
			}else if(_xmlHttp.status == 500)
			{
				alert("Server Err");
			}
		}
	}
	
}

Ajax.prototype.requestPage=null;
Ajax.prototype.method="GET";