function jctExtTree()
{
    
};
jctExtTree.datatableObj=null;
jctExtTree.AllString=new StringBuffer();
jctExtTree.PGroup="";
jctExtTree.ReadCountGroup="";
jctExtTree.TopNodeIDGroup="";
jctExtTree.ParentIDGroup="";
jctExtTree.UserTime="";
jctExtTree.TopNodeID=0;
jctExtTree.PubOtherAtt="";
//获取树的生成字符串
jctExtTree.GetTree=function(txtSql,tableName,_TopNodeID,OtherAtt)
{
    var returnValue="";
    try
    {
    //    jctExtTree.UserTime+="查询数据使用时间：\r\n开始时间："+(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString();
        jctExtTree.datatableObj=DBReader.selectSql(txtSql,tableName);
    //     jctExtTree.UserTime+="\r\n"+"结束时间："+(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString();
         
    //     alert(jctExtTree.UserTime);
        if(_TopNodeID!=undefined)
        {
            jctExtTree.TopNodeID=_TopNodeID;
        }
       
	    if(DBReader.DObjectIsNull(jctExtTree.datatableObj)==false && parseInt(jctExtTree.datatableObj.RecordCount)>0)
	    {
            jctExtTree.datatableObj.MoveFirst();
            //获取顶级ID集合
        //    jctExtTree.UserTime+="获取上级节点集合使用时间：\r\n开始时间："+(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString();
             jctExtTree.getTopIDGroup();
        //     jctExtTree.UserTime+="\r\n"+"结束时间："+(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString();
        //     alert(jctExtTree.UserTime);
        //    alert(jctExtTree.TopNodeIDGroup);
            jctExtTree.AllString.clear();
            jctExtTree.AllString.appendLine("[");
            var RowCount=jctExtTree.datatableObj.RecordCount;
            jctExtTree.PubOtherAtt=OtherAtt;
            
            var arrTopNodeID=jctExtTree.TopNodeIDGroup.split(',');
            jctExtTree.TopNodeIDGroup="";
            for(x=0;x<arrTopNodeID.length;x++)
            {
                if(x!=0)
                {
                    jctExtTree.AllString.appendLine(",");
                }
                var strTopNodeID=arrTopNodeID[x];
                jctExtTree.datatableObj.Filter=" ParentID="+strTopNodeID;
                var FNodeList=jctExtTree.datatableObj;
                if(FNodeList.RecordCount>0)
                {
                    jctExtTree.datatableObj.Filter=" ID="+strTopNodeID;
                    var FParentNodeList=jctExtTree.datatableObj;
                    if(FParentNodeList.RecordCount>0)
                    {
                        FParentNodeList.MoveFirst();
                        var IDValue=FParentNodeList.Fields("ID").Value;
                        var NameValue=FParentNodeList.Fields("NAME").Value;
                        var ParentIDValue=0;
                        var strOthArr="";
                        if(jctExtTree.PubOtherAtt!=undefined && jctExtTree.PubOtherAtt!="")
                        {
                            var tempOtherAtt=jctExtTree.PubOtherAtt.replace(/@Data@/g,'FParentNodeList');
                            try{strOthArr=eval(tempOtherAtt);}catch(err){};
                        }
                        var ParentNodeValue="";
                        NodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:false,"children":'; 
                        jctExtTree.AllString.appendLine(NodeValue);
                        jctExtTree.AllString.appendLine("[");
                    
                        jctExtTree.datatableObj.Filter=" ParentID="+strTopNodeID;
                        FNodeList=jctExtTree.datatableObj;
                        var FNodeCount=FNodeList.RecordCount;
                        if(FNodeCount>0)
                        {
                            FNodeList.MoveFirst();
                            var ReadCount=0;
                            for(i=0;i<FNodeCount;i++)
                            {
                                var IDValue=FNodeList.Fields("ID").Value;
                                var NameValue=FNodeList.Fields("NAME").Value;
                                var ParentIDValue=FNodeList.Fields("ParentID").Value;
                                                              
                                var strOthArr="";
                                if(jctExtTree.PubOtherAtt!=undefined && jctExtTree.PubOtherAtt!="")
                                {
                                    var tempOtherAtt=jctExtTree.PubOtherAtt.replace(/@Data@/g,'FNodeList');
                                    try{strOthArr=eval(tempOtherAtt);}catch(err){};
                                }
                                ReadCount=i;
                                jctExtTree.datatableObj.Filter=" ParentID= "+IDValue;
                                var ChileNodeItemList=jctExtTree.datatableObj;
                                
                                var NodeValue="";
                                if(ChileNodeItemList.RecordCount==0)
                                {
                                    if(i==0)
                                    {
                                        NodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:true,"children":null}'; 
                                    }
                                    else
                                    {
                                        NodeValue=',{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:true,"children":null}';
                                    }
                                    jctExtTree.AllString.appendLine(NodeValue);
                                }
                                else
                                {
                                    if(i==0)
                                    {
                                        NodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:false,"children":'; 
                                    }
                                    else
                                    {
                                        NodeValue=',{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:false,"children":';
                                    }
                                    jctExtTree.AllString.appendLine(NodeValue);
                                    jctExtTree.AllString.appendLine("[");
                                    jctExtTree.ReadCountGroup="";
                                    jctExtTree.PGroup="";
                                    jctExtTree.GetChildValue(IDValue);
                                    jctExtTree.AllString.appendLine("]");
                                    jctExtTree.AllString.appendLine("}");
                                }
                                
                                jctExtTree.datatableObj.Filter=" ParentID="+strTopNodeID;
                                FNodeList=jctExtTree.datatableObj;
                                i=ReadCount;
                                if(i>0)
                                {
                                    for(tt=0;tt<parseInt(i)+1;tt++)
                                    {
                                        FNodeList.MoveNext();
                                    }
                                }
                                else
                                {
                                    FNodeList.MoveNext();
                                }
                            }
                        }
                        jctExtTree.AllString.appendLine("]");
                        jctExtTree.AllString.appendLine("}");
                    }
                }
                else
                {
                    jctExtTree.datatableObj.Filter=" ID="+strTopNodeID;
                    var FNodeList=jctExtTree.datatableObj;
                    if(FNodeList.RecordCount>0)
                    {
                        FNodeList.MoveFirst();
                    
                        var IDValue=FNodeList.Fields("ID").Value;
                        var NameValue=FNodeList.Fields("NAME").Value;
                        var ParentIDValue=0;
                        var strOthArr="";
                        if(jctExtTree.PubOtherAtt!=undefined && jctExtTree.PubOtherAtt!="")
                        {
                            var tempOtherAtt=jctExtTree.PubOtherAtt.replace(/@Data@/g,'FNodeList');
                            try{strOthArr=eval(tempOtherAtt);}catch(err){};
                        }
                        var ParentNodeValue="";
                        ParentNodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"hasChildren":true,"isexpand":true,"complete":true,leaf:true,"children":null}';             
                        jctExtTree.AllString.appendLine(ParentNodeValue);
                        FNodeList.MoveNext();
                    }
                }
            }
            DBReader.Dispose(jctExtTree.datatableObj);
            
            jctExtTree.AllString.appendLine("]");
            if(jctExtTree.AllString.toString()=="[]")
            {
                returnValue="";
            }
            returnValue=jctExtTree.AllString.toString();
            jctExtTree.AllString.clear();
       }
//        alert(returnValue);
        window.clipboardData.setData('Text',returnValue);
    }
    catch(e)
    {
        alert(e.message);
        DBReader.Dispose(jctExtTree.datatableObj);
    }
    return returnValue;
}
//递归绑定下级树节点
var inum=0;
jctExtTree.GetChildValue=function(PID)
{
    try{
        inum++;
        if(PID!="")
        {
            if(jctExtTree.PGroup=="")
            {
                jctExtTree.PGroup+=PID;
            }
            else
            {
                jctExtTree.PGroup+=","+PID;
            }
            jctExtTree.datatableObj.Filter=" ParentID= "+PID;
            var ChileNodeList=jctExtTree.datatableObj;
            var ReadChildCount=0;
            var ChildLen=ChileNodeList.RecordCount;
            
            var strOthArr="";
            if(jctExtTree.PubOtherAtt!=undefined && jctExtTree.PubOtherAtt!="")
            {
                strOthArr=jctExtTree.PubOtherAtt;
            }
            for(m=0;m<ChildLen;m++)
            {
                var IDValue=ChileNodeList.Fields("ID").Value;
                var NameValue=ChileNodeList.Fields("NAME").Value;
                var EndFlag=0;//2010-11-17添加
                try{EndFlag=ChileNodeList.Fields("EndFlag").Value;}catch(err){}

                var strOthArr="";
                if(jctExtTree.PubOtherAtt!=undefined && jctExtTree.PubOtherAtt!="")
                {
                    var tempOtherAtt=jctExtTree.PubOtherAtt.replace(/@Data@/g,'ChileNodeList');
                    try{strOthArr=eval(tempOtherAtt);}catch(err){};
                }
                
                ReadChildCount=m;
                jctExtTree.datatableObj.Filter=" ParentID= "+IDValue;
                var ChileNodeItemList=jctExtTree.datatableObj;
                
                var NodeValue="";
                if(ChileNodeItemList.RecordCount==0)
                {
                    if(m==0)
                    {
                        NodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"EndFlag":"'+EndFlag+'","hasChildren":false,"isexpand":true,"complete":true,leaf:true,"children":null}'; 
                    }
                    else
                    {
                        NodeValue=',{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"EndFlag":"'+EndFlag+'","hasChildren":false,"isexpand":true,"complete":true,leaf:true,"children":null}';
                    }
                    jctExtTree.AllString.appendLine(NodeValue);
                }
                else
                {                    
                    if(m==0)
                    {
                        NodeValue='{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"EndFlag":"'+EndFlag+'","hasChildren":true,"isexpand":true,"complete":true,leaf:false,"children":'; 
                    }
                    else
                    {
                        NodeValue=',{"id":"'+IDValue+'","text":"'+NameValue+'",'+strOthArr+'"EndFlag":"'+EndFlag+'","hasChildren":true,"isexpand":true,"complete":true,leaf:false,"children":';
                    }
                    jctExtTree.AllString.appendLine(NodeValue);
                    
                    jctExtTree.AllString.appendLine("[");
                    jctExtTree.GetChildValue(IDValue);
                    jctExtTree.AllString.appendLine("]");
                    jctExtTree.AllString.appendLine("}");
                    
                }
                try{
                    var arrPG=jctExtTree.PGroup.split(',');
                    
                    PID=arrPG[arrPG.length-1];
                    if(PID=="")
                    {
                        PID=arrPG[0];
                    }
                    if(PID!="")
                    {
                        jctExtTree.datatableObj.Filter=" ParentID= "+PID;
                        ChileNodeList=jctExtTree.datatableObj;
                        
                        m=ReadChildCount;
                        if(m>0)
                        {
                            for(tt=0;tt<parseInt(m)+1;tt++)
                            {
                                ChileNodeList.MoveNext();
                            }
                        }
                        else
                        {
                            ChileNodeList.MoveNext();
                        }
                    }
                }
                catch(e)
                {
//                    alert(arrPG);
                    alert(e.message);
                }
            }
//            jctExtTree.PGroup=jctExtTree.PGroup.substring(0,jctExtTree.PGroup.length-2);

            var tempArr=Array();
            tempArr=jctExtTree.PGroup.split(',');
            tempArr[tempArr.length-1]=null;
            tempArr.length=tempArr.length-1;
            
            jctExtTree.PGroup=tempArr.join(',');
        }
    }
    catch(e)
    {
//        alert(inum);
        alert(e.message);
    }
}
//获取顶级节点ID集合
jctExtTree.getTopIDGroup=function()
{
//    if(jctExtTree.TopNodeID==-1)
//    {
        jctExtTree.getParentIDGroup();
//    }
//    else
//    {
//        jctExtTree.ParentIDGroup="0";
//    }
    var arrParentID=jctExtTree.ParentIDGroup.split(',');
    jctExtTree.ParentIDGroup="";
    for(x=0;x<arrParentID.length;x++)
    {
        var strParentID=arrParentID[x];
//        jctExtTree.datatableObj.Filter=" ID="+strParentID;
//        var TempObj=jctExtTree.datatableObj;
//        if(TempObj.RecordCount==0)
//        {
            if(jctExtTree.TopNodeIDGroup=="")
            {
                jctExtTree.TopNodeIDGroup+=strParentID;
            }
            else
            {
                jctExtTree.TopNodeIDGroup+=","+strParentID;
            }
//        }
    }
    jctExtTree.datatableObj.Filter="";
}
//获取所有父级节点ID集合
jctExtTree.getParentIDGroup=function()
{
    var RowCount=jctExtTree.datatableObj.RecordCount;
    var SelectedIDGroup="";
    var DonotSelectedIDGroup="";
    var execCount=0;
    if(jctExtTree.TopNodeID==0)
    {
        jctExtTree.datatableObj.Filter="ParentID=NULL OR ParentID=0";
        var NullParentCount=jctExtTree.datatableObj.RecordCount;
        //先找到ParentID是null或0的节点为顶级，如果找不到再找ParentID是大于0的
        for(m=0;m<NullParentCount;m++)
        {
            if(jctExtTree.ParentIDGroup=="")
            {
                jctExtTree.ParentIDGroup+=jctExtTree.datatableObj.Fields("ID").Value;
            }
            else
            {
                jctExtTree.ParentIDGroup+=","+jctExtTree.datatableObj.Fields("ID").Value;
            }
            jctExtTree.datatableObj.MoveNext();
            execCount++;
        }
    }
    else
    {
        jctExtTree.datatableObj.Filter="";//ParentID="+jctExtTree.TopNodeID;
    }
    if(jctExtTree.ParentIDGroup=="")
    {
        SelectedIDGroup="";
        jctExtTree.datatableObj.Filter="";
        if(jctExtTree.datatableObj.RecordCount>0)
        {
            jctExtTree.datatableObj.MoveFirst();
        }
        for(m=0;m<RowCount;m++)
        {
            var TempParentID=jctExtTree.datatableObj.Fields("ParentID").Value;
            if(parseInt(TempParentID)<=0)
            {
                var NewParentID=jctExtTree.datatableObj.Fields("ID").Value;
                if(SelectedIDGroup.indexOf("["+NewParentID+"]")==-1)
                {
                    if(SelectedIDGroup=="")
                    {
                        SelectedIDGroup+="["+NewParentID+"]";
                    }
                    else
                    {
                        SelectedIDGroup+=","+"["+NewParentID+"]";
                    }
                    if(jctExtTree.ParentIDGroup=="")
                    {
                        jctExtTree.ParentIDGroup+=NewParentID;
                    }
                    else
                    {
                        jctExtTree.ParentIDGroup+=","+NewParentID;
                    }
                }
                jctExtTree.datatableObj.MoveNext();
            }
            else
            {
                if(SelectedIDGroup.indexOf("["+TempParentID+"]")==-1)
                {
                    if(SelectedIDGroup=="")
                    {
                        SelectedIDGroup+="["+TempParentID+"]";
                    }
                    else
                    {
                        SelectedIDGroup+=","+"["+TempParentID+"]";
                    }
                    if(jctExtTree.ParentIDGroup=="")
                    {
                        jctExtTree.ParentIDGroup+=TempParentID;
                    }
                    else
                    {
                        jctExtTree.ParentIDGroup+=","+TempParentID;
                    }
                    if(DonotSelectedIDGroup=="")
                    {
                        DonotSelectedIDGroup+=" ParentID<>"+TempParentID +" AND ID<>"+TempParentID;
                    }
                    else
                    {
                        DonotSelectedIDGroup+=" AND ParentID<>"+TempParentID+" AND ID<>"+TempParentID;
                    }
                    jctExtTree.datatableObj.Filter=DonotSelectedIDGroup;
                    RowCount=jctExtTree.datatableObj.RecordCount;
                    if(RowCount>0)
                    {
                        m=0;
                        jctExtTree.datatableObj.MoveFirst();
                    }
                    else
                    {
                        jctExtTree.datatableObj.Filter="";
                        RowCount=jctExtTree.datatableObj.RecordCount;
                        jctExtTree.datatableObj.MoveNext();
                    }
                }
                else
                {
                    jctExtTree.datatableObj.MoveNext();
                }
            }
            execCount++;
        }
    }
//    alert(execCount);
    jctExtTree.datatableObj.Filter="";
}