function emSetCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function emGetCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
      } 
  }
  return ""
}

function getLinkText() {
  return showTools? 'Hide Toolbar' : 'Show Toolbar';
}

function getDisplayClass() {
  return showTools? 'shown' : 'hidden';
}

function toggleTools() {
   showTools = !showTools;
   document.getElementById("showHideToolsLink").innerHTML = getLinkText();
   document.getElementById("toolbar").className = getDisplayClass();
   emSetCookie('show-tools',showTools?'true':'false',365);
}

function initToolbar() {
  // over-ride with cookie value if there is one
  var showToolsCookie = emGetCookie('show-tools');
  if (showToolsCookie != '') {
     showTools = (showToolsCookie=='true');
  }
  
  // set the CSS class for the tools menu
  if (document.getElementById("showHideToolsLink")) {
   document.getElementById("showHideToolsLink").innerHTML = getLinkText();
   document.getElementById("toolbar").className = getDisplayClass();
  }
}

function toggleMenu() {
  showMenu = !showMenu;
  var menupage = document.getElementById("menupage");
  var content = document.getElementById("content");  
  var container = document.getElementById("container")
  if (showMenu) {
    if (menupage) menupage.style.display='inline';
    if (content) content.style.width='620px';
    if (container) container.style.width='550px';    
  } else {
    if (menupage) menupage.style.display='none';
    if (content) content.style.width='860px';
    if (container) container.style.width='810px';    
  }    
  emSetCookie('show-menu',showMenu?'true':'false',365);
}

function initMenu() {
  // over-ride with cookie value if there is one
  var showMenuCookie = emGetCookie('show-menu');
  if (showMenuCookie != '') {
     showMenu = (showMenuCookie=='true');
  }  
  if (!showMenu) {
    showMenu = !showMenu;
    toggleMenu();
  }
}



