﻿// JScript File

        
    
// Loads an xml file as an xml document and 
// returns the xml document.
// handles cross-platform compatability issues.
function LoadXmlDocument( pathToXmlFile) 
{
    var xdoc;
    
    // code for IE
    if (window.ActiveXObject)
    {
      xdoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
    {
      xdoc=document.implementation.createDocument("","",null);
    }
    else
    {
      alert('Your browser cannot handle this script');
    }
    
    xdoc.async=false;
    xdoc.load(pathToXmlFile);
    return(xdoc);
}
    

// Make sure that Xpath is supported.    
function CheckXPathRequirement()
{           
    // check for XPath implementation 
 if( document.implementation.hasFeature("XPath", "3.0") ) 
 { 
     // prototying the XMLDocument 
     XMLDocument.prototype.selectNodes = function(cXPathString, xNode) 
     { 
         if( !xNode ) { xNode = this; }
         var oNSResolver = this.createNSResolver(this.documentElement) 
         var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
         XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) 
         var aResult = [];
         
         for( var i = 0; i < aItems.snapshotLength; i++) 
         { 
            aResult[i] = aItems.snapshotItem(i);
         } 
         return aResult;
     } 

     // prototying the Element 
     Element.prototype.selectNodes = function(cXPathString) 
     { 
         if(this.ownerDocument.selectNodes) 
         { 
            return this.ownerDocument.selectNodes(cXPathString, this);
         } 
         else{throw "For XML Elements Only";} 
     } 
 } 
}
