// Modified by Anthony Ouwehand for Counter-Hack.net

/* $Id: left.js,v 1.7 2001/07/02 21:17:17 loic1 Exp $ */

// These scripts were originally found on cooltype.com.
// Modified 01/01/1999 by Tobias Ratschiller for linuxapps.com

// Modified 7th June 2000 by Brian Birtles for Mozilla 5.0
// compatibility for phpMyAdmin

// Rewritten and put in a libray 2nd May 2001 by Loïc Chapeaux

// Test passed with:
// - Mozilla 0.8.1 for Windows (js enabled & disabled)
// - IE5, 5.01, 5.5 for Windows
// - Netscape 4.75 for Windows
// - Opera 5.02 for windows (js disabled)

// Test failed with:
// - Opera 5.02 for windows with js enabled -> crappy DOM implementation
//   ('getElementsByTagName' is unsupported), nothing to do :(


var isExpanded   = false;

var imgOpened    = new Image(9,9);
imgOpened.src    = root + 'images/minus.gif';
var imgClosed    = new Image(9,9);
imgClosed.src    = root + 'images/plus.gif';


/**
 * Do reloads the frame if the window has been resized under Netscape4+
 *
 * @access  private
 */
function reDo() {
  if (innerWidth != origWidth || innerHeight != origHeight)
    location.reload(true);
} // end of the 'reDo()' function

/**
 * Positioned element resize bug under NS4+
 */
if (isNS4) {
  var origWidth  = innerWidth;
  var origHeight = innerHeight;
  onresize       = reDo;
}


/**
 * Specific stuffs for IE4
 */
function doDocumentOnMouseOver() {
  var eSrc = window.event.srcElement ;
  if (eSrc.className == 'item') {
    window.event.srcElement.className = 'highlight';
  }
} // end of the 'doDocumentOnMouseOver()' function

function doDocumentOnMouseOut() {
  var eSrc = window.event.srcElement ;
  if (eSrc.className == 'highlight') {
    window.event.srcElement.className = 'item';
  }
} // end of the 'doDocumentOnMouseOut()' function

if (isIE4) {
  document.onmouseover = doDocumentOnMouseOver ;
  document.onmouseout = doDocumentOnMouseOut ;
}


/**
 * Gets the id of the first collapsible room
 *
 * @param  string  the name of the first collapsible room
 *
 * @return  integer  the index number corresponding to this room
 *
 * @access  public
 */
function nsGetIndex(el) {
  var ind       = null;
  var theLayers = document.layers;
  var layersCnt = theLayers.length;
  for (var i = 0; i < layersCnt; i++) {
    if (theLayers[i].id == el) {
      ind = i;
      break;
    }
  }
  return ind;
} // end of the 'nsGetIndex()' function


/**
 * Positions layers under NS4+
 *
 * @access  public
 */
function nsArrangeList() {
  if (firstInd != null) {
    var theLayers = document.layers;
    var layersCnt = theLayers.length;
    var nextY     = theLayers[firstInd].pageY + theLayers[firstInd].document.height;
    for (var i = firstInd + 1; i < layersCnt; i++) {
      if (theLayers[i].visibility != 'hide') {
        theLayers[i].pageY = nextY;
        nextY              += theLayers[i].document.height;
      }
    }
  }
} // end of the 'nsArrangeList()' function


/**
 * Expand databases at startup
 *
 * @access  public
 */
function nsShowAll() {
  var theLayers = document.layers;
  var layersCnt = theLayers.length;
  for (i = firstInd; i < layersCnt; i++) {
    theLayers[i].visibility = 'show';
  }
} // end of the 'nsShowAll()' function


/**
 * Collapses databases at startup
 *
 * @access  public
 */
  function initIt()
  {
    if (!capable)
      return;
 
    if (isDOM) {
      var tempColl    = document.getElementsByTagName('DIV');
      var tempCollCnt = tempColl.length;
      for (var i = 0; i < tempCollCnt; i++) {
        if (tempColl[i].id == expandedDb) {
          tempColl[i].style.display = 'block';
        } else if (tempColl[i].className == 'child') {
          tempColl[i].style.display = 'none';
        }
      }

if ((menupart == '1') || (menupart == '50')) { tempColl[2].style.display = 'block'; el1Img.src = imgOpened.src; }
if ((menupart == '2') || (menupart == '51')) { tempColl[4].style.display = 'block'; el2Img.src = imgOpened.src; }
if ((menupart == '3') || (menupart == '52')) { tempColl[6].style.display = 'block'; el3Img.src = imgOpened.src; }
if ((menupart == '4') || (menupart == '53')) { tempColl[8].style.display = 'block'; el4Img.src = imgOpened.src; }
if ((menupart == '5') || (menupart == '54')) { tempColl[10].style.display = 'block'; el5Img.src = imgOpened.src; }
if ((menupart == '6') || (menupart == '55')) { tempColl[12].style.display = 'block'; el6Img.src = imgOpened.src; }
if ((menupart == '7') || (menupart == '56')) { tempColl[14].style.display = 'block'; el7Img.src = imgOpened.src; }
if ((menupart == '8') || (menupart == '57')) { tempColl[16].style.display = 'block'; el8Img.src = imgOpened.src; }
if ((menupart == '8') || (menupart == '58')) { tempColl[18].style.display = 'block'; el9Img.src = imgOpened.src; }
    } // end of the DOM case
    else if (isIE4) {
      tempColl        = document.all.tags('DIV');
      var tempCollCnt = tempColl.length;
      for (var i = 0; i < tempCollCnt; i++) {
        if (tempColl(i).id == expandedDb)
          tempColl(i).style.display = 'block';
        else if (tempColl(i).className == 'child')
          tempColl(i).style.display = 'none';
      }

if ((menupart == '1') || (menupart == '50')) { tempColl[2].style.display = 'block'; el1Img.src = imgOpened.src; }
if ((menupart == '2') || (menupart == '51')) { tempColl[4].style.display = 'block'; el2Img.src = imgOpened.src; }
if ((menupart == '3') || (menupart == '52')) { tempColl[6].style.display = 'block'; el3Img.src = imgOpened.src; }
if ((menupart == '4') || (menupart == '53')) { tempColl[8].style.display = 'block'; el4Img.src = imgOpened.src; }
if ((menupart == '5') || (menupart == '54')) { tempColl[10].style.display = 'block'; el5Img.src = imgOpened.src; }
if ((menupart == '6') || (menupart == '55')) { tempColl[12].style.display = 'block'; el6Img.src = imgOpened.src; }
if ((menupart == '7') || (menupart == '56')) { tempColl[14].style.display = 'block'; el7Img.src = imgOpened.src; }
if ((menupart == '8') || (menupart == '57')) { tempColl[16].style.display = 'block'; el8Img.src = imgOpened.src; }
if ((menupart == '9') || (menupart == '58')) { tempColl[18].style.display = 'block'; el9Img.src = imgOpened.src; }

    } // end of the IE4 case
    else if (isNS4) {
      var theLayers  = document.layers;
      var layersCnt  = theLayers.length;
      for (var i = 0; i < layersCnt; i++) {
       if (theLayers[i].id == expandedDb)
          theLayers[i].visibility   = 'hide';
        else if (theLayers[i].id.indexOf('Child') != -1)
          theLayers[i].visibility   = 'hide';
        else
          theLayers[i].visibility   = 'show';
      }

if ((menupart == '1') || (menupart == '50')) { theLayers[2].visibility = 'show'; el1Img.src = imgOpened.src; }
if ((menupart == '2') || (menupart == '51')) { theLayers[4].visibility = 'show'; el2Img.src = imgOpened.src; }
if ((menupart == '3') || (menupart == '52')) { theLayers[6].visibility = 'show'; el3Img.src = imgOpened.src; }
if ((menupart == '4') || (menupart == '53')) { theLayers[8].visibility = 'show'; el4Img.src = imgOpened.src; }
if ((menupart == '5') || (menupart == '54')) { theLayers[10].visibility = 'show'; el5Img.src = imgOpened.src; }
if ((menupart == '6') || (menupart == '55')) { theLayers[12].visibility = 'show'; el6Img.src = imgOpened.src; }
if ((menupart == '7') || (menupart == '56')) { theLayers[14].visibility = 'show'; el7Img.src = imgOpened.src; }
if ((menupart == '8') || (menupart == '57')) { theLayers[16].visibility = 'show'; el8Img.src = imgOpened.src; }
if ((menupart == '9') || (menupart == '58')) { theLayers[18].visibility = 'show'; el9Img.src = imgOpened.src; }
      nsArrangeList();
    } // end of the NS4 case
  } // end of the 'initIt()' function

/**
 * Collapses/expands a database when the user require this to be done
 *
 * @param  string  the  name of the room to act on
 * @param  boolean whether to expand or to collapse the database content
 *
 * @access  public
 */
function expandBase(el, unexpand)
{
  if (!capable)
    return;

  if (isDOM) {
    var whichEl = document.getElementById(el + 'Child');
    var whichIm = document.getElementById(el + 'Img');
    if (whichEl.style.display == 'none' && whichIm) {
      whichEl.style.display  = 'block';
      whichIm.src            = imgOpened.src;
    }
    else if (unexpand) {
      whichEl.style.display  = 'none';
      whichIm.src            = imgClosed.src;
    }
  } // end of the DOM case
  else if (isIE4) {
    var whichEl = document.all(el + 'Child');
    var whichIm = document.images.item(el + 'Child');
    if (whichEl.style.display == 'none') {
      whichEl.style.display  = 'block';
      whichIm.src            = imgOpened.src;
    }
    else if (unexpand) {
      whichEl.style.display  = 'none';
      whichIm.src            = imgClosed.src;
    }
  } // end of the IE4 case
  else if (isNS4) {
    var whichEl = document.layers[el + 'Child'];
    var whichIm = document.layers[el + 'Parent'].document.images['imEx'];
    if (whichEl.visibility == 'hide') {
      whichEl.visibility  = 'show';
      whichIm.src         = imgOpened.src;
    }
    else if (unexpand) {
      whichEl.visibility  = 'hide';
      whichIm.src         = imgClosed.src;
    }
    nsArrangeList();
  } // end of the NS4 case
} // end of the 'expandBase()' function


/**
 * Add styles for positioned layers
 */

if (capable) {
  with (document) {
    // Brian Birtles : This is not the ideal method of doing this
    // but under the 7th June '00 Mozilla build (and many before
    // it) Mozilla did not treat text between <style> tags as
    // style information unless it was written with the one call
    // to write().
    if (isDOM) {
      var lstyle = '<style type="text/css">'
                 + '.parent {display:block}'
                 + '.child {display:none}'
                 + '<\/style>';
      write(lstyle);
    }
    else {
      write('<style type="text/css">');
      if (isIE4) {
        write('.child {display:none}');
      }
      else {
        write('.parent {visibility:hidden}');
        write('.child {visibility:hidden}');
        write('.regular {position:absolute; visibility:hidden}');
      }
      write('<\/style>');
    }
  }
} // end of adding styles

onload = initIt;
