/* --------------------------------------------------------------------------------------------- 
Function that sets a cookie with the desired name and value, expires either in a year
or after the session. Function that reads cookies set by the first function.

version 1, 08/02/2002
version 1.1 20/02/2002 - added exp_date (ID)
version 1.2 01/03/2002 - added optional path and domain (ID)

Copyright (c) Open World Ltd. Written by Iwein, idekoninck@openworld.co.uk
Do not edit this file! Documentation can be found at 
http://iwein.test.openworld.co.uk/javascriptExamples/cookie.html
-----------------------------------------------------------------------------------------------*/

var the_date = new Date();
the_date.setTime(the_date.getTime() + (365*24*60*60*1000));
var exp_date = '; expires=' + the_date.toGMTString();

function setCookie(name, value, expires, path, domain)
	{
	if ( value != 'empty' )
		{
		var setPath =(path) ? '; path=' + path : '; path=/';	
		var setDomain = (domain) ? '; domain=' + domain : '';
		if (expires == 'no')
			{
			document.cookie = name + '=' + escape(value) +'#' + exp_date +setDomain + setPath +  ';' ;
			}
		else
			{
			document.cookie = name + '=' + escape(value) +'#' +setDomain + setPath +  ';' ;
			}
		}
	else
		{
		alert('You are trying to set the value of the cookie to "empty".\nThis is not a good idea, as you will not be able to find out whether the cookie exists or not.');
		}
	}
	
function getCookie(name)
	{
	var theCookie = document.cookie;
	var whichCookie = name + '=';
	var rightCookie = theCookie.indexOf(whichCookie);
	if (rightCookie != -1)
		{
		var startCookie = rightCookie + whichCookie.length;
		var endCookie = theCookie.indexOf('#',startCookie);
		if (endCookie == -1)
			{
			endCookie = theCookie.length;
			}
		var theValue= unescape(theCookie.substring(startCookie, endCookie));
		return theValue;
		}
	else
		{
		var theValue ='empty';
		return theValue;
		}
	}