﻿// JScript File
HthzAjaxNoAnsy=function(url)
{
    var m_xmlReq=null;
    if(window.ActiveXObject)
    {
        try 
        {
            m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); 
        }
        catch(e)
        {
            try{m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
        }
    }
    else if(window.XMLHttpRequest)
    {
        m_xmlReq = new XMLHttpRequest();
    }
	
    this.post=function(d)
    {
        if(!m_xmlReq)  return;
        m_xmlReq.open('POST',url,false);
        m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
        m_xmlReq.send(d);
        return eval(m_xmlReq.responseText);
    }
}

var HthzAjax=Class.create();
HthzAjax.prototype = {
    initialize: function() {
        this.RequestUrl='';//请求的页面地址。
        this.Method='post';
        this.Encoding='UTF-8';
        
        this.ServerError=function(req){};
        this.ClientError=function(req,errobj){};
        this.ReceiveContent=function(req){};
        this.RegisteronCreate=function(req){};
        this.MyRegisteronComplete=function(req){};
        
        this.rnd=Math.random();//取随机数。
        
        this.GlobalHandlers={
          onCreate:this.RegisteronCreate,
          onComplete:this.MyRegisteronComplete
        };
		Ajax.Responders.register(this.GlobalHandlers);
	},
	
	SendUpdate:function(objId,pars)
	{
	    this.rnd++;
        var sendpars = [];
        
        if(pars != null){
            sendpars[sendpars.length]=Object.toQueryString(pars);
            sendpars[sendpars.length]='&'; 
        }
        sendpars[sendpars.length] = 'Session=';
        sendpars[sendpars.length] =this.rnd;
        
        new Ajax.Updater(
            {success:objId},
            this.RequestUrl,
            {
                method: this.Method,
                encoding:this.Encoding,
                parameters: sendpars.join(""),
                onFailure: this.ServerError,
                onException: this.ClientError,
                evalScripts: true
            }
        );
	},
	
	SendData:function(pars)
	{
        this.rnd++;
        var sendpars = [];
        
        if(pars != null){
            sendpars[sendpars.length]=Object.toQueryString(pars);
            sendpars[sendpars.length]='&'; 
        }
        sendpars[sendpars.length] = 'Session=';
        sendpars[sendpars.length] =this.rnd;
        new Ajax.Request(
            this.RequestUrl,
            {
                method: this.Method,
                encoding:this.Encoding,
                parameters: sendpars.join(""),
                onSuccess: this.ReceiveContent,
                onFailure: this.ServerError,
                onException: this.ClientError
            }
        );
    }
};

//发送数据方法
/*HthzAjax.prototype.SendUpdate=function(objId,pars){
    this.rnd++;
    var sendpars = [];
    
    if(pars != null){
        sendpars[sendpars.length]=Object.toQueryString(pars);
        sendpars[sendpars.length]='&'; 
    }
    sendpars[sendpars.length] = 'Session=';
    sendpars[sendpars.length] =this.rnd;
    
    new Ajax.Updater(
        {success:objId},
        this.RequestUrl,
        {
            method: "post",
            encoding:this.Encoding, 
            parameters: sendpars.join(""),
            onFailure: this.ServerError,
            onException: this.ClientError,
            evalScripts: true
        }
    );
}

HthzAjax.prototype.SendData=function(pars){
    this.rnd++;
    var sendpars = [];
    
    if(pars != null){
        sendpars[sendpars.length]=Object.toQueryString(pars);
        sendpars[sendpars.length]='&'; 
    }
    sendpars[sendpars.length] = 'Session=';
    sendpars[sendpars.length] =this.rnd;
    new Ajax.Request(
        this.RequestUrl,
        {
            method: "post",
            encoding:this.Encoding,
            parameters: sendpars.join(""),
            onSuccess: this.ReceiveContent,
            onFailure: this.ServerError,
            onException: this.ClientError
        }
    );
}
*/