﻿// JScript File

//加载XML数据
function DataSource(RootName){
    this.isLoad=false;
    this.Contents=document.createElement("div");
    isNothing=function(obj){return obj==null?true:false;}
    dc=function(name,value){var tmp=document.createElement("div");tmp.id=name;tmp.innerHTML=value;return tmp;}
    this.isFox=function(){if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){return true;}else{return false;}}
    isFox=this.isFox;
    this.gTagValue=function(Node){if(isFox()){var tmp=Node.childNodes[0];return isNothing(tmp)?"":Node.childNodes[0].nodeValue;}else{return Node.text;}}
    this.hasChild=function(Node){if(Node.hasChildNodes()){if(Node.childNodes[0].hasChildNodes()||Node.childNodes[1].hasChildNodes()){return true;}else{return false;}}else{return false;}}
    this.gTag=function(Xml,NodeName){var Node=Xml.getElementsByTagName(NodeName)[0];return isNothing(Node)?"":this.gTagValue(Xml.getElementsByTagName(NodeName)[0]);}
    this.gTags=function(Xml){
        var root=this.RootName;
        var rNode=Xml.getElementsByTagName(RootName)[0];
        var rdiv=document.createElement("div");rdiv.id="dsRoot";
        treeTags=function(Node,div){  
            var flagIndex=isFox()?Node.childNodes.length-1:Node.childNodes.length;
            for(var i=0;i<flagIndex;i++){
                var flag=isFox()?i+1:i;
                if(Node.childNodes[flag].nodeType==1){
                    var subdiv=dc(Node.childNodes[flag].nodeName,this.gTagValue(Node.childNodes[flag]));
                    div.appendChild(subdiv);
                    if(this.hasChild(Node.childNodes[flag])){treeTags(Node.childNodes[flag],subdiv);}
                }
            }     
        }
        treeTags(rNode,rdiv);
        this.isLoad=true;return rdiv;
    }
    this.gChildTags=function(Xml,TagName){
        var Node=Xml.getElementsByTagName(TagName)[0];var tmp=[];
        if(!isNothing(Node)){if(this.hasChild(Node)){var flagIndex=isFox()?Node.childNodes.length-1:Node.childNodes.length;for(var i=0;i<flagIndex;i++){var flag=isFox()?i+1:i;if(Node.childNodes[flag].nodeType==1){var tmp = tmp.concat(Node.childNodes[flag]);}}return tmp;}else{return "";}}else{return "";}
    }
    this.gChildByName=function(Node,ChildName){if(this.hasChild(Node)){var flagIndex=isFox()?Node.childNodes.length-1:Node.childNodes.length;for(var i=0;i<flagIndex;i++){var flag=isFox()?i+1:i;if(Node.childNodes[flag].nodeType==1){if(Node.childNodes[flag].nodeName==ChildName){return Node.childNodes[flag];}}}return null;}else{return null;}}
    this.gXmlByPath=function(FN){
        var bd=this.DataBinder;
        var d;
        if(window.ActiveXObject){
            d = new ActiveXObject('Microsoft.XMLDOM');d.async = false;d.load(FN);
            return bd.Bind(d);}
        else if (document.implementation&&document.implementation.createDocument){
            d = document.implementation.createDocument('', '', null);d.load(FN);d.onload = function (){return bd.Bind(d);};}
        else{
            alert('您的浏览器不支持xml文件读取，导致本页面可能无法正常使用,推荐使用IE5.0以上可以解决此问题!');
            return null;}
    }
    this.gXmlByID=function(fid){
        if (fid==null){fid="881";}
        var sPath='/XML/Content/Ctt' + (fid.length>=5?fid:'00000'.substring(fid.length,5) + fid) + '.xml';
        this.gXmlByPath(sPath);
    }
}