/**
 *  Returns a boolean determining if the cookie exists.
 */
function checkCookie(name) {
	cookieVal = document.cookie;

	if( cookieVal.indexOf(eval("'" + name + "'")) > -1 ) {
		return true;
	} else {
		return false;
	}
}


/**
 *  Sends the cookie to the users browser with the
 *  specified expiration date (GMT).
 */
function setCookieValue(name,value,expires) {
	var expireDate = new Date(expires);
	var theCookie = name + "=" + escape(value) + "; expires=" + expireDate.toGMTString() + "; path=/";
	document.cookie = theCookie;
}



/**
 *  Returns the actual value of the given cookie name.
 */
function getCookieValue(name) {
	var temp = document.cookie+";";
	var Pos = temp.indexOf("=",temp.indexOf(name+"="));
	if (temp.indexOf(name+"=") == -1) {
		return "";
	}
	return temp.substring(Pos+1,temp.indexOf(";",Pos));
}


/**
 *  Returns a boolean indicating wether or not the browser
 *  accepts cookies.
 */
function cookiesEnabled() {
  if (document.all) {
    if (!navigator.cookieEnabled) {
		return false;
    } else {
		return true;
	}
  } else {
	var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
    setCookieValue('check','check',expires);
    var temp = getCookieValue('check');
    if (!temp) {
		return false;
    } else {
		return true;
	}
  }
}


/**
 *  Deletes the specified cookie name from the users system.
 */
function deleteCookie(name, path, domain) {
  var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
  (path)    ? ';path='    + path                  : '';
  (domain)  ? ';domain='  + domain                : '';

  if (getCookieValue(name)) {
    document.cookie = name + '=' + expires + path + domain;
  }
}


/**
 *  Returns an expired date for cookies.
 */
function getExpiredDate() {
	var today = new Date();
	var yesterday = new Date();
	yesterday.setDate(today.getDate()-1);
	yesterday.setHours(0);
	yesterday.setMinutes(0);
	yesterday.setSeconds(1);
	return yesterday;
}
