/**
 Copyright 2010 1fb.net Financial Services.
  
 This document may not be reproduced, distributed or used 
 in any manner whatsoever without the expressed written 
 permission of 1st Financial Bank USA. 
**/

/**
 * @constructor
 */
function CookieUtil(){}

/**
 * Get cookie value by name
 */
CookieUtil.getCookie = function(cookieName) {
	var start = document.cookie.indexOf(cookieName + "=");
	var len = start + cookieName.length + 1;
	if ((!start) && (cookieName != document.cookie.substring(0, cookieName.length))) {
		return null;
	}
	if (start == -1)
		return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1)
		end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

/**
 * set cookie
 * cookieName - the cookie name
 * value - the cookie value
 * expYear - year of expiration
 * expMonth - month of expiration
 * expDay - day of expiration
 * path - cookie path
 * domain - cookie domain
 * secure - secure or not
 */
CookieUtil.setCookie = function(cookieName, value, expYear, expMonth, expDay, path, domain, secure) {
	var cookie_string = cookieName + "=" + escape(value);
	if (expYear) {
		var expires = new Date(expYear, expMonth, expDay);
		cookie_string += "; expires=" + expires.toGMTString();
	}

	if (path){
		cookie_string += "; path=" + escape(path);
	} else {
		cookie_string += "; path=/";
	}

	if (domain)
		cookie_string += "; domain=" + escape(domain);

	if (secure)
		cookie_string += "; secure";

	document.cookie = cookie_string;
}

/**
 * remove cookie by name
 */
CookieUtil.removeCookie = function(cookieName) {
	var cookieDate = new Date(); // current date & time
	cookieDate.setTime(cookieDate.getTime() - 1);
	document.cookie = cookieName + "=; expires=" + cookieDate.toGMTString();
}

