// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie(name, value, expires, path, domain, secure) 
{
  var curCookie = name + "=" + escape(value) + 
                  (expires ? "; expires=" + expires.toGMTString() : "") + 
                  (path ? "; path=" + path : "") + 
                  (domain ? "; domain=" + domain : "") +  
                  (secure ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) 
{
  var prefix = name + "=";
  var nullstring = "";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if (cookieStartIndex == -1)
    return nullstring;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex 
	+ prefix.length);
  if (cookieEndIndex == -1)
    cookieEndIndex = document.cookie.length;
  return unescape(document.cookie.substring(cookieStartIndex 
	+ prefix.length, cookieEndIndex));
}

function deleteCookie(name, path, domain) 
{
  if (getCookie(name)) 
  {
    document.cookie = name + "=" + ((path) ? "; path=" + path : "") 
	+ ((domain) ? "; domain=" + domain : "") 
	+ "; expires=Thu, 01-Jan-70 00:00:01 GMT"
  };
}

function fixDate(date) 
{
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

var domain = null; /* Don't put domain in cookie - it's  not needed, and may stop cookie working*/
var path = '/weblog'

function setGMcookies() 
{
  if (document.newcomment.bakecookie.checked)
  {
    var now = new Date();
    fixDate(now); 
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); 
    setCookie('gmcmtauth', document.forms['newcomment'].newcommentauthor.value,   now, path, domain,''); 
    setCookie('gmcmtmail', document.forms['newcomment'].newcommentemail.value ,   now, path, domain,''); 
    setCookie('gmcmthome', document.forms['newcomment'].newcommenthomepage.value, now, path, domain,''); 
  }
}	 

function getGMcookies()
{
  document.forms['newcomment'].newcommentemail.value = getCookie("gmcmtmail");
  document.forms['newcomment'].newcommentauthor.value = getCookie("gmcmtauth");
  document.forms['newcomment'].newcommenthomepage.value = getCookie("gmcmthome");
}

function deleteGMcookies() 
{
  deleteCookie('gmcmtmail','',domain);
  deleteCookie('gmcmthome','',domain);
  deleteCookie('gmcmtauth','',domain);
  document.newcomment.newcommentemail.value =    '';
  document.newcomment.newcommentauthor.value =   '';
  document.newcomment.newcommenthomepage.value = '';	
}	

