
/*
 * sccsid = '@(#) 1.18 wt/wtp/htdocs/scripts/toolbar_2.js, wtcode, jtime71 4/12/05 09:57:03'
 *
 * toolbar.js
 *
 * (C) COPYRIGHT Journyx, Inc 1997 - 2005
 *  All Rights Reserved
 *  Licensed Materials - Property of Journyx, Inc.
 *
 */


var intPrimaryContainerWidthShort = 0;
var intPrimaryContainerWidthLong = 0;


function fncToggleToolbar() {

  var ToolbarContainer = document.getElementById("idToolbarContainer");
  var PrimaryContainer = document.getElementById("idPrimaryContainer");
  var ToolbarOpenTriggerContainer = document.getElementById("idToolbarOpenTriggerContainer");
  var PrimaryTabs = document.getElementById("idPrimaryTabs");

  if (ToolbarContainer != null) {

    // The technique we are using here to see whether the toolbar is
    // currently open or closed is to look at the offsetHeight variable.
    // This will be 0 if the toolbar is closed.  Previously we were looking
    // at ToolbarContainer.style.display, but this turned out to be unreliable

    // window.alert("ToolbarContainer.offsetHeight: <" + ToolbarContainer.offsetHeight + ">");

    if (ToolbarContainer.offsetHeight) {

      // Toolbar is visible, close it      
      if (intPrimaryContainerWidthShort < 1) {
        intPrimaryContainerWidthShort = PrimaryContainer.offsetWidth;
      }
      if (intPrimaryContainerWidthLong > 0) {
        PrimaryContainer.width = intPrimaryContainerWidthLong;
      }
      
      ToolbarContainer.style.display = "none";
      ToolbarOpenTriggerContainer.style.display = "block";
      PrimaryContainer.style.paddingLeft = "0.2em"; 

      // Add some padding for the main nav tabs so the toolbar-open button 
      // doesn't get lost under the nav tabs. 
      if (PrimaryTabs != null) {

		// This is a magic toolbar width number! 
		// The value here should be slightly LESS than the toolbar width
		// which is currently 13.5 and established in jx_corestyle.css
		// and the #idPrimaryContainer padding-left property

        PrimaryTabs.style.marginLeft = "13.25em"; 
      }
            
      // Set a cookie to remember the closed state of the Toolbar
      setCookie('tb_open','0','never','/', '', '');  // jsgenlib.js
    }
    else {
      // Toolbar is hidden, open it
      // window.alert("Opening toolbar.");

	  // This function is defined in calendar-setup.js.  It
	  // automatically skips re-initializing the calendar if it's
	  // already been inited once in this page view.
	  //
	  initializeToolbarCalendar();
      
      if (intPrimaryContainerWidthLong < 1) {
        intPrimaryContainerWidthLong = PrimaryContainer.offsetWidth;
      }
      if (intPrimaryContainerWidthShort > 0) {
        PrimaryContainer.width = intPrimaryContainerWidthShort;
      }

      ToolbarContainer.style.display = "block";

      ToolbarOpenTriggerContainer.style.width = "0px";
      ToolbarOpenTriggerContainer.style.display = "none";

      PrimaryContainer.style.paddingLeft = "13.5em";  // XXX TODO magic toolbar width number

      if (PrimaryTabs != null) {
        PrimaryTabs.style.marginLeft = "0px";
      }
      
      // Set a cookie to remember the open state of the Toolbar
      setCookie('tb_open','1','never','/', '', '');  // jsgenlib.js
    }
  }

  if (typeof(fncPageStateChange) == "function") {
    fncPageStateChange();  // timeTables.js
  }
}

function fncToggleToolbarModule(moduleid, blnForceOpen) {
  // fncToggleToolbarModule opens and closes a module in the Toolbar and
  //   sets a cookie to remember it's state.


  // If we're toggling the time calendar, initialize it.  The function
  // is smart enough to skip the work if it's already been initialized
  // on this pageview.
  //
  if (moduleid == 'TimeCalendar') {
	initializeToolbarCalendar(); 
  }

  var ToolbarContainer = document.getElementById("idToolbarContainer");

  if (ToolbarContainer != null) {
    if (ToolbarContainer.style.display != "none") {

      var TheModule = document.getElementById("idToolbarTitle" + moduleid);
      var TheContent = document.getElementById("idToolbarContent" + moduleid);

      if (TheModule != null && TheContent != null) {
        if (TheModule.className != "clsToolbarTitleOpen" || blnForceOpen) {
		  DoModuleOpen(moduleid);
		}
        else {
		  DoModuleClose(moduleid);
        }
      }
    }
  }  
}


function DoModuleOpen(moduleid) {
  var TheModule = document.getElementById("idToolbarTitle" + moduleid);
  var TheContent = document.getElementById("idToolbarContent" + moduleid);

  if (TheModule && TheContent) {
	// window.alert('Opening module ' + moduleid); // XXX TODO
	TheModule.title = "Click to Close this Module";
	TheModule.className = "clsToolbarTitleOpen";
	TheContent.style.display = "block";
	setCookie('tb_mod'+moduleid,'1','never','/', '', ''); // jsgenlib.js
  }
  else {
	// window.alert('NOT Opening module ' + moduleid); // XXX TODO
  }
}

function DoModuleClose(moduleid) {

  var TheModule = document.getElementById("idToolbarTitle" + moduleid);
  var TheContent = document.getElementById("idToolbarContent" + moduleid);

  if (TheModule && TheContent) {
	// window.alert('Closing module ' + moduleid); // XXX TODO
	TheModule.title = "Click to Open this Module";
	TheModule.className = "clsToolbarTitleClose";
	TheContent.style.display = "none";
	setCookie('tb_mod'+moduleid,'0','never','/', '', ''); // jsgenlib.js
  }
  else {
	// window.alert('NOT Opening module ' + moduleid); // XXX TODO
  }

}


