// MINI-CART MANAGEMENT FUNCTIONALITY ==============================================================
	var totalInCart = 0;
function purgeAll(){
		deleteCookie({name:'r2b', path:'/'});	
	}
	
	//deleteCookie({name:'r2b', path:'/'});	
		
	// Reads the cookie and changes the mini-cart's contents to reflect what's in it -----
	function updateMiniCart(){
		var cookieValue = readCookie('r2b');
		if(cookieValue == '' || cookieValue == null){
			findObj("cartTotal").innerHTML = formatCurrency(0);
			findObj("miniCart").innerHTML  = 'Your cart is empty.';
			return false;
		} 
		cookieValue 	= cookieValue + "";
		var cartText 	= '<table id="miniCartTable" cellpadding="0" cellspacing="0" border="0">';
		var price		= 0;
		if(cookieValue.indexOf('|||') == -1)
			cookieValue = new Array(cookieValue);
		else
			cookieValue = cookieValue.split('|||');
		
		var selProduct 	= null;
		for(var i=0; i<cookieValue.length; i++){
			selProduct = findProductById(cookieValue[i]);
			if(selProduct){
				cartText += '<tr><td class="mc1"><a href="javascript:void(0)" onClick="removeFromCart(' + selProduct[0] + ')"><img src="interface/icn_remove.gif" class="remIcon" align="absmiddle" border="0" width="9" height="11" alt="Remove this item from my cart" title="Remove this item from my cart"></a></td>' + 
							'<td class="mc2">' + selProduct[2] + '</td>' + 
							'<td class="mc3">' + formatCurrency(selProduct[6]) + '</td></tr>';
				price 	 += parseFloat(selProduct[6]);
			}
		}
		findObj("cartTotal").innerHTML = formatCurrency(price);
		findObj("miniCart").innerHTML  = cartText + "</table>";
	} // EO: updateMiniCart --------------------------------------------------------------
	
	// Adds a product (by ID) to the user's cart -----------------------------------------
	function addToCart(productId, overrideCheck){
		if(productId == "" || productId == null) return false;
		if(cookieValueExists('r2b', productId) && overrideCheck != true) return false;
		if(totalInCart >= 25) {
			alert("You have reached the maximum of 25 titles in your cart. If you would like to add more, please remove some titles from your cart first.");
			return false;
		}
		
		var btnObj = findObj("btnUpgrade" + productId);
		rotateTitle(productId); 
		var newCookieValue = appendCookie({name:'r2b', value:productId, expiration:1});
		btnObj.src = 'interface/btn_upgraded.gif';
		updateMiniCart();
		totalInCart++;
	} // EO: addToCart -------------------------------------------------------------------
	
	// Removes the specified product from the cookie & updates the mini-cart -------------
	function removeFromCart(productId){
		var cookieString = readCookie('r2b');
		cookieString = cookieString.replace(('|||' + productId), '');
		cookieString = cookieString.replace((productId + '|||'), '');
		cookieString = cookieString.replace(productId, '');
		deleteCookie({name:'r2b', path:'/'});
		setCookie({name:'r2b', value:cookieString, expiration:1, path:'/'});
		updateMiniCart();
		revertTitle(productId);
		totalInCart--;
	} // EO: removeFromCart --------------------------------------------------------------
	
	// Constucts the link to DataPak's checkout URL --------------------------------------
	function checkoutLink(){
		var selectedIds = readCookie('r2b');
		if(selectedIds == null) return false;
		var opString = '';
		if(selectedIds.indexOf('|||') == -1){
			opString = '&product_id=' + selectedIds;
		}else{
			selectedIds = selectedIds.split('|||');
			for(var i=0; i<selectedIds.length; i++){
				opString += '&product_id=' + selectedIds[i];
			}
		}
		opString = "https://secure.red2blu.com/process?action=add_to_cart_ext" + opString;
		document.location = opString;
	} // EO: checkoutLink ----------------------------------------------------------------
	
	function populateCart(){
		try {
			var cookieValue = readCookie('r2b');
			if(cookieValue == '' || cookieValue == null) return false;
			if(cookieValue.indexOf('|||') == -1)	cookieValue = new Array(cookieValue);
			else									cookieValue = cookieValue.split('|||');
			for(var i=0; i<cookieValue.length; i++){
				if(cookieValue[i] == "") continue;
				rotateTitle(cookieValue[i]);
				findObj("btnUpgrade" + cookieValue[i]).src = 'interface/btn_upgraded.gif';
				totalInCart++;
			}
			updateMiniCart();
		} catch(e) {
			console.log(e);
		}
	}
	
	function emptyCart(){
		var cookieValue = readCookie('r2b');
		if(cookieValue == '' || cookieValue == null) return false;
		if(cookieValue.indexOf('|||') == -1)	cookieValue = new Array(cookieValue);
		else									cookieValue = cookieValue.split('|||');
		for(var i=0; i<cookieValue.length; i++)	revertTitle(cookieValue[i]);
		deleteCookie({name:'r2b', path:'/'});
		updateMiniCart();
		totalInCart = 0;
	}
	
	
// =================================================================================================