function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

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) {
  // Try to make cookie retrieval case insensitive by
  // fetching the case sensitive cookie name using
  // getRealCookieName. If that doesn't work, just
  // use the original request name
  var temp = getRealCookieName(name);
  if (temp != null)
	name = temp;

  for(var i = 0; i < name.length; i++)
		if (name.charAt(i) == " ")
			name = name.substring(0, i) + "+" + name.substring(i+1, name.length);

  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
	{
	  //modified to escape + signs, 8/26/98, John Richter
	  var outVal = getCookieVal(j);
	  for (i = 0; i < outVal.length; i++)
		if (outVal.charAt(i) == "+")
			outVal = outVal.substring(0, i) + " " + outVal.substring(i+1, outVal.length);
      return outVal;
	}
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function checkCookieOnNav(URLifBad, URLifGood)
{
	SetCookie ("testCookie", "cookieTest", null, "/", ".yale.edu");
	tester = GetCookie ("testCookie");
	if (tester == null)
		location.href = URLifBad;
	else
		location.href = URLifGood;
}

function getRealCookieName(name) {
	name = name.toUpperCase();
	for(var i = 0; i < name.length; i++)
		if (name.charAt(i) == " ")
			name = name.substring(0, i) + "+" + name.substring(i+1, name.length);

	var index = document.cookie.toUpperCase().indexOf(name.toUpperCase()+"=");
	if (index == -1) {
		return null;
	}
	return document.cookie.substr(index, name.length);
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
	// Try to make cookie retrieval case insensitive by
	// fetching the case sensitive cookie name using
	// getRealCookieName. If that doesn't work, just
	// use the original request name
	var temp = getRealCookieName(name);
	if (temp != null)
		name = temp;
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
