// Version : 1.0
// 2007/01/09  檔案初建立, 這個檔案會引用 EinsString.js 的部份功能

/////////////////////////////////////////////////
// FireFox Compatible
function OldTree_Find_Parent_By_ID(oEl,sTagName,theID) 
{
   var bIsIE=(document.all!=null);
   if (bIsIE)
   {
      while (oEl!=null && (oEl.tagName!=sTagName || oEl.id!=theID))
      {
         oEl=oEl.parentElement;
      }
      return oEl;
   }
   else
   {
      while (oEl!=null && (oEl.tagName!=sTagName || oEl.id!=theID))
      {
         oEl = oEl.parentNode;
      }
      return oEl;
   }
}

/////////////////////////////////////////////////
// FireFox Compatible
function OldTree_Find_Parent_by_TagName(oEl,sTag) 
{
   var bIsIE=(document.all!=null);
   if (bIsIE)
   {
      while (oEl!=null && oEl.tagName!=sTag)
      {
         oEl=oEl.parentElement;
      }
      return oEl;
   }
   else
   {
      while (oEl!=null && oEl.tagName!=sTag)
      {
         oEl = oEl.parentNode;
      }
      return oEl;
   }
}

///////////////////////////////////////////////////////////
// FireFox Compatible
function OldTree_Set_TR_Display(sDisplay,ChildTRs)
{
   var bIsIE=(document.all!=null);
   var AnyThing=false;
   if (ChildTRs!=null)
   {
      for (var i=0; i < ChildTRs.length; i++) // var <--- is very important
      {
         var theTR=ChildTRs[i];
         if (sDisplay=="none")
         {
            if (theTR.m_ChildTRs!=null) OldTree_Set_TR_Display(sDisplay,theTR.m_ChildTRs);  // Hide the Children
         }
         if ((sDisplay=="block")||(sDisplay==""))  // IE use 'block', FireFox use ''
         {
            var bExpand;
            if (bIsIE) bExpand=theTR.bExpand;
            else       bExpand=theTR.getAttribute("bExpand");
            if (bExpand==1)
            {
               if (theTR.m_ChildTRs!=null) OldTree_Set_TR_Display(sDisplay,theTR.m_ChildTRs);  // Show the Children
            }
         }
         theTR.style.display=sDisplay;
         AnyThing=true;
      }
   }
}

function OldTree_RebuildChildTR(TRArray,theID)
{
   var bIsIE=(document.all!=null);
   var oObject;
   if (bIsIE) oObject=document.all.tags("TR");
   else       oObject=document.getElementsByTagName("TR");
   if ((oObject!=null) && (theID!=""))
   {
      for (var i=0; i < oObject.length; i++) // var <--- is very important
      {
         var nParentID=null;
         if (bIsIE) 
         {
            var theObj=oObject(i);
            nParentID=theObj.ParentID;
         }
         else       
         {
            var theObj=oObject[i];
            nParentID=theObj.getAttribute("ParentID");
         }
         if (nParentID!=null)
         {
            if (nParentID==theID)
            {
               TRArray[TRArray.length]=theObj;   
            }
         }
      }
   }
}

function OldTreeToggle(ImgObjClicked, sClickTRID)
{
   var bIsIE=(document.all!=null);
   var ClickTR=OldTree_Find_Parent_By_ID(ImgObjClicked,"TR",sClickTRID);
   if (ClickTR!=null)
   {
      var bExpand;
      if (bIsIE)
      {
         bExpand=ClickTR.bExpand;
         sIconExpanded =ClickTR.sIconExpanded;
         sIconCollapsed=ClickTR.sIconCollapsed;
      }
      else       
      {
         bExpand=ClickTR.getAttribute("bExpand");
         sIconExpanded =ClickTR.getAttribute("sIconExpanded");
         sIconCollapsed=ClickTR.getAttribute("sIconCollapsed");
      }
      if (bExpand!=null)
      {
         if (ClickTR.m_ChildTRs==null) // 可能在 OldTree 裡, 設定為預設展開
         {
            ClickTR.m_ChildTRs=new Array();
            OldTree_RebuildChildTR(ClickTR.m_ChildTRs,sClickTRID);
         }
         if (bExpand==0)
         {
            if (bIsIE) ClickTR.bExpand=1;
            else       ClickTR.setAttribute("bExpand",1);
            ImgObjClicked.src=sIconExpanded;
            var sDisplay;
            if (bIsIE) sDisplay="block";
            else       sDisplay="";
            OldTree_Set_TR_Display(sDisplay,ClickTR.m_ChildTRs); // Try to Show Hidden Children
         }
         else // bExpand!=0
         {
            if (bIsIE) ClickTR.bExpand=0;
            else       ClickTR.setAttribute("bExpand",0);
            ImgObjClicked.src=sIconCollapsed;
            OldTree_Set_TR_Display("none",ClickTR.m_ChildTRs);
         }
      }
      else 
      {
         alert("ATTR bExpand not found");
      }
   }
   else
   {
      alert("TR not found -->"+sClickTRID);
   }
}
