
//************************
//** GLOBAL SITE FUNCTIONS
//************************
function addbookmark(){
bookmarkurl = "http://www.vitadigest.com";
bookmarktitle = "VitaDigest.com the Ultimate Online Supplement Store.";
if (document.all)window.external.AddFavorite(bookmarkurl,bookmarktitle);
}

function popIt(width, height, scrollbars){ 
	if(!width) width = "640";
	if(!height) height = "480";
	if(!scrollbars) scrollbars = 1;
	var windowString = 'width=' + width + ',height=' + height + ',resizable=1,status=0,toolbar=no,scrollbars=' + scrollbars + ',scrolling=auto';
	var popItWindow = window.open('',"popIt", windowString);
	return false;
}
function tellFriendPop(width, height, scrollbars){ 
	if(!width) width = "640";
	if(!height) height = "480";
	if(!scrollbars) scrollbars = 0;
	var windowString = 'width=' + width + ',height=' + height + ',resizable=0,status=0,toolbar=no,scrollbars=' + scrollbars + ',scrolling=auto';
	var popItWindow = window.open('',"popIt", windowString);
	return false;
}
function displayDate() {
	var d=new Date();
	var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var monthname=new Array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
	var apm;
	var hours = d.getHours();
	var minutes = d.getMinutes();
	if (hours >= 12){apm = " P.M.";} else {apm = " A.M.";}
	if (hours > 12) hours -= 12;
	if (hours == 0) hours = 12;
	if (minutes <10) minutes = "0" + minutes; 
	document.write(weekday[d.getDay()] + ", "); 
	document.write(monthname[d.getMonth()] + " "); 
	document.write(d.getDate() + ", "); 
	document.write(d.getFullYear()); 
	document.write("&nbsp; &nbsp;"); 
	document.write(hours + ":" + minutes + apm); 
}
var windowHandle = new Object();
function createWindow(width, height,img) {
	if(!width) width = 500;
	if(!height) height = 500;
	windowHandle = window.open("loading.html", "popUpWindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,scrolling=yes,resizable=yes,width=" + width + ",height=" + height);
	self.setTimeout("writePopUpContents(" + img + ")", 500);
	return false;
}

function writePopUpContents(img) {
	var pageContent = "";
	pageContent = '<html><head><link rel="stylesheet" href="http://lib.store.yahoo.net/lib/vitadigest/compiledStyle.css"></head>';
	pageContent += '<body onload="drawImage(' + img + ')">';
	pageContent += document.getElementById("popUpContent").innerHTML;
	pageContent += '</body></html>';
	windowHandle.document.open();
	windowHandle.document.write(pageContent);
	windowHandle.document.close();
	windowHandle.focus();
	return false;
}
var tabArray = new Array("descriptionTab", "productReviewsTab");
function activateTab(tabId) {
	//*** TURN OFF TABS
	var item = new Object();
	for(item in tabArray) {
		document.getElementById(tabArray[item] + "-tab").className = "tabOff";
		document.getElementById(tabArray[item] + "-link").className = "tabLinkOff";
		document.getElementById(tabArray[item] + "-content").style.display = "none";
	}
	//*** TURN ON TAB
	document.getElementById(tabId + "-tab").className = "tabOn";
	document.getElementById(tabId + "-link").className = "tabLinkOn";
	document.getElementById(tabId + "-content").style.display = "block";
	return false;
}



function displayRecentlyViewedItems(productList) {
	var item = new Object();
	var innerHtml = '<table width="100%" cellpadding="8" cellspacing="0"><tr>';
	var product = new Object();
	for(item in productList) {
		if(productList[item].price){innerHtml += '<form method=post action="http://order.store.yahoo.com/cgi-bin/wg-order?vitadigest+' + productList[item].productId + '"><input name=vwcatalog type=hidden value=vitadigest><input name=vwitem type=hidden value=' + productList[item].productId + '>';};	
		innerHtml += '<td align="center">';
		innerHtml += '<a href="' + productList[item].url	+ '"><font size=2>';
		innerHtml += '<img src="' + productList[item].imageThumbnailUrl + '" border="0">';
		innerHtml += '<br>';
		innerHtml += productList[item].name;
		innerHtml += '</a>';
		if(productList[item].price && productList[item].salePrice){innerHtml += '<br><font style="font-size:11px">Regular Price:<b> ' + productList[item].price + '</b></font>';}else if(productList[item].price){innerHtml += '<br><font color="#cc0000"><b>Our Price: ' + productList[item].price + '</b></font>';};	
		if(productList[item].salePrice){innerHtml += '<br><font color="#cc0000"><b>Our Price: ' + productList[item].salePrice + '</b></font>';};	
		if(productList[item].price){innerHtml += '<br><input type="image" src="http://lib.store.yahoo.net/lib/vitadigest/buyNow3.gif" border="0" vspace=5>';};	
		innerHtml += '</font></td><td>&nbsp;</td>';
		if(productList[item].price){innerHtml += '</form>';};	
		
	}
	innerHtml += '</tr></table>';
	document.getElementById("recentlyViewedProducts").innerHTML = innerHtml;
}
//***************************************************
//***** CODE COPYRIGHT VITADIGEST.COM 2004 *****
//***** - USE WITHOUT PERMISSION IS PROHIBITED ******
//***************************************************
function displayShoppingCart(shoppingCart) {
	
	var itemsInCart = shoppingCart.products.length;
	
	//****************************************
	//***** FREE SHIPPING QUALIFICATION ******
	//****************************************
	var freeShippingCutoff = 100;
	var freeShipMessage = "";
	if(shoppingCart.subtotal >= freeShippingCutoff) freeShipMessage = "<font class=scFreeShipText>You Qualify for FREE Shipping! &nbsp;<a href=shipinfo.html onclick=popIt(250,250); class=scFreeShipText target=popIt> > details</a></font><br>";
	else freeShipMessage = "<font class=scFreeShipText>Add " + formatCurrency(freeShippingCutoff - shoppingCart.subtotal) + " to qualify for Free Shipping!</font> &nbsp;<a href=shipinfo.html onclick=popIt(800,800); class=scFreeShipText target=popIt> > details</a><br>";

		var innerHTML = '';
		if(itemsInCart == 1) {innerHTML += '<b>Items in Cart = ' + itemsInCart + '</b><br><div class="scHrDiv"><hr class="scHr"></div>';}else{innerHTML += '<b>Items in Cart = ' + itemsInCart + '</b><br><div class="scHrDiv"><hr class="scHr"></div>'}
		
		var item = new Object();
		for(item in shoppingCart.products) {
			innerHTML += '<a href="http://' + getCurrentPagePath() + "/" + shoppingCart.products[item].productId + '.html" class="scProductLink">';
			innerHTML += shoppingCart.products[item].name;
			innerHTML += '</a>';
			innerHTML +=  '<br><font class="scProductName">' + shoppingCart.products[item].qty + 'x </font>&nbsp; <font class="scPrice">' + formatCurrency(shoppingCart.products[item].price) + '</font><div class="scHrDiv"><hr class="scHr"></div>';
		}
		innerHTML += '<div style="margin-top:2px;" class="scSubtotal">SubTotal = ' + formatCurrency(shoppingCart.subtotal) + '</div>';
		innerHTML += '<div style="margin-top:6px;margin-bottom:8px;" class="scSubtotal">';
		innerHTML += freeShipMessage;
		innerHTML += '</div>';
		innerHTML += '<a href="http://order.store.yahoo.com/cgi-bin/wg-order?vitadigest" class="scEditLink">> Edit Shopping Cart</a>';
		innerHTML += '<br>';
		innerHTML += '<div style="padding-top:12px;"><a href="https://order.store.yahoo.com/cgi-bin/shipping-form?catalog=vitadigest"><img src="http://www.vitadigest.com/lib/vitadigest/fcCheckout.gif" border="0"></a></div>';

	//*********************************
	//***** DISPLAY FLOATING CART *****
	//*********************************	
	document.getElementById("shoppingCartDisplay").innerHTML = innerHTML;
}

//***************************************************
//***** CODE COPYRIGHT VITADIGEST.COM 2004 *****
//***** - USE WITHOUT PERMISSION IS PROHIBITED ******
//***************************************************
function getCookie(cookieName) {
	var allCookies = document.cookie;
	var cookieStart = allCookies.indexOf(cookieName)
	if(cookieStart == -1) return "";
	cookieStart = cookieStart + cookieName.length + 1;
	var cookieEnd = allCookies.indexOf(";", cookieStart);
	if(cookieEnd == -1) cookieEnd = allCookies.length;
	var cookieValue = allCookies.substring(cookieStart, cookieEnd);
	return cookieValue;
}

function getShoppingCart() {
	var storeCode = getStoreCode();
	var cartCookieInfoName = "pdsc_" + storeCode + "_info";
	var cartCookieName = "pdsc_" + storeCode + "_";
	var shoppingCart = new Object();
	shoppingCart.products = new Array();
	var pd_shoppingCartInfo = getCookie(cartCookieInfoName);
	var cookieValue = "";
	for(var i=0;i<pd_shoppingCartInfo;i++) {
		cookieValue += getCookie(cartCookieName + i);
	}
	cookieValue = unescape(cookieValue);
	
	if(cookieValue.length > 10) shoppingCart = decodeShoppingCart(cookieValue);
	shoppingCart.subtotal = 0;
	if(shoppingCart.products) {
		for(var i=0;i<shoppingCart.products.length;i++) {
			shoppingCart.subtotal+= (shoppingCart.products[i].price * shoppingCart.products[i].qty); 
		}
	}
	return shoppingCart;
}

function getCurrentPagePath() {
	var url = String(location);
	url = url.replace("http://", "");
	var slashIndex = url.lastIndexOf("/");
	if(slashIndex == -1) slashIndex = url.length;
	var pagePath = url.substring(0, slashIndex);
	return pagePath;
}

function decodeShoppingCart(encodedCart) {

	var shoppingCart = new Object();
	shoppingCart.isTrimmed = false;
	shoppingCart.products = new Array();
	
	//**************************
	//*** TEST FOR CART TRIM ***
	//**************************
	if(encodedCart.charAt(0) == '+') {
		shoppingCart.isTrimmed = true;
		encodedCart = encodedCart.substring(1, encodedCart.length);
	}
	
	//*************************
	//**** SPLIT CART ROWS ****
	//*************************	
	var tempArray = encodedCart.split("~");
	
	var tempArray2 = new Array();
	var i = 0;
	var item = new Object();
	for(item in tempArray) {
	
		//************************************************
		//*** SPLIT APART ATTRIBUTES & BUILD CART ITEM ***
		//************************************************
		tempArray2 = tempArray[item].split("^");
		
		shoppingCart.products[i] = new Object();
		shoppingCart.products[i].productId = tempArray2[0];
		shoppingCart.products[i].name = decodeSpecialCharacters(tempArray2[1]);
		shoppingCart.products[i].options = decodeSpecialCharacters(tempArray2[2]);
		shoppingCart.products[i].price = tempArray2[3];
		shoppingCart.products[i].qty = tempArray2[4];
		shoppingCart.products[i].inStock = tempArray2[5];
		i++;		
	}
	//**************
	//*** RETURN ***
	//**************
	return shoppingCart;
}

function decodeSpecialCharacters(value) {
	
	//**************
	//*** DECODE ***
	//**************
	value = String(value);
	value = value.replace(/\\"/g, '"');
	value = value.replace(/\\r/g, '\r');
	value = value.replace(/\\n/g, '\n');
	
	//***************
	//*** RETURN ***
	//**************
	return value;
}
function getStoreCode() {
	return "vitadigest";
}
//*************************************************
//***** COPYRIGHT 2005, VITADIGEST.COM ******
//***** - UNAUTHORIZED USE IS PROHIBITED **********
//*************************************************
function pdGetCookie(cookieName) {
	var allCookies = document.cookie;
	var cookieStart = allCookies.indexOf(cookieName)
	if(cookieStart == -1) return "";
	cookieStart = cookieStart + cookieName.length + 1;
	var cookieEnd = allCookies.indexOf(";", cookieStart);
	if(cookieEnd == -1) cookieEnd = allCookies.length;
	var cookieValue = unescape(allCookies.substring(cookieStart, cookieEnd));
	return cookieValue;
}

function pdSetCookie(cookieName, cookieValue, cookieDomain, cookiePath, expirationDate) {
	if(isBlank(cookieDomain)) cookieDomain = getCurrentDomainName();
	if(isBlank(cookiePath)) cookiePath = "/";
	var cookieString = cookieName + "=" + escape(cookieValue) + ";domain=" + cookieDomain + ";path=" + cookiePath;
	if(!isBlank(expirationDate)) {
		cookieString += ";expires=" + expirationDate.toGMTString();
	}
	document.cookie = cookieString;
	return true;
}

function getCurrentDomainName() {
	var url = String(location);
	var domainName = extractDomain(url);
	return domainName;
}

function extractDomain(url) {
	var url = url.replace("http://", "");
	var slashIndex = url.indexOf("/");
	if(slashIndex == -1) slashIndex = url.length;
	var url = url.substring(0, slashIndex);
	var urlSectionArray = url.split('.');
	var urlSectionArrayLength = urlSectionArray.length;
	var domainName = "";
	for(var i=urlSectionArrayLength - 2;i<urlSectionArrayLength; i++) {
		domainName += "." + urlSectionArray[i];
	}
	return domainName;
}

function isBlank(item) {
	item = String(item).toLowerCase();
	if(item == "undefined" || item == "" || item == "null") return true;
	else return false;
}
function isBlank(item) {
	item = String(item).toLowerCase();
	if(item == "undefined" || item == "" || item == "null") return true;
	else return false;
}

function getCurrentDomainName() {
	var url = String(location);
	var domainName = extractDomain(url);	
	return domainName;
}

function extractDomain(url) {
	var url = url.replace("http://", "");
	var slashIndex = url.indexOf("/");
	if(slashIndex == -1) slashIndex = url.length;
	var url = url.substring(0, slashIndex);
	var urlSectionArray = url.split('.');
	var urlSectionArrayLength = urlSectionArray.length;
	var domainName = "";
	for(var i=urlSectionArrayLength - 2;i<urlSectionArrayLength; i++) {
		domainName += "." + urlSectionArray[i];
	}
	return domainName;
}

function getCookie(cookieName) {
	var allCookies = document.cookie;
	var cookieStart = allCookies.indexOf(cookieName)
	if(cookieStart == -1) return "";
	cookieStart = cookieStart + cookieName.length + 1;
	var cookieEnd = allCookies.indexOf(";", cookieStart);
	if(cookieEnd == -1) cookieEnd = allCookies.length;
	var cookieValue = allCookies.substring(cookieStart, cookieEnd);
	return cookieValue;
}

function getProductList() {
	var storeCode = getStoreCode();
	var cartCookieInfoName = "pdrv_" + storeCode + "_info";
	var cartCookieName = "pdrv_" + storeCode + "_";
	var productList = new Array();
	var pd_productListInfo = getCookie(cartCookieInfoName);
	var cookieValue = "";
	for(var i=0;i<pd_productListInfo;i++) {
		cookieValue += getCookie(cartCookieName + i);
	}
	cookieValue = unescape(cookieValue);
	try {
		if(cookieValue.length > 10)	eval(cookieValue);
	} catch(e) {
		//alert(cookieValue);
	}
	return productList;
}

function addProductToProductList(product, productList, maxItems) {
	var item = new Object();
	for(item in productList) {
		if(productList[item].productId == product.productId) return productList;
	}
	if(isBlank(maxItems) || maxItems == 0) maxItems = 5;
	productList.unshift(product);
	productList = productList.splice(0,maxItems);
	return productList;
}

function recordProductList(productList, storeCode, cookieDomain, expirationDate) {
	var productListString = serialize("productList", productList);
	var chunkSize = 3000;
	var cookieArray = new Array();
	var j = 0;
	var i = 0;
	for(i=0;i<productListString.length;i+=chunkSize) {
		cookieArray[j] = productListString.substring(i, chunkSize + i);
		j++;
	}
	var cookieString = "pdrv_" + storeCode + "_info=" + j +";domain=" + cookieDomain + ";path=/";
	if(!isBlank(expirationDate)) {
		cookieString += ";expires=" + expirationDate.toGMTString();
	}
	document.cookie = cookieString;
	
	for(i=0;i<j;i++) {
		cookieString = "pdrv_" + storeCode + "_" + i + "=" + escape(cookieArray[i]) + ";domain=" + cookieDomain + ";path=/";
		if(!isBlank(expirationDate)) cookieString +=";expires=" + expirationDate.toGMTString();
		document.cookie = cookieString;
	}
	return true;
}
//***************************************************
//***** CODE COPYRIGHT VITADIGEST.COM 2004 *****
//***** - USE WITHOUT PERMISSION IS PROHIBITED ******
//***************************************************
function serialize(objectName, myObject) {
	
	//***************************************
	//********* BEGIN SERIALIZATION *********
	//***************************************
	var objectString = "";
	var objectType = typeof(myObject);
	
	//***********************************************
	//******* CREATE STRING ACCORDING TO TYPE *******
	//***********************************************	
	if(objectType == 'undefined') return objectString;
	else if(objectType == 'string') {
		objectString += 'var ' + serializeString(objectName, myObject);
	} else if(objectType == 'number') {
		objectString += 'var ' + serializeNumber(objectName, myObject);
	} else if(objectType == 'boolean') {
		objectString += 'var ' + serializeBoolean(objectName, myObject);
	} else if(objectType == 'object' && myObject.constructor == Array) {
		objectString += 'var ' + serializeArray(objectName, myObject);
	} else if(objectType == 'object') {
		objectString += 'var ' + serializeObject(objectName, myObject);
	}
	
	//**************************************
	//****** RETURN SERIALIZED OBJECT ******
	//**************************************
	return objectString + "";
}

function serializeString(name, value) {
	var tempString = "";
	value = value.replace(/"/g, '\\"');
	value = value.replace(/\r/g, '\\r');
	value = value.replace(/\n/g, '\\n');

	if(name - 0 == name) tempString = '[' + name + '] = "' + value + '";\r\n';
	else tempString = name + ' = "' + value + '";\r\n';
	return tempString;
}

function serializeNumber(name, value) {

	var tempString = "";
	if(name - 0 == name) tempString = '[' + name + '] = ' + value + ';\r\n';
	else tempString = name + ' = ' + value + ';\r\n';
	return tempString;
}

function serializeBoolean(name, value) {
	var tempString = "";
	if(name - 0 == name) tempString = '[' + name + '] = ' + value + ';\r\n';
	else tempString = name + ' = ' + value + ';\r\n';
	return tempString;
}

function serializeDate(name, value) {
	var tempString = "";
	if(name - 0 == name) tempString = '[' + name + '] = new Date("' + value + '");\r\n';
	else tempString = name + ' = new Date("' + value + '");\r\n';
	return tempString;
}

function serializeObject(name, myObject) {
	var objectString = name + ' = new Object();\r\n';
	
	//*********************************************************
	//***** ITERATE OBJECT AND GENERATE EQUIVALENT STRING *****
	//*********************************************************
	var item = new Object();	//*** ITERATOR
	for(item in myObject) {
	
		//***********************************************
		//******* CREATE STRING ACCORDING TO TYPE *******
		//***********************************************
		objectType = typeof(myObject[item]);
		
		//**************************************************************************************
		//******* TRAP OBJECTS THAT HAVE BEEN SET TO NULL AND REDEFINE AS EMPTY STRINGS ********
		//**************************************************************************************
		try {
			var temp = myObject[item].constructor;
		} catch(e) {
			myObject[item] = new String();
			objectType = typeof(myObject[item]);
		}

		if(objectType == 'undefined') return objectString;
		else if(objectType == 'string' || myObject[item].constructor == String) {
			objectString += name + "." + serializeString(item, myObject[item]);
		} else if(objectType == 'number') {
			objectString += name + "." + serializeNumber(item, myObject[item]);
		} else if(objectType == 'boolean') {
			objectString += name + "." + serializeBoolean(item, myObject[item]);
		} else if(objectType == 'object' && myObject[item].constructor == Array) {
			if(item - 0 == item) objectString += serializeArray(name + "[" + item + "]", myObject[item]);
			else objectString += serializeArray(name + "." + item, myObject[item]);
		} else if(objectType == 'object' && myObject[item].constructor == Date) {
			if(item - 0 == item) objectString += serializeDate(name + "[" + item + "]", myObject[item]);
			else objectString += serializeDate(name + "." + item, myObject[item]);
		} else if(objectType == 'object') {
			if(item - 0 == item) objectString += serializeObject(name + "[" + item + "]", myObject[item]);
			else objectString += serializeObject(name + "." + item, myObject[item]);
		}
	}

	return objectString;
}


function serializeArray(name, myObject) {
	
	var objectString = name + ' = new Array();\r\n';
	
	//*********************************************************
	//***** ITERATE OBJECT AND GENERATE EQUIVALENT STRING *****
	//*********************************************************
	var item = new Object();	//*** ITERATOR
	for(item in myObject) {
	
		//***********************************************
		//******* CREATE STRING ACCORDING TO TYPE *******
		//***********************************************
		objectType = typeof(myObject[item]);
		
		//**************************************************************************************
		//******* TRAP OBJECTS THAT HAVE BEEN SET TO NULL AND REDEFINE AS EMPTY STRINGS ********
		//**************************************************************************************
		try {
			var temp = myObject[item].constructor;
		} catch(e) {
			myObject[item] = new String();
			objectType = typeof(myObject[item]);
		}

		if(objectType == 'undefined') return objectString;
		else if(objectType == 'string' || myObject[item].constructor == String) {
			objectString += name + serializeString(item, myObject[item]);
		} else if(objectType == 'number') {
			objectString += name + serializeNumber(item, myObject[item]);
		} else if(objectType == 'boolean') {
			objectString += name + serializeBoolean(item, myObject[item]);
		} else if(objectType == 'object' && myObject[item].constructor == Array) {
			if(item - 0 == item) objectString += serializeArray(name + "[" + item + "]", myObject[item]);
			else objectString += serializeArray(name + "." + item, myObject[item]);
		} else if(objectType == 'object' && myObject[item].constructor == Date) {
			if(item - 0 == item) objectString += serializeDate(name + "[" + item + "]", myObject[item]);
			else objectString += serializeDate(name + "." + item, myObject[item]);
		} else if(objectType == 'object') {
			if(item - 0 == item) objectString += serializeObject(name + "[" + item + "]", myObject[item]);
			else objectString += serializeObject(name + "." + item, myObject[item]);
		}
	}

	return objectString;
}

//***************************************************
//***** CODE COPYRIGHT VITADIGEST.COM 2004 *****
//***** - USE WITHOUT PERMISSION IS PROHIBITED ******
//***************************************************
function getCookie(cookieName) {
	var allCookies = document.cookie;
	var cookieStart = allCookies.indexOf(cookieName)
	if(cookieStart == -1) return "";
	cookieStart = cookieStart + cookieName.length + 1;
	var cookieEnd = allCookies.indexOf(";", cookieStart);
	if(cookieEnd == -1) cookieEnd = allCookies.length;
	var cookieValue = allCookies.substring(cookieStart, cookieEnd);
	return cookieValue;
}

function getShoppingCart() {
	var storeCode = getStoreCode();
	var cartCookieInfoName = "pdsc_" + storeCode + "_info";
	var cartCookieName = "pdsc_" + storeCode + "_";
	var shoppingCart = new Object();
	shoppingCart.products = new Array();
	var pd_shoppingCartInfo = getCookie(cartCookieInfoName);
	var cookieValue = "";
	for(var i=0;i<pd_shoppingCartInfo;i++) {
		cookieValue += getCookie(cartCookieName + i);
	}
	cookieValue = unescape(cookieValue);
	
	if(cookieValue.length > 10) shoppingCart = decodeShoppingCart(cookieValue);
	shoppingCart.subtotal = 0;
	if(shoppingCart.products) {
		for(var i=0;i<shoppingCart.products.length;i++) {
			shoppingCart.subtotal+= (shoppingCart.products[i].price * shoppingCart.products[i].qty); 
		}
	}
	return shoppingCart;
}

function getCurrentPagePath() {
	var url = String(location);
	url = url.replace("http://", "");
	var slashIndex = url.lastIndexOf("/");
	if(slashIndex == -1) slashIndex = url.length;
	var pagePath = url.substring(0, slashIndex);
	return pagePath;
}

function decodeShoppingCart(encodedCart) {

	var shoppingCart = new Object();
	shoppingCart.isTrimmed = false;
	shoppingCart.products = new Array();
	
	//**************************
	//*** TEST FOR CART TRIM ***
	//**************************
	if(encodedCart.charAt(0) == '+') {
		shoppingCart.isTrimmed = true;
		encodedCart = encodedCart.substring(1, encodedCart.length);
	}
	
	//*************************
	//**** SPLIT CART ROWS ****
	//*************************	
	var tempArray = encodedCart.split("~");
	
	var tempArray2 = new Array();
	var i = 0;
	var item = new Object();
	for(item in tempArray) {
	
		//************************************************
		//*** SPLIT APART ATTRIBUTES & BUILD CART ITEM ***
		//************************************************
		tempArray2 = tempArray[item].split("^");
		
		shoppingCart.products[i] = new Object();
		shoppingCart.products[i].productId = tempArray2[0];
		shoppingCart.products[i].name = decodeSpecialCharacters(tempArray2[1]);
		shoppingCart.products[i].options = decodeSpecialCharacters(tempArray2[2]);
		shoppingCart.products[i].price = tempArray2[3];
		shoppingCart.products[i].qty = tempArray2[4];
		shoppingCart.products[i].inStock = tempArray2[5];
		i++;		
	}
	//**************
	//*** RETURN ***
	//**************
	return shoppingCart;
}

function decodeSpecialCharacters(value) {
	
	//**************
	//*** DECODE ***
	//**************
	value = String(value);
	value = value.replace(/\\"/g, '"');
	value = value.replace(/\\r/g, '\r');
	value = value.replace(/\\n/g, '\n');
	
	//***************
	//*** RETURN ***
	//**************
	return value;
}
//***************************************************
//***** CODE COPYRIGHT VITADIGEST.COM 2004 *****
//***** - USE WITHOUT PERMISSION IS PROHIBITED ******
//***************************************************

//*************************************************************************
//******* FORMAT A NUMBER AS CURRENCY WITH OPTIONAL COMMA FORMATTING ******
//*************************************************************************
function formatCurrency(item) {
	item = String(Math.round(item * 100) /100);
	var frontString = "";
	var backString = "";
	var decimalIndex = item.indexOf(".");		

	if(decimalIndex == -1) {
		item += ".00";
		decimalIndex = item.indexOf(".");
	}

	//*****************************************
	//**** FORMAT WHOLE AND DECIMAL PARTS *****		
	//*****************************************
	frontString = item.substring(0, decimalIndex);
	backString = item.substring(decimalIndex, item.length);
	if(backString.length < 3) backString += "0";
	
	//***********************************************************
	//***** COMMA-FORMAT WHOLE PORTION OF OUR CURRENCY VALUE ****
	//***********************************************************
	if(true) {
		var tempString = new String();
		var frontLength = frontString.length;
		var i = 0;
		var j = 0;
		for(i=frontLength; i>=0;i--) {
			tempString += String(frontString.charAt(i));
			if(j%3 == 0 && j<frontLength && j != 0 && frontString.charAt(i-1) != '-') tempString += ",";
			j++;
		}
	
		frontString = "";
		var tempLength = tempString.length;
		for(i=tempLength; i>=0;i--) {
			frontString += String(tempString.charAt(i));				
		}
		
	}
	
	//***********************************************************
	//***** RECONSTRUCT AND RETURN FORMATTED CURRENCY VALUE *****
	//***********************************************************		
	item = "$" + frontString + backString;
	return (item);
}



