/*************************/
/* BEGIN VISIBILITY HANDLING */
/*************************/

function toggleVisibility(i) {
	var e = document.getElementById(i);
	var t = e.className;
	if (t.match('invisible')) { t = t.replace(/invisible/gi, 'visible'); }
	else { t = t.replace(/visible/gi, 'invisible'); }
	e.className = t;
}

/*************************/
/* END VISIBILITY HANDLING */
/*************************/

/*************************/
/* BEGIN COOKIE HANDLING */
/*************************/

function toggleDealInCart(dealid, onoff) {
	var cn = "cart";	//cookie name
	var strCart = getCookie(cn);
	var regStr = ":" + dealid + ":";
	
	if (!strCart) strCart = "";	//make var a string no matter what so we can do regEx on it
	
	if (strCart.match(regStr)) {	//this deal is already in the cookie
		if (onoff != "on") {
			//take this deal out of cart if the checkbox is off
			strCart = strCart.replace(regStr, '');
			setCookie(cn, strCart);
		}
	}
	else {		//if the cookie exists, the deal is not in it
		if (onoff != "off") {
			strCart += regStr;
			setCookie(cn, strCart);
		}
	}
}

function setCookie(name,value,days)
{
	if (days)	//if we've specified how many days until cookie expires
	{
		var date = new Date();
		date.setTime(date.getTime()+(1000*60*60*24*days));
		var expires = "; expires = "+date.toGMTString();
	}
	else var expires = "";	//don't put any expiration information into cookie

	document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}

function eraseCookie(name)
{
	setCookie(name,"",-1);
}

/***********************/
/* END COOKIE HANDLING */
/***********************/
