/*
 * menuExpandable3.js - implements an expandable menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 * 11/27/07 now uses cookies, so that state is not lost when switching pages (R. Hawley)
 * There are better ways to save menu state, but would involve major code changes
 */

/*if (!document.getElementById)
    document.getElementById = function() { return null; }*/

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    // if there is a cookie, get the old status
    enabled = getCookie(menu.id);

    // TODO: Check to see that the referrer fo this page is data.php
    // if not reset all cookies to N
    if (enabled == "Y") {
	menu.style.display = "block";
    } else {
	menu.style.display = "none";
    }
    
   
    actuator.onclick = function() {
        var display = menu.style.display;
        if (display == "block") { 
		menu.style.display =  "none";
		document.cookie = menu.id + "=N";
	} else {
		menu.style.display =  "block";
		document.cookie = menu.id + "=Y";
	}

        return false;
    }
}

// w3schools cookies tutorial
function getCookie(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 document.cookie.substring(c_start,c_end)
    } 
  }
return ""
}




