function setCookie(cName,cVal) {
//	sets a cookie for cName to cVal
	var cookieContent;
	cookieContent = cName + '=' + cVal;
	var expireDate = new Date();
	expireDate.setTime(expireDate.getTime() + (365*24*60*60*1000));		// 1 yr = d*h*m*s*ms
	cookieContent += ";expires=" + expireDate.toGMTString();
	cookieContent += ";path=/";
	document.cookie = cookieContent;					// write cookie
}

function readCookie(cName) {
//	returns the value of the cookie named cName
	var cGet = unescape(document.cookie);
	var cLen = document.cookie.length;           // length of cookie
	var nLen = cName.length+1;                   // length of cookie name + '='
	var cBase = cGet.indexOf(cName, 0);          // find the index of the desired name/value pair
	if (cBase == -1)                             // name/value not found
		cVal = 'NOT FOUND';
	else {
		var cEnd = cGet.indexOf (";", cBase+nLen); // start at end of 'cName=' and look for ';'
		if (cEnd == -1)                            // no trailing ';' (last n/v pair in cookie)
			cEnd = cGet.length;                      // ...so will go to the end
		var cVal = unescape(cGet.substring(cBase+nLen, cEnd)); // read from '=' to ';' or end
	}
	return (cVal);
}

function setBranch(branch, goTo) {
/*	sets the 'branch' cookie to value in branch (either 'BG' or 'BF')
		then reloads the page to that specified in goto (requires link from site root '/')
*/
	setCookie('branch', branch);
	location.href = goTo;
}

function checkBranch(goBG, goBF) {
/*	checks the value of the 'branch' cookie (either 'BG' or 'BF')
		then reloads the page to that specified in goBG or
		goBF (requires link from site root '/'), respectively
		If the cookie does not contain one of the acceptable
		values, BG is written as default.
*/
	var cVal = readCookie('branch');
	if (cVal == 'BF')
		location.href = goBF;  /* location.replace(); alters history */
	else if (cVal == 'BG')
		location.href = goBG;
	else
		setBranch('BG',goBG);
}

function setName(fname, lname) {
	setCookie('fname', fname);
	setCookie('lname', lname);
}

function login() {
	setCookie('loginfrom', document.URL);
	location.replace('http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=aaa&club=032&page=ClubConfig41');
}

function loginReturn() {
	var dest = readCookie('loginfrom');
	location.replace(dest);
}



/*
function delCookies() {
// http://www.juicystudio.com/tutorial/javascript/cookies.html
    if (document.cookie != "") {
        var cookieInfo, cookieData, counter;
        var expireDate = new Date();
        // Set the expiration date to yesterday
        expireDate.setDate(expireDate.getDate() - 1);
        cookieInfo = document.cookie.split("; ");
		for (counter=0; counter<cookieInfo.length; counter++) {
			// Get the cookie name
			cookieData = cookieInfo[counter].split("=")[0];
			// Add a null value and the expiration date
			cookieData += "=;expires=" + expireDate.toGMTString();
			// Expire the cookie
			document.cookie = cookieData; 
		}
    }
}
*/
