//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <bdortch@netw.com>
//  The following functions are released to the public domain.

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 4) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain));
}

function DeleteCookie(name){
exp=new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie ("name");
document.cookie = name + "=" + cval +"; expires=" + exp.toGMTString();
}



//  nixtasinks Cookie Functions
//  Dependent upon Bill Dortch's cookie functions
function SetTabCookie(tab_name)
{
	var span_name = GetSpanName(tab_name);
	var the_span = document.getElementById(span_name);
	if (the_span != null)
	{
		var span_display_style = the_span.style.display;
		var cookie_name = GetCookieName(tab_name);
		nd= new Date();
		nd.setTime (nd.getTime()+(365*24*60*60*1000));
		cdomain = (location.domain) ? location.domain : null;
		cpath = (location.domain) ? location.pathname : null;
		SetCookie (cookie_name, span_display_style, nd, cpath, cdomain);
	}
}

function SetTabByCookie(tab_name, cookie_val)
{
	var span_name = GetSpanName(tab_name);
	var the_span = document.getElementById(span_name);
	if (the_span != null)
	{
	  the_span.style.display = cookie_val;
	}  
}

function GetCookieName(id) { return "c_" + id; }
function GetSpanName(id) { return id + "_span"; }

function TabClick(tab_name)
{
  var span_name = GetSpanName(tab_name);
  ToggleThingT(span_name);
  SetTabCookie(tab_name);
  return false;
}

function DoCookieForTab(tab_name)
{
  var cookie_name = GetCookieName(tab_name);
  var cookie_val = GetCookie(cookie_name);
  if (cookie_val==null)
  {
     SetTabCookie(tab_name);
  }
  else
  {
     SetTabByCookie(tab_name, cookie_val);
  }
}