function getWidth() {
  var myWidth = 0;
  if ( typeof( window.innerWidth ) == 'number' ) {
    // Non-IE
    myWidth = window.innerWidth;
  } else if ( document.documentElement && document.documentElement.clientWidth ) {
    // IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else {
    myWidth = document.body.clientWidth;
  }
  
  return myWidth;
}

function getHeight() {
  var myHeight = 0;
  if ( typeof( window.innerHeight ) == 'number' ) {
    // Non-IE
    myHeight = window.innerHeight;
  } else if ( document.documentElement && document.documentElement.clientHeight ) {
    // IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else {
    myHeight = document.body.clientHeight;
  }
  
  return myHeight;
}

function getElementHeight(Elem) {
  if(document.getElementById) {
    var elem = document.getElementById(Elem);
  } else if (document.all){
    var elem = document.all[Elem];
  }
  return elem.offsetHeight;
}

function getElementWidth(Elem) {
  if(document.getElementById) {
    var elem = document.getElementById(Elem);
  } else if (document.all){
    var elem = document.all[Elem];
  }
  return elem.offsetWidth;
}

function setContentWidth() {
  if (!document.getElementById('container'))
    return false;
  var clientWidth = getWidth();
  var myWidth = clientWidth < 780 ? '780px' : clientWidth > 1000 ? '1000px' : (clientWidth + 'px');
  document.getElementById('container').style.width = myWidth;
}

function setContentHeight() {
  if (!document.getElementById('content') || !document.getElementById('contentcontainer'))
    return false;
  var contentHeight = getElementHeight('content');
  var myHeight = ( contentHeight > 500 ? contentHeight : 500 ) + 'px';
  document.getElementById('contentcontainer').style.height = myHeight;
  document.getElementById('contentleft').style.height = myHeight;
  document.getElementById('contentright').style.height = myHeight;
}

function setContentDims() {
  setContentWidth();
  setContentHeight();
}

function trim(str) {
    str = str.replace(/\s+/g, " ");
    str = str.replace(/^\s*?(\S[\s|\S]*?)\s*?$/, "$1");
    
    return str;
}

function setCurrent(itemId) {
  if(document.getElementById) {
    var theItem = document.getElementById(itemId);
  } else if (document.all){
    var theItem = document.all[itemId];
  }
  
  if (!theItem)
    return false;
  if ( !theItem.className.match("current") ) {
    var classes = theItem.className.split(" ");
    theItem.className = theItem.className + " " + classes.join("current ");
    theItem.className = theItem.className + "current";
  }
  
  return true;
}

function removeCurrent(itemId) {
  if(document.getElementById) {
    var theItem = document.getElementById(itemId);
  } else if (document.all){
    var theItem = document.all[itemId];
  }
  
  if (!theItem)
    return false;

  theItem.className = trim(theItem.className.replace(/\S*?current/g, ""));
}

function showItem(theItem) {
  theItem.className = theItem.className.replace(/hide/g, "");
  
  if ( theItem.className.match("show") )
    return;
    
  theItem.className = theItem.className + " show";
  theItem.className = trim( theItem.className );
}

function hideItem(theItem) {
  theItem.className.replace(/show/g, " ");

  if ( theItem.className.match("hide") )
    return;
    
  theItem.className = theItem.className + " hide";
  theItem.className = trim(theItem.className);
}

function closeAllObjects(tagType, itemType) {
  var allObjs = document.getElementsByTagName(tagType);
  var myRegEx = new RegExp(itemType+'$');
  
  for ( var i = 0; i < allObjs.length; i++ ) {
    if ( myRegEx.test(allObjs[i].id) ) {
      hideItem(allObjs[i]);
      
      var menuItem = document.getElementById(allObjs[i].id.replace(myRegEx, ""));
      if (menuItem) {
        removeCurrent(menuItem.id);
      }
    }
  }
}

function toggleMenuItem(itemId, itemType) {
  var targetId = itemId + itemType;
  var menuItem = document.getElementById(itemId);
  var targetItem = document.getElementById(targetId);

  if (!menuItem || !targetItem)
    return false;

  if (targetItem.className.match("hide")) {
    closeAllObjects('div', itemType);
    showItem(targetItem);
    setCurrent(menuItem.id);
  } else {
    hideItem(targetItem)
    removeCurrent(menuItem.id);
    
    if ( itemType == "Div" && document.getElementById('mainDiv') ) {
      showItem(document.getElementById('mainDiv'));
      setCurrent('main');
    }
  }
  
  setContentDims();
 
  return true;  
}

function swapImage(place, image) {
  var imgLoc = document.getElementById(place);
  if (imgLoc)
    imgLoc.src = image;
  return true;
}
