/* copyright by nece001@163.com */

var Ajax = {
	'xmhr' : null,
    'create' : function()
    {
		if(this.xmhr != null) return this.xmhr;
        if(typeof XMLHttpRequest!='undefined')// other browser
        {
          this.xmhr = new XMLHttpRequest();
		  return this.xmhr;
        }
        else if(document.all)// ie browser
        {
            var versions=['MSXML2.XMLHttp.5.0','MSXML2.XMLHttp.4.0','MSXML2.XMLHttp.3.0','MSXML2.XMLHttp','Microsoft.XMLHttp'];
            for(var i=0;i<versions.length;i++)
            {
               try
               {
                    var request = new ActiveXObject(versions[i]);
                    this.xmhr = request;
					return this.xmhr;
               }
               catch(ex){}
            }
        }
        throw new Error('could not create XMLHTTP object');
    },
    
    'post' : function(u,h,d)
    {
        var a = this.create();
        try{
			a.open('post',encodeURI(u),true);
			a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			a.setRequestHeader('Content-Length',d.length);
			a.setRequestHeader('Connection','Close');
			a.onreadystatechange = function()
			{
				if(a.readyState == 4)
				{
					if(a.status == 200)
					{
						h(a);
					}
				}
			};
			a.send(d);
        }catch(e)
        {
			alert(e.message);
        }
    },
    
    'get' : function(u,h)
    {
        var a = this.create();
        try{
			a.open('get',encodeURI(u),true);
			a.onreadystatechange = function()
			{
				if(a.readyState == 4)
				{
					if(a.status == 200)
					{
						h(a);
					}
				}
			};
			a.send(null);
        }catch(e)
        {
			alert(e);
        }
    }
}