var __XmlHttpPool__ =
{
    m_MaxPoolLength : 10,
    m_XmlHttpPool : [],
    
    __requestObject : function()
    {
        var xmlhttp = null;
        var pool = this.m_XmlHttpPool;
        for ( var i=0 ; i < pool.length ; ++i )
        {
            if ( pool[i].readyState == 4 || pool[i].readyState == 0 )
            {
                xmlhttp = pool[i];
                break;
            }
        }
        if ( xmlhttp == null )
        {
            return this.__extendPool();
        }
        return xmlhttp;
    },
    
    __extendPool : function()
    {
        if ( this.m_XmlHttpPool.length < this.m_MaxPoolLength )
        {
            var xmlhttp = null;
            try //ie
            {
                xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
            }
            catch(e)
            {
                try
                {
                    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
                }
                catch(e2) {}
            }
			if ( xmlhttp == null ){//not ie
				xmlhttp = new XMLHttpRequest();
			}
            if ( xmlhttp )
            {
                this.m_XmlHttpPool.push(xmlhttp);
            }
            return xmlhttp;
        }
    },
    
    GetRemoteData : function(url, callback)
    {
        this.__receiveRemoteData(url, callback, 'GET', null);
    },
    
    PostRemoteData : function(url, callback, data)
    {
        this.__receiveRemoteData(url, callback, 'POST', data);
    },
    
    __receiveRemoteData : function(url, callback, httpmethod, data)
    {
        var xmlhttp = this.__requestObject();
        if ( !xmlhttp )
        {
            return null;
        }
        xmlhttp.open(httpmethod, url, true);
        xmlhttp.onreadystatechange = function()
        {
            if ( xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete' )
            {
                //callback(xmlhttp.responseText);
				callback(xmlhttp.responseXML);
            }
        };
        xmlhttp.send(data);
    }
}; 
