/* MarkTree JavaScript code
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Miika Nurminen, 12.7.2004.
 */


function is_exp(n) {
  if (n==null) return false;
  return ((n.className=='exp') || (n.className=='exp_active'));
}

function is_col(n) {
  if (n==null) return false;
  return ((n.className=='col') || (n.className=='col_active'));
}

function is_basic(n) {
  if (n==null) return false;
  return ((n.className=='basic') || (n.className=='basic_active'));
}


function is_list_node(n) {
  if (n==null) return false;
  if (n.className==null) return false;
  if ( (is_exp(n)) ||
       (is_col(n)) ||
       (is_basic(n)) )
   return true; else return false;
}


function getsub (li) {
  if (li.childNodes.length==0) return null;
  for (var c = 0; c < li.childNodes.length; c++)
    if ( (li.childNodes[c].className == 'sub') || (li.childNodes[c].className == 'subexp') )
      return li.childNodes[c];
}


function myClickHandler (evt) {
  var target = evt ? evt.target : event.srcElement;
  if (!is_list_node(target)) return;
  mytoggle(target);
}


function setSubClass(node,name) {
  sub = getsub(node);
  if (sub==null) return;
  sub.className=name;
}


function mytoggle(target) {
  if (!is_list_node(target)) return;
    if (is_col(target)) {
      target.className='exp';
      setSubClass(target,'sub');
    }
    else if (is_exp(target)) {
      target.className='col';
      setSubClass(target,'subexp');
    }
}


document.onclick = myClickHandler;


