﻿//-------- Region XmlDocument class --------
function XmlDocument(a_strSource)
{
    this.Source = a_strSource;
    this.Document = null;

    this.OnDocumentLoadedEvent = null;
}

XmlDocument.prototype.CreateDocumentFromFile = function()
{
    if (this.Source)
    {
        if (window.ActiveXObject)
        {
            this.Document = new ActiveXObject("Microsoft.XMLDOM");
            this.Document.async = false;
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            this.Document = document.implementation.createDocument("", "doc", null);
        }   
        
        if (typeof this.Document != "undefined")
        {
            this.Document.load(this.Source);
        } 
        
        if (typeof this.Document != "undefined")
        {
            if (window.ActiveXObject)
            {
                if (this.OnDocumentLoadedEvent)
                {
                    this.OnDocumentLoadedEvent();
                }  
            }
            else
            {
                if (this.OnDocumentLoadedEvent)
                {                
                    this.Document.onload = this.OnDocumentLoadedEvent;
                }
            }
        }        
    }
    else
    {
        throw new Error("Source hasn't been set");
    }
}

XmlDocument.prototype.RemoveWhitespaces = function(a_oElement)
{
    var strWs = /\S/;
    for (i = 0; i < a_oElement.childNodes.length; i++)
    {
        if ((a_oElement.childNodes[i].nodeType == 3) && (!strWs.test(a_oElement.childNodes[i].nodeValue))) 
        {        
            a_oElement.removeChild(a_oElement.childNodes[i]);
            i--;
        }
    }
    return a_oElement;
}

XmlDocument.prototype.GetValueList = function(a_oElement)
{
    a_oElement = XmlDocument.prototype.RemoveWhitespaces(a_oElement);
    var arrList = new Array();
    for (var i = 0; i < a_oElement.childNodes.length; i++)
    {
        arrList[i] = a_oElement.childNodes[i].firstChild.nodeValue;
    }
    return arrList;
}

XmlDocument.prototype.Get2DValueList = function(a_oElement)
{
    a_oElement = XmlDocument.prototype.RemoveWhitespaces(a_oElement);
    
    var arrList = new Array();
    var arrInnerList = null;
    var oTemporaryElement = null;
    for (var i = 0; i < a_oElement.childNodes.length; i++)
    {
        arrList[i] = this.GetValueList(a_oElement.childNodes[i]);
    }
    return arrList;
}