﻿function createXmlHttpRequest()
{
    //check to see if we have a native XMLHttpRequest type

    //this means we are dealing with a non-MS based browser.
    if(typeof XMLHttpRequest != "undefined")
    {
        return new XMLHttpRequest();
    }
    //We have to try using an ActiveX object.
    //Try to create an object with the latest version
    //and work back from there.
    else if(window.ActiveXObject)
    {
        var aVersions = ["MSXML2.XMLHttp.5.0", 
		        "MSXML2.XMLHttp.4.0", 
		        "MSXML2.XMLHttp.3.0", 
		        "MSXML2.XMLHttp", 
		        "Microsoft.XMLHttp"];
		
        for(var i = 0; i < aVersions.length; i++)
        {
	        try
	        {
		        var oXmlHttp = new ActiveXObject(aVersions[i]);
		        return oXmlHttp;
	        }
	        catch(oError)
	        {
		        //Do nothing
	        }
        }
    }
    //unable to create a XMLHttpRequest object
    throw new Error("XMLHttpRequest object could not be created.");
}