/*  cookies.js
    $Id: cookies.js,v 1.2 2004/09/07 19:38:01 dferruggia Exp $ */

//#############################################################################
//#
//# allowCookies - checks if browser will accept cookies 
//#                   
function allowCookies(popupURL)
{   
	var cookieValue = getCookie('SESSION_ID');
	if (cookieValue)
	{
		return true;
	}
	if( popupURL != "" && popupURL != null ) window.open(popupURL,'','width=400,height=225');
	
	return false;
}

//#############################################################################
//#
//# deleteCookie - delete a cookie from the users machine
//#
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";
  }
}

//#############################################################################
//#
//# getCookie - retrieve a cookie from the users machine
//#
function getCookie(name) 
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
  	begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } 
  else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

//#############################################################################
//#
//# setCookie - set a cookie from the users machine
//#
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;
}
