﻿/**
* Synchronously load the XML document at the specified URL and
* return it as a Document object
*/
//XML.load = function(url) 
function loadDoc(url) {
    // Create a new document with the previously defined function
    var xmldoc = new newDocument(url);
    return xmldoc;         // Return the document
};

/**
* Create a new Document object. If no arguments are specified,
* the document will be empty. If a root tag is specified, the document
* will contain that single root tag. If the root tag has a namespace
* prefix, the second argument must specify the URL that identifies the
*namespace.
*/
//XML.newDocument = function(rootTagName, namespaceURL) 
function newDocument(url) {
    try {

        if (window.ActiveXObject) {
            var errorHappendHere = "Check Browser and security settings";
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
            xmlDoc.load(url);
            return xmlDoc
        }
        else if (window.XMLHttpRequest) {
            var errorHappendHere = "Error handling XMLHttpRequest request";
            var d = new XMLHttpRequest();
            d.open("GET", url, false);
            d.send(null);
            xmlDoc = d.responseXML;
            return xmlDoc;
        }
        else (document.implementation && document.implementation.createDocument)
        {
            // This is the W3C standard way to do it
            var errorHappendHere = "Error.";
            xmlDoc = document.implementation.createDocument("", "", null);
            xmlDoc.async = false;
            xmlDoc.load(url);

        }
    }
    catch (e) {
        alert(errorHappendHere);
    }
};
