//
//	http://momche.net
//	mo@momche.net
//	:: feel free to use it BUT
//	:: if you want to use this code PLEASE send a note
//	:: and please keep this disclaimer intact
//
//
//
//	remastered from WebFX
//
//
var XMLHTTP = function()
{
	var aPrefixes = [ "MSXML2", "Microsoft", "MSXML", "MSXML3" ];

	if( window.ActiveXObject )
	{
		var sMSDomDocumentPrefix = function()
		{
			var hO;
			for (var nI = 0; nI < aPrefixes.length; nI++) 
			{
				try 
				{
					// try to create the objects
					hO = new ActiveXObject( aPrefixes[ nI ] + ".DomDocument" );
					return aPrefixes[ nI ];
				}
				catch ( hE ) 
				{}
			}
			throw new Error( "Could not find an installed XML parser" );
		}();

		var sMSXmlHttpPrefix = function()
		{
			var hO;
			for (var nI = 0; nI < aPrefixes.length; nI++) 
			{
				try 
				{
					// try to create the objects
					hO = new ActiveXObject( aPrefixes[ nI ] + ".XmlHttp" );
					return aPrefixes[ nI ];
				}
				catch ( hE ) 
				{}
			}
			throw new Error( "Could not find an installed XML parser" );
		}();
	}

	// Create the loadXML method and xml getter for Mozilla
	if (	window.DOMParser &&
			window.XMLSerializer &&
			window.Node && Node.prototype && Node.prototype.__defineGetter__ ) 
	{
		Document.prototype.loadXML = function ( s ) {
			var doc2 = ( new DOMParser() ).parseFromString(s, "text/xml");
			
			// remove all initial children
			while (this.hasChildNodes())
			{
				this.removeChild(this.lastChild);
			}
				
			// insert and import nodes
			for (var i = 0; i < doc2.childNodes.length; i++) 
			{
				this.appendChild( this.importNode(doc2.childNodes[i], true) );
			}
		};
		Document.prototype.__defineGetter__("xml", function () {
			return (new XMLSerializer()).serializeToString(this);
		});
	}
	
	return {
		createXmlHttp : function()
		{
			try
			{
				if( window.XMLHttpRequest )
				{
					var hRequest = new XMLHttpRequest();
					if( hRequest.readyState == null )
					{
						hRequest.readyState = 1;
						hRequest.addEventListener( "load", 	function() {
																hRequest.readyState = 4;
																if( hRequest.onreadystatechange )
																{
																	hRequest.onreadystatechange();
																}
															}, false );
					}
					return hRequest;
				}
				if( window.ActiveXObject )
				{
					return new ActiveXObject( sMSXmlHttpPrefix + '.XmlHttp' );
				}
				alert( 'dead' );
			}
			catch ( hE )
			{
			alert( 'problem' );
			}
			//if we are here
			throw new Error( "No XmlHttp" );
		},
		createDomDocument : function()
		{
			try {
				// DOM2
				if ( document.implementation && document.implementation.createDocument ) 
				{
					var hDocument = document.implementation.createDocument( "", "", null );
					
					// some versions of Moz do not support the readyState property
					// and the onreadystate event so we patch it!
					if ( hDocument.readyState == null ) 
					{
						hDocument.readyState = 1;
						hDocument.addEventListener("load", function () {
							hDocument.readyState = 4;
							if ( hDocument.onreadystatechange )
							{
								hDocument.onreadystatechange();
							}
						}, false);
					}
					
					return hDocument;
				}
				if ( window.ActiveXObject )
				{
					return new ActiveXObject( sMSDomDocumentPrefix + ".DomDocument" );
				}
			}
			catch ( hE )
			{}
			throw new Error( "No XmlDocument" );
		}
	};
}();