﻿// JScript 文件
//<script type="text/javascript" src="Mootools_V1.11.js"></script>
//必须一起包含Mootools_V1.11.js

var ConstCollectionHandler = new Class
(
{   
    xmlDoc:null, 
    initialize:function()
    {   
          this.getXmlDoc();
//        this.xmlDoc = getXmlDoc();
     },    
     
     getXmlDoc:function()
     {
        if(window.ActiveXObject)  
        {  
            this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");  
        }
        else if (document.implementation && document.implementation.createDocument) 
        {  
            this.xmlDoc=document.implementation.createDocument("","",null);  
        }
        else  {  
            alert('Your browser cannot handle this script'); 
         }
         this.xmlDoc.async=false;
         this.xmlDoc.load("/XML/StaticConstCollection/StaticConstCollection.xml"); 
//         return (xmlDoc);
     },
     
     getNodeText:function(obj){
        if(!obj)
        {
            return "";
        }
        if(obj.textContent){
            return obj.textContent;
        }
        
        if(obj.firstChild){
            obj=obj.firstChild;    
        }
        if(obj.nodeValue)
        {
            return obj.nodeValue;
        }
        if(obj.data)
        {
            return obj.data;
        }
        return "";
        
    },
     
    GetConstName:function(constCollectionCode,constValue)
    {
        var strReturn = ""
        //var str = "//ConstCollectionList/ConstCollection[@Code='" + constCollectionCode + "']/Option[@Value='" + constValue + "']";    
        var aNodes = this.xmlDoc.getElementsByTagName('ConstCollection');
        for(var i = 0; i < aNodes.length; i ++)
        {
            if(aNodes[i].getAttribute('Code') == constCollectionCode)
            {
                var aChilds = aNodes[i].childNodes;
                for(var j=0;j<aChilds.length;j++)
                {
                    if(aChilds[j].nodeType == 1)
                    {
                        if (aChilds[j].getAttribute("Value")==constValue)
                        strReturn = this.getNodeText(aChilds[j]);
                    }
                }   
            }
        }
        
        return strReturn;
	    
    },

//    
    AddConstCollectionToSelectBox:function (constCollectionCode,selectBoxName)
    {  
        var aNodes = this.xmlDoc.getElementsByTagName('ConstCollection');	
		                            
        for(var i = 0; i < aNodes.length; i ++){
//		                    
                if(aNodes[i].getAttribute('Code') == constCollectionCode){
                    var aChilds = aNodes[i].childNodes;
                    var objSelectBox = $(selectBoxName);
                    if (typeof(objSelectBox) != "object")
                    {
                        return;
                    } 
                    objSelectBox.options.add(new Option(aNodes[i].getAttribute('Description'),''));
                    for(var j=0;j<aChilds.length;j++)
                    {
                        if(aChilds[j].nodeType == 1){
                            objSelectBox.options.add(new Option(this.getNodeText(aChilds[j]),aChilds[j].getAttribute("Value")));
                        }
                    }               
                    break;
                }
//                            		                
        }
    }
//    
});






//var x=new ConstCollectionHandler();
//document.all("txtName").value = x.GetConstName('PROVIDER_TYPE','2');



//x.AddConstCollectionToSelectBox('PROVIDER_TYPE','txtSelect');		
//x.AddConstCollectionToSelectBox('PROVIDER_TYPE','txtSelect1');		
