window.toggleDiv = function(){
  /*
   Purpose: Toggle DIV structures open/close via class reassignment and event capture at a macro level.

   Notes:   Incorrectly nested DIV's do not register on the DOM and won't work here... 
            make sure your HTML is well-formed.  (symptom... clicks on bad DIV's bubble up to 
            the closest parent DIV)

   Usage:   Wrap your dynamic DIV's between...
            <div class="mToggle" onclick="if(window.toggleDiv)toggleDiv()"> and </div> 

   Problems/Suggestions? thomas2003*esqsoft^om (antibot: *=@, ^=.c)
   Be sure to visit us at http://ESQSoft.com for scripts, tools, web hosting and more.
  */

  //try to figure out the browser DOM's event model
  var mE = 0
  if(window.event) mE = event
  else if(window.Event){ mE = Event; alert('Well, that\'s a nice browser DOM too, \nMaybe you want to write an Event object handler for it?\nUntil then, this is a friendly "error" message'); return }
  if(!mE){ alert('Error: Non-supporting browser DOM'); return }
  mObj = mE.srcElement


  //get a ref to first DIV north of the source element on the DOM
  this.mSafety = 20;  //die already!
  while(--this.mSafety>0){
    if(mObj.tagName != 'DIV'){
      mObj = mObj.parentElement    
      if(!mObj) this.mSafety = 1; //permit us to drop out of the loop early w/fail (mSafety will == 0)
    }
    else this.mSafety = -1; //drop out of loop w/success (mSafety will == -1)
    --this.mSafety
  }
  if(!this.mSafety) return;  //didn't find a DIV in the srcElement or parent heirarchy


  //persist settings
  if(!mObj.toggle){
    mObj.toggle = 1
    mObj.className = 'mToggleOpen';
  }
  else{
    mObj.toggle = 0
    mObj.className = 'mToggleClosed';
  }
}

