///window.onerror=null;

var srcs = ["/ti/node.gif","/ti/node-last.gif",
            "/ti/plus.gif","/ti/plus-last.gif",
            "/ti/minus.gif","/ti/minus-last.gif"];
var imgs = new Array();
var TreeId="Tree";
for(i=0;i<srcs.length;i++) {
  fn=srcs[i];
  im=new Image();
  im.src=fn;
  imgs[i]=im;
}



function ChangeVisible(li) {
 if ( li && li.tagName && li.tagName.toLowerCase() == 'li') {
   for (var i = 0; i < li.childNodes.length; i++) {
     ch=li.childNodes[i];
     if (ch && ch.tagName && ch.tagName.toLowerCase() == 'ul') {
       opened = ch.style.display != 'none';
       if (opened) {
         ch.style.display='none';
         if (li.parentNode.lastChild != li)
           li.className = 'plus';
         else
           li.className = 'plus-last';
       } else {
         ch.style.display='';
         if (li.parentNode.lastChild != li)
           li.className = 'minus';
         else
           li.className = 'minus-last';
       }
     }
   }
 }
}


function AnchorClick() {
  n=this;
  cpath="";
  while (n && n.id != TreeId) {
    if (n && n.tagName && n.tagName.toLowerCase() == 'li')
      cpath=n.id +";"+cpath;
    n=n.parentNode;
  }
  if (cpath=="") {
     code=""+document.location;
     code=code.replace(/.*cpath=([t0-9;]+).*/, "$1");
     cpath=code;
     if (cpath==""+document.location) cpath="";
  }
  if (cpath!="") {
    d=(this.href.indexOf("?")==-1)?"?":"&";
    this.href=this.href+d+"cpath="+cpath;
  }
  return true;
}

function NodeClick(e) {
 if (!e) var e = window.event
 if (!e) var e = window.Event
 if (!e) return;
 if (e.srcElement) n=e.srcElement;
 if (e.target) n=e.target;
 if (!n) return;
 e.cancelBubble = true;
 if (e.stopPropagation) e.stopPropagation();
 ChangeVisible(n);
}


function SetId(li) {
  a=li.firstChild;
  if (a && a.tagName && a.tagName.toLowerCase() == 'a') {
    hr=""+a.href;
    id=hr.replace(/.*\/([0-9]+)\/?/, "$1");
    li.id="t"+id;
  }
}

function GotoID(root, id) {
 if (document.location.pathname == "/") return;

 var code=""+document.location;
 if (code==id) id="";
 code=code.replace(/.*cpath=([t0-9;]+).*/, "$1");
 re = /[0-9]*/g;
 ids = code.match(re);

  if (id) {
    n = document.getElementById("t"+id);
    if (!n) return;
    aa=n.getElementsByTagName('a');
    if (aa.length > 0) {
      a=aa[0];
      a.className='active';
    }
  } else {  
     for(i=ids.length-1;i>=0;i--) {
      if (ids[i]!="") {
        li = document.getElementById("t"+ids[i]);
        if (li) {
          aa=li.getElementsByTagName('a');
          if (aa.length > 0) {
            a=aa[0];
            a.className='active';
          }
          break;
        }
      }
    }
  }

//alert('p='+Get_Cookie('cpath'));
//str = ""+Get_Cookie('cpath');

//alert("ids="+ids);
for(i=0;i<ids.length;i++)
  if (ids[i]!='') {
    li = document.getElementById("t"+ids[i]);
    ChangeVisible(li);
//    alert("li.id=t"+ids[i])
  }


}


function init(RootName) {
 if (!document.getElementById) return;
 root = document.getElementById(RootName);
 if (!root) return;
 root.style.display='none';
 TreeId=RootName;
 var nodes = root.getElementsByTagName('li');
 for (var li = 0; li < nodes.length; li++) {
   n=nodes[li];
   SetId(n);
   if (n.getElementsByTagName('ul').length > 0) {
     n.onclick=NodeClick;
     if (n.captureEvents) n.captureEvents(Event.CLICK);
     ChangeVisible(n);
   } else {
     if (n.nextSibling)
       n.className = ''
     else
       n.className = 'last';
   }
   // AnchorClick
   aa=n.getElementsByTagName('a');
   if (aa.length > 0) {
     aa[0].onclick=AnchorClick;
   }
 }
 
 var code=""+document.location;
 code=code.replace(/.*category\/([0-9]+).*/, "$1");
 if (code == ""+document.location) code="";
 GotoID(root, code);
 root.style.display='';
 
 window.onload=TreeOnLoad;
 NewHrefsPather();
 
}



function HrefsPatcher() {
 aa=document.getElementsByTagName('a');
 for (i=0;i<aa.length;i++) {
   if(aa[i].id != 'sp') 
     aa[i].onclick=AnchorClick;
 }
}

function TreeOnLoad() {
  HrefsPatcher();
}

function NewHrefsPather() {
  HrefsPatcher();
  if ((document.readyState!="loaded") && (document.readyState!="complete")) 
    setTimeout('NewHrefsPather()',200);
  //window.status=document.readyState;
 // setTimeout('window.status="ok"',50);
}

