/* id of element to toggle, isOn is either 1 or 0 or not present.  If not present, then will toggle */
function toggleDisplay(id,isOn) {
  var obj = document.getElementById(id);
  if (!obj) return false;

  if (isOn == 0) {	 
	 obj.style.display = 'none';
     return true;
	 }
  if (isOn == 1) {
	 obj.style.display = 'block';
     return true;
     }
  obj.style.display = (obj.style.display == 'none') ? 'block' : 'none';
  return true;
}
/* closeTab and changeTab are used to display and hide divs on the page
   The divs do not have to be tabs
   changeTab(obj, number);  -- obj is the object of the 
   */
var tabActiveArray=new Array();
function closeTab(instance) {
  var inst = (!instance ? 1 : instance);
  var tabActiveObj = (inst <= tabActiveArray.length ? tabActiveArray[inst] : '');
     if (tabActiveObj) {
      //tabActiveObj.className='normal';
      tabActiveObj.className= tabActiveObj.className.replace('active','');
	  tabID = tabActiveObj.id;
      pageObj = document.getElementById(tabID + 'Body');
      if (pageObj) { pageObj.style.display='none'; }
      else {
         pageObj = document.getElementById('allBody');
         pageObj.style.display='none';
         }
      tabActiveArray[inst]='';
     }
  return true;
}
function initTab(tabObj,instance) {
  var tabObj;
  var inst = (!instance ? 1 : instance);
  if (!tabObj) { return false };
  var tabActiveObj = (inst <= tabActiveArray.length ? tabActiveArray[inst] : '');
     if (!tabActiveObj) {
        tabActiveArray[inst]=tabObj;
		}
  return true;
}
function changeTab(tabName,instance) {
  var tabID=0;
  var pageObj;
  var tabObj = document.getElementById(tabName);
  var inst = (!instance ? 1 : instance);
  closeTab(inst);
  if (!tabObj) { return false };
  tabID = tabObj.id;
  pageObj = document.getElementById(tabID + 'Body');
  tabObj.className='active';
  tabActiveArray[inst]=tabObj;
  if (!pageObj) {
     pageObj = document.getElementById('allBody');
  }
  pageObj.style.display='block';
  return true;
}
function initialize(tabName) {
  var tabObj = document.getElementById(tabName);
  initTab(tabObj);
  changeTab(tabName);  
  return true;
}
function switchTab(tabName) {
  document.getElementById('cat').value=tabName;
  changeTab(tabName);
  return false;
}
