/*
	If path is specified, use syntax "/path/path", elsewhise supply false
	if domain is specified, use syntax ".domain.com" - note leading dot
*/
function setCookie(cName, cValue, cExpInDays, cPath, cDomain, cSecure) {
	var cString = cName + "=" + escape(cValue);
	if (cExpInDays) {
		var expire_date = new Date();
		var ms_from_now = cExpInDays * 24 * 60 * 60 * 1000;
		expire_date.setTime(expire_date.getTime() + ms_from_now);
		var expire_string = expire_date.toGMTString();
		cString += "; expires=" + expire_string;
	}
	cString += ((cPath) ? "; path=" + cPath : "") + ((cDomain) ? "; domain=" + cDomain : "") + ((cSecure) ? "; secure" : "");
	document.cookie = cString;
}
function getCookie(cName) {
    var dc = document.cookie;
    var fnd =0;
    var cookieList = new Array();
    var aCookie = new Array();
    if (dc) {
        cookieList = dc.split(";");
        fnd = cookieList.length;
    }
    for (var i = 0; i<fnd; i++) {
        aCookie = cookieList[i].split("=");
        if (aCookie.length==2) {
            var temp = aCookie[0].replace(" ","")
            if (temp==cName) {
                return unescape(aCookie[1]);
            }
        }
    }
    return null;
}

/*
	path of the cookie must be same as path used to create cookie
	domain of the cookie must be same as domain used to create cookie
*/
function deleteCookie(cName, cPath, cDomain) {
	if (getCookie(cName)) {
		var cString = cName + "=" + ((cPath) ? "; path=" + cPath : "") + ((cDomain) ? "; domain=" + cDomain : "");
		var expire_date = new Date();
		expire_date.setTime(0);
		var expire_string = expire_date.toGMTString();
		cString += "; expires=" + expire_string;
		document.cookie = cString;
		return true;
	}
	return false;
}

