/**************************************************************************** 
	The following functions are used to get, set and delete cookies
	Note: cookies are found (using getCookie) from subdomains (i.e. 
	*.domain.com) and subpaths (i.e. /path/to/calling/path/*).
	When deleting cookies, the path and domain must be the same as when set.
	
	Created by Klas Skogmar 2004-01-16
*****************************************************************************/

/**
	name - the name of the cookie. Only one cookie with the same name can exist.
	value - the value of the cookie
	path - the path (and subpaths) that the cookie should be valid for
	domain - the domain and subdomains that the cookie should be valid for
	expires - the time when the cookie will expire
*/
function setCookie(name, value, expires, path, domain, secure) {
	if(!expires) { expires = new Date(); expires.setDate(expires.getDate()+365); }
	document.cookie = name + "=" + escape(value) +
      "; expires=" + expires.toGMTString() +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}
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 getCookie(name) {
	var cookie_start = document.cookie.indexOf(name + "=");
	if(cookie_start == -1) return null;
	var cookie_end = document.cookie.indexOf("; ", cookie_start);
	if(cookie_end == -1) cookie_end = document.cookie.length;
	return unescape(document.cookie.substring(cookie_start + name.length + 1, cookie_end));
}