/**
 * Cookie support for world enough
 *
 * $Revision: 1.7 $
 *
 */

/*
 * $Log$
 */
 
/**
 * format an expiry date for a cookie ndays into the future
 */
function getexpirydate( ndays)
{
  	var date = new Date();
  	date.setTime(Date.parse( new Date()) + ( ndays*24*60*60*1000));
  	return date.toUTCString();
}

/**
 * get the cookie with this name from among my cookies
 */
function getCookie(cookiename) 
{
  	var cookieString=""+document.cookie;
  	var index1=cookieString.indexOf(cookiename);

  	if (index1 > -1 )
  	{   
    	var index2=cookieString.indexOf(';',index1);
    	if (index2==-1) 
    		index2=cookieString.length; 
    	return unescape(cookieString.substring(index1+cookiename.length+1,index2));
  	}
  	else
  	{
    	return null;
  	}
}

/**
 * set a cookie with this name to this value for this duration
 */
function setCookie(name,value,duration)
{
  	var cookieString=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);

  	document.cookie=cookieString;

  	if( getCookie(name))
  	{
  	  	return true;
  	}
  	else
  	{
  	  	return false;
  	}
}
