﻿var XMLRequests = new Array();

function XMLRequest()
{
	var XMLRequest = false ;

	try {
		XMLRequest = new XMLHttpRequest() ;
	} catch (trymicrosoft) {
	  try {
		  XMLRequest = new ActiveXObject("Msxml2.XMLHTTP") ;
	  } catch (othermicrosoft) {
		try {
		  XMLRequest = new ActiveXObject("Microsoft.XMLHTTP") ;
		} catch (failed) {
		  XMLRequest = false ;
		  alert("Sorry, Your browser doesn't support AJAX. Please use Firefox, Opera or IE6+") ;
		}
	  }
	}
	return XMLRequest;
}

// XmlDocument factory
function XmlDocument() {}

XmlDocument.create = function () {
   try {
      // DOM2
      if (document.implementation && document.implementation.createDocument) {
         var doc = document.implementation.createDocument("", "", null);

         // some versions of Moz do not support the readyState property
         // and the onreadystate event so we patch it!
         if (doc.readyState == null) {
            doc.readyState = 1;
            doc.addEventListener("load", function () {
               doc.readyState = 4;
               if (typeof doc.onreadystatechange == "function")
                  doc.onreadystatechange();
            }, false);
         }

         return doc;
      }
      if (window.ActiveXObject)
	   {
         return new ActiveXObject(getControlPrefix() + ".XmlDom");
	   }
   }
   catch (ex) {}
   throw new Error("Your browser does not support XmlDocument objects");
};

// Create the loadXML method
if (window.DOMParser) {
	Document.prototype.loadXML = function (s) {

	   // parse the string to a new doc
	   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));
	   }
	};
}

function getControlPrefix() {
   if (getControlPrefix.prefix)
      return getControlPrefix.prefix;

   var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
   var o, o2;
   for (var i = 0; i < prefixes.length; i++) {
      try {
         // try to create the objects
         o = new ActiveXObject(prefixes[i] + ".XmlHttp");
         o2 = new ActiveXObject(prefixes[i] + ".XmlDom");
         return getControlPrefix.prefix = prefixes[i];
      }
      catch (ex) {};
   }

   throw new Error("Could not find an installed XML parser");
}
