Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
     
function Set_Cart_Cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	if ( domain == '' ) {
		domain = document.domain.split('.');
		if (domain[domain.length-1].toLowerCase() == 'au' || domain[domain.length-1].toLowerCase() == 'uk') {
			domain = domain[domain.length-3] + '.' + domain[domain.length-2] + '.' + domain[domain.length-1];
		} else {
			domain = domain[domain.length-2] + '.' + domain[domain.length-1];
		}
	}

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Get_Cart_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );

		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;

			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}

			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cart_Cookie( name, path, domain ) {
	if ( Get_Cart_Cookie( name ) ) {
	
		if ( domain == '' ) {
			domain = document.domain.split('.');
			if (domain[domain.length-1].toLowerCase() == 'au' || domain[domain.length-1].toLowerCase() == 'uk') {
				domain = domain[domain.length-3] + '.' + domain[domain.length-2] + '.' + domain[domain.length-1];
			} else {
				domain = domain[domain.length-2] + '.' + domain[domain.length-1];
			}
		}
	
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function CollapseCart() {
	var cartDiv = $("#cartDiv");
	
	var cartUrl = '/module/product.htm?editCart=1';
	if (location.host == 'www.quiltstorewebsites.com' || location.host == 'quiltstorewebsites.com' || location.host == 'www.my-quiltstorewebsites.com' || location.host == 'my-quiltstorewebsites.com' || location.host == 'www.onyxwebsites.com' || location.host == 'onyxwebsites.com') {
		cartUrl = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrl;
	}

	cartDiv.html(
		'<span style="color: #ccc; font-family: Arial; font-size: 12px;"><a href="javascript:ProceedToCheckout();" style="color: #ccc; font-family: Arial; font-size: 12px;">Check Out</a> &nbsp; | &nbsp; <a href="' + cartUrl + '" style="color: #ccc; font-family: Arial; font-size: 12px;">Edit Cart</a></span>' +
		'<div style="position:absolute; top: 8px; right: 10px;"><a href="javascript:ExpandCart();"><img border=0 width=16 height=11 src="http://siteimages.s3.amazonaws.com/btn-expand.png"></a></a></div>' +
		MakeCartForm() +
		'');
	
	var cart = Get_Cart_Cookie('cart');
	cart = 'mode##collapsed' + cart.substring(cart.indexOf(';'));
	Set_Cart_Cookie( 'cart', cart, '', '/', '', '' );
}

// Test to see if in_email is a valid email address--as far as we can tell with Javascript
function IsValidEmail(in_email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(in_email) == false) return false;
	else return true;
}

function ProceedToCheckout() {
	
	// see if we need to get their email address for digital downloads
	var needEmail = false;
	var cart = '';
	if (Get_Cart_Cookie('cart')) cart = Get_Cart_Cookie('cart');
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'product' && window.cartArray[i][8] == 'yes') {
			needEmail = true;
			break;
		}
	}
	
	// if needed, get email address for digital download
	if (needEmail) {
		var email = prompt("At least 1 item in your shopping cart will be emailed to you.  Please enter your email address:");
		if (IsValidEmail(email)) {
			Set_Cart_Cookie( 'cart', cart + ';;downloadEmail##' + email, '', '/', '', '' );
		} else {
			alert('The email address you entered was not a valid email address.');
			return;
		}
	}
	
	return;

	// do normal checkout
	if (window.paymentProcessor === undefined || window.paymentProcessor == false) window.paymentProcessor = 'paypal';
	
	if (window.paymentProcessor == 'authorize.net') {
		location = "/module/product.htm?checkout=1";
	}
	else { // paypal
		$.post("http://" + document.domain + "/module/product.htm?save_shopping_cart_contents=1&shopping_cart_contents_id=" + window.shopping_cart_contents_id, $("#cartform").serialize(), 
			function(data) {
				document.cartform.submit();
			});
	}
}

function CalculateDiscount(subtotal, i) {
	var discount = 0;
	if (window.cartArray[i][0] == 'coupon') {
		if (window.cartArray[i][1] == 'dollar_off') {
			// Calculate discount
			if (subtotal > window.cartArray[i][3]) {
				discount = window.cartArray[i][4];
			}
			discount = Math.round(discount*100)/100;
		}
		else if (window.cartArray[i][1] == 'percent_off') {
			discount = parseFloat(subtotal) * (parseFloat(window.cartArray[i][3]) / 100);
			discount = Math.round(discount*100)/100;
		}
	}
	return discount;
}

function ExpandCart() {
	var cartDiv = $("#cartDiv");
	
	var products = '';
	var subtotal = 0;
	
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'product') {
			subtotal += (window.cartArray[i][3] * window.cartArray[i][4]);
			products +=
				window.cartArray[i][2].replace(/\+/g, ' ') + '<br>' +
				'<div style="padding-top: 5px; padding-bottom: 5px;"><b>' + formatCurrency(window.cartArray[i][3]) + '</b></div>' +
				'<span style="font-size: 10px; color: #999;">- quantity: ' + window.cartArray[i][4] + '</span><br><br>' +
				'';
		}
	}
	
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'coupon') {
			var discount = CalculateDiscount(subtotal, i);
			if (discount > 0) {
				subtotal -= discount;
				products +=
					window.cartArray[i][2].replace(/\+/g, ' ') + '<br>' +
					'<div style="padding-top: 5px; padding-bottom: 5px; color: #ff9999;"><b>- ' + formatCurrency(discount) + '</b></div>' +
					'';
			}
		}
	}
	
	subtotal = Math.round(subtotal*100)/100;
	
	var cartUrl = '/module/product.htm?editCart=1';
	if (location.host == 'www.quiltstorewebsites.com' || location.host == 'quiltstorewebsites.com' || location.host == 'www.my-quiltstorewebsites.com' || location.host == 'my-quiltstorewebsites.com' || location.host == 'www.onyxwebsites.com' || location.host == 'onyxwebsites.com') {
		cartUrl = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrl;
	}
	
	cartDiv.html(
		'<a href="' + cartUrl + '" style="color: #ccc; font-family: Arial; font-size: 12px;">Shopping Cart</a>' +
		'<div style="position:absolute; top: 8px; right: 10px;"><a href="javascript:CollapseCart();"><img border=0 width=16 height=11 src="http://siteimages.s3.amazonaws.com/btn-collapse.png"></a></div>' +
		'<div style="position:absolute; width: 100%; top: 30px; right: 0px; border-top: 1px solid #ccc;">&nbsp;</div><br><br><br>' +
		'<a href="javascript:ProceedToCheckout();"><img border=0 width=160 height=24 src="http://siteimages.s3.amazonaws.com/btn-proceed-to-checkout-a.png"></a><br><br>' +
		'<a href="' + cartUrl + '"><img border=0 width=121 height=22 src="http://siteimages.s3.amazonaws.com/btn-edit-shopping-cart-a.png"></a><br><br>' +
		'<a href="' + cartUrl + '&enterCoupon=true" style="color: #ffffff; font-size: 12px;">Enter Coupon</a><br><br>' + 
		'<div style="padding: 10px; color: #fff; background: url(http://siteimages.s3.amazonaws.com/cart-bg-2a.png) repeat;">' +
		products +
		'<div style="text-align: center; border-top: 1px solid #999;">' +
		'<br>' +
		'<span style="color: #ccc; font-size: 12px;"><b>Subtotal = ' + formatCurrency(subtotal) + '</b></span><br><br>' +
		'</div>' +
		'</div><br>' +
		'<a href="javascript:ProceedToCheckout();"><img border=0 width=160 height=24 src="http://siteimages.s3.amazonaws.com/btn-proceed-to-checkout-a.png"></a><br><br>' +
		MakeCartForm() +
		'');
		
	var cart = Get_Cart_Cookie('cart');
	cart = 'mode##expanded' + cart.substring(cart.indexOf(';'));
	Set_Cart_Cookie( 'cart', cart, '', '/', '', '' );
}

function WideCart() {
	var wideCartDiv = $("#wideCartDiv");
	
	var products = '';
	var subtotal = 0;
	var itemTotal = 0;
	var integer = 0;
	var remainder = 0;
	
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'product') {
			subtotal += (window.cartArray[i][3] * window.cartArray[i][4]);
			itemTotal = parseFloat(window.cartArray[i][3]) * parseFloat(window.cartArray[i][4]);
			itemTotal = Math.round(itemTotal*100)/100;
			integer = Math.floor(window.cartArray[i][4]);
			products +=
				'	<tr>' +
				'		<td><b>' + window.cartArray[i][2].replace(/\+/g, ' ') + '</b></td>' +
				'		<td align=right nowrap><b>' + formatCurrency(window.cartArray[i][3]) + '</b></td>' +
				'		<td align=left nowrap>' +
				'			<select onchange="checkFabricMinimum(' + window.cartArray[i][1] + ')" name=integer' + window.cartArray[i][1] + ' id=integer' + window.cartArray[i][1] + '>';
			for (var j=0; j<=100; j++) {
				products +=
					'				<option value=' + j + (j == integer ? ' selected' : '') + '>' + j + '</option>';
			}
			products += '</select>';

			if (window.cartArray[i][6] == 'fraction') {
				remainder = (parseFloat(window.cartArray[i][4]) * 100) % 100;
				products +=
					'<select name=fraction' + window.cartArray[i][1] + ' id=fraction' + window.cartArray[i][1] + '>' +
					'	<option value="0"' + (remainder == 0 ? ' selected' : '') + '>0</option>' +
					'	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>1/4</option>' +
					'	<option value="0.5"' + (remainder == 50 ? ' selected' : '') + '>1/2</option>' +
					'	<option value="0.75"' + (remainder == 75 ? ' selected' : '') + '>3/4</option>' +
					'</select>';
			}
			products +=
				'		</td>' +
				'		<td align=right nowrap><b>' + formatCurrency(itemTotal) + '</b></td>' +
				'	</tr>';
		}
	}
	
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'coupon') {
			var discount = CalculateDiscount(subtotal, i);
			if (discount > 0) {
				subtotal -= discount;
				products +=
					'	<tr>' +
					'		<td><b>' + window.cartArray[i][2].replace(/\+/g, ' ') + '</b></td>' +
					'		<td>&nbsp;</td>' + 
					'		<td>&nbsp;</td>' +
					'		<td align=right nowrap><b>- ' + formatCurrency(discount) + '</b></td>' +
					'	</tr>' +
					'';
			}
		}
	}
	
	subtotal = Math.round(subtotal*100)/100;
	
	var cartUrl = '/module/product.htm?editCart=1';
	if (location.host == 'www.quiltstorewebsites.com' || location.host == 'quiltstorewebsites.com' || location.host == 'www.my-quiltstorewebsites.com' || location.host == 'my-quiltstorewebsites.com' || location.host == 'www.onyxwebsites.com' || location.host == 'onyxwebsites.com') {
		cartUrl = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrl;
	}
	
	wideCartDiv.html( 
		'<table width=100% cellpadding=5 cellspacing=0 border=0>' +
		'	<tr><td colspan=4><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
		'	<tr>' +
		'		<td style="font-size: 10px;">Description</td>' +
		'		<td style="font-size: 10px;" align=right>Price</td>' +
		'		<td style="font-size: 10px;" align=left>Quantity</td>' +
		'		<td style="font-size: 10px;" align=right>Amount</td>' +
		'	</tr>' +
		'	<tr><td colspan=4><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
		products +
		'	<tr>' +
		'		<td colspan=2>&nbsp;</td>' +
		'		<td align=left>' +
		'			<a href="javascript:UpdateWideCart()"><img width=70 height=24 border=0 src="http://siteimages.s3.amazonaws.com/btn-update-a.png" alt="Update"></a>' +
		'		</td>' +
		'		<td>&nbsp;</td>' +
		'	</tr>' +
		'	<tr><td colspan=4><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
		'	<tr>' +
		'		<td colspan=3 align=right valign=top>' +
		'			<h2>Item Total</h2>' +
		'			<span style="font-size: 10px;">(shipping will be calculated at checkout)</span>' +
		'		</td>' +
		'		<td align=right valign=top nowrap><h2>' + formatCurrency(subtotal) + '</h2></td>' +
		'	</tr>' +
		'	<tr>' +
		'		<td colspan=4 align=right>' +
		'			<br>' +
		'			<a href="javascript:ProceedToCheckout();"><img border=0 width=160 height=24 src="http://siteimages.s3.amazonaws.com/btn-proceed-to-checkout-a.png" alt="Proceed to Checkout"></a>' +
		'		</td>' +
		'	</tr>' +
		'</table>' +
		'' +
		MakeCartForm() +
		'');
		
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$ ' + num + '.' + cents);
}

function UpdateWideCart() {
	for (var i=window.cartArray.length-1; i>=0; i--) {
		if (window.cartArray[i][0] == 'product') {
			if (window.cartArray[i][6] == 'integer') {
				productCount = parseInt(document.getElementById('integer' + window.cartArray[i][1]).value);
			}
			else {
				productCount = parseInt(document.getElementById('integer' + window.cartArray[i][1]).value) + parseFloat(document.getElementById('fraction' + window.cartArray[i][1]).value);
			}
			if (productCount == 0) {
				window.cartArray.remove(i);
			}
			else window.cartArray[i][4] = productCount;
		}
	}
	
	var productCount = 0;
	for (var i=window.cartArray.length-1; i>=0; i--) {
		if (window.cartArray[i][0] == 'product') {
			productCount++;
		}
	}
	
    if (productCount == 0) {
		Delete_Cart_Cookie( 'cart', '/', '' );
    }
    else {
		Set_Cart_Cookie( 'cart', BuildCookieFromArray(), '', '/', '', '' );
	}
	WideCart();
}

function MakeCartForm() {
	var productsStr = '';
	var totalWeight = 0;
	var count = 0;
	var subtotal = 0;
	
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'product') {
			count++;
			totalWeight += (window.cartArray[i][4] * window.cartArray[i][5]);
			
			if (parseInt(window.cartArray[i][4]) == window.cartArray[i][4]) {
				subtotal += (parseFloat(window.cartArray[i][3]) * window.cartArray[i][4]);
				productsStr += '<input type=hidden name=amount_' + count + ' id=amount_' + count + ' value="' + window.cartArray[i][3] + '">';
				productsStr += '<input type=hidden name=item_name_' + count + ' id=item_name_' + count + ' value="' + window.cartArray[i][2].replace('"', "").replace("'", "") + (window.cartArray[i].length >= 8 && window.cartArray[i][7] != '' ? " [" + window.cartArray[i][7] + "]" : '') + '">';
				productsStr += '<input type=hidden name=item_number_' + count + ' id=item_number_' + count + ' value="' + window.cartArray[i][1] + '">';
				productsStr += '<input type=hidden name=weight_' + count + ' id=weight_' + count + ' value="' + window.cartArray[i][5] + '">';
				productsStr += '<input type=hidden name=quantity_' + count + ' id=quantity_' + count + ' value="' + window.cartArray[i][4] + '">';
			}
			else {
				var amount = (parseFloat(window.cartArray[i][3]) * parseFloat(window.cartArray[i][4]));
				subtotal += parseFloat(amount);
				amount = Math.round(amount*100)/100;
				var weight = (parseFloat(window.cartArray[i][5]) * parseFloat(window.cartArray[i][4]));
				weight = Math.round(weight*100)/100;

				productsStr += '<input type=hidden name=amount_' + count + ' id=amount_' + count + ' value="' + amount + '">';
				productsStr += '<input type=hidden name=item_name_' + count + ' id=item_name_' + count + ' value="' + window.cartArray[i][2].replace('"', "").replace("'", "") + ' (' + window.cartArray[i][4] + ' yards)' + (window.cartArray[i].length >= 8 && window.cartArray[i][7] != '' ? " [" + window.cartArray[i][7] + "]" : '') + '">';
				productsStr += '<input type=hidden name=item_number_' + count + ' id=item_number_' + count + ' value="' + window.cartArray[i][1] + '">';
				productsStr += '<input type=hidden name=weight_' + count + ' id=weight_' + count + ' value="' + weight + '">';
				productsStr += '<input type=hidden name=quantity_' + count + ' id=quantity_' + count + ' value="1">';
			}
		}
	}
	
	var discountStr = '';
	for (var i=0; i<window.cartArray.length; i++) {
		if (window.cartArray[i][0] == 'coupon') {
			var discount = CalculateDiscount(subtotal, i);
			if (discount > 0) {
				discount = Math.round(discount*100)/100;
				discountStr = '<input type=hidden name=discount_amount_cart id=discount_amount_cart value="' + discount + '">';
			}
		}
	}	
	subtotal = Math.round(subtotal*100)/100;
	
	if (productsStr == '') return ''; // Return nothing if we have no products
	
	totalWeight = Math.ceil(totalWeight);
	if (totalWeight < 1) totalWeight = 1;
	
	var paymentAction = 'sale';
	if (window.cartArray[1].length >= 4 && window.cartArray[1][3] == 'authorization') paymentAction = 'authorization';
	
	window.shopping_cart_contents_id = escape(document.domain).replace(/@/g,'').replace(/\./g, '') + Math.floor(Math.random() * 100000000) + Math.floor(Math.random() * 100000000);
	
	var str = 
		'<form id=cartform name=cartform method=post action="https://www.paypal.com/cgi-bin/webscr">' +
		'<input type="hidden" name="cmd" value="_cart">' +
		'<input type="hidden" name="notify_url" value="http://' + document.domain + '/module/product.htm?ipn=1&shopping_cart_contents_id=' + window.shopping_cart_contents_id + '">' +
		'<input type=hidden name=upload id=upload value="1">' +
		'<input type=hidden name=weight_unit id=weight_unit value="lbs">' +
		discountStr +
        '<input type="hidden" name="return" value="' + location.href + (location.href.indexOf('?') > 0 ? '&' : '?') + 'emptycart=1">' +
		'<input type="hidden" name="shopping_url" value="' + location.href + '">' +
		'<input type=hidden name=business id=business value="' + window.cartArray[1][1] + '">' +
		'<input type=hidden name=paymentaction id=paymentaction value="' + paymentAction + '">' +
		productsStr +
		'</form>' +
		'';
	
	return str;
}

function CreateCartArray(cart) {
	tuples = cart.split(";;");
	window.cartArray = new Array();
	for (i=0; i<tuples.length; i++) {
		parts = tuples[i].split("##");
		window.cartArray[i] = parts;
	}
}

function ShowCart(forceExpand) {
	var cartDiv = $("#cartDiv");
	if (window.cartMode === undefined || window.cartMode == false) window.cartMode = 'normal';
	
	if (window.cartMode == 'hidden') {
		cartDiv.hide();
	}
	else { 
		var cart = '';
		if (Get_Cart_Cookie('cart')) cart = Get_Cart_Cookie('cart');
		
		if (window.cartMode == 'wide') {
			CreateCartArray(cart);
			cartDiv.hide();
			WideCart();
		}
		else {
			if (cart.length > 0) {
				CreateCartArray(cart);
				if (window.cartArray[0][1] == 'collapsed' && forceExpand != true) {
					CollapseCart();
				}
				else {
					ExpandCart();
				}
				cartDiv.slideDown();
				return;
			}
			else {
				cartDiv.hide();
			}
		}
	}
}

function BuildCookieFromArray() {
	var newCart = '';
	for (var i=0; i<window.cartArray.length; i++) {
		if (i > 0) newCart += ';;';
		newCart += window.cartArray[i].join("##");
	}
	return newCart;
}

/*Code developed by Posin Begin*/

//Function used to stroe value in cookie
function setDesignWallCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	if ( domain == '' ) {
		domain = document.domain.split('.');
		if (domain[domain.length-1].toLowerCase() == 'au' || domain[domain.length-1].toLowerCase() == 'uk') {
			domain = domain[domain.length-3] + '.' + domain[domain.length-2] + '.' + domain[domain.length-1];
		} else {
			domain = domain[domain.length-2] + '.' + domain[domain.length-1];
		}
	}

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );	
}
//Function used to get product id from cookie
function getDesignWallCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );

		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;

			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}

			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

//Function used to open a design wall popup
function o(href,height,width) 
{ 
	var w = window.open(href,"popup","height="+height+",width="+width+",resizable,scrollbars=yes"); w.focus();
}

//Function used to store  product id in cookie
function AddProductToDesignWall(store_url,productId)
{
	var designWall = '';
	if (getDesignWallCookie('designWallCookie')) designWall = getDesignWallCookie('designWallCookie');
	var designWallArray= new Array();
	designWallArray= designWall.split('|');
		var itemFlag = 0;
		for (var i=0; i<designWallArray.length; i++) {
			if(designWallArray[i]!='')
			{
				if (designWallArray[i] == productId) {
					itemFlag = 1;
					break;
				}
			}
		}
		
		if (itemFlag == 0) 
		{
			if(designWall=="")
			{
				setDesignWallCookie('designWallCookie',productId, '', '/', '', '');
			}
			else {
				setDesignWallCookie('designWallCookie',designWall+'|'+productId, '', '/', '', '');
			}
		}
		o(store_url,630,800)
		
}

/*Code developed by Posin End*/

function AddProductToCart(in_businessEmail, in_paymentAction, productId, productTitle, productPrice, productWeight, productCountType, productSku, requiresDownloadEmailAddress) {
	window.businessEmail = in_businessEmail;
	
	if (!requiresDownloadEmailAddress || requiresDownloadEmailAddress == 'undefined') requiresDownloadEmailAddress = "no";

	var cart = '';
	if (Get_Cart_Cookie('cart')) cart = Get_Cart_Cookie('cart');
	
	productCount = parseInt(document.getElementById('integer' + productId).value) + parseFloat(document.getElementById('fraction' + productId).value);
		
	var productOption = document.getElementById('option' + productId);
	if (productOption != null && productOption != 'undefined') {
		var optionTitle = productOption.value.substring(0, productOption.value.lastIndexOf('=='));
		var optionPrice = productOption.value.substring(productOption.value.lastIndexOf('==')+2);
		
		productTitle += ' - ' + optionTitle;
		productPrice = optionPrice;
		productId = productId + '-' + productOption.selectedIndex;
	}
	
	if (cart.length > 0) {

		var item = 'new';
		for (var i=0; i<window.cartArray.length; i++) {
			if (window.cartArray[i][0] == 'product') {
				if (productId == window.cartArray[i][1]) {
					item = i;
					break;
				}
			}
		}
		
		if (item == 'new') {
			Set_Cart_Cookie( 'cart', cart + ';;product##' + productId + '##' + productTitle + '##' + productPrice + '##' + productCount + '##' + productWeight + '##' + productCountType + '##' + productSku + '##' + requiresDownloadEmailAddress, '', '/', '', '' );
		}
		else {
			window.cartArray[item][4] = parseFloat(window.cartArray[item][4]) + parseFloat(productCount);
			Set_Cart_Cookie( 'cart', BuildCookieFromArray(), '', '/', '', '' );
		}
	}
	else {
		Set_Cart_Cookie( 'cart', 'mode##expanded' + ';;businessEmail##' + in_businessEmail + '##paymentAction##' + in_paymentAction + ';;product##' + productId + '##' + productTitle + '##' + productPrice + '##' + productCount + '##' + productWeight + '##' + productCountType + '##' + productSku + '##' + requiresDownloadEmailAddress, '', '/', '', '' );
	}

	ShowCart(true);
}


function AddCouponToCart(in_businessEmail, in_paymentAction, couponType, couponTitle, param1, param2, param3) {
	
	window.businessEmail = in_businessEmail;

	var cart = '';
	if (Get_Cart_Cookie('cart')) cart = Get_Cart_Cookie('cart');
	
	var params = '';
	if (param1 != '' && param1 != undefined) params += '##' + param1;
	if (param2 != '' && param1 != undefined) params += '##' + param2;
	if (param3 != '' && param1 != undefined) params += '##' + param3;
	
		
	if (cart.length > 0) {

		var item = 'new';
		for (var i=0; i<window.cartArray.length; i++) {
			if (window.cartArray[i][0] == 'coupon') {
				item = i;
				break;
			}
		}
		
		if (item == 'new') {
			Set_Cart_Cookie( 'cart', cart + ';;coupon##' + couponType + '##' + couponTitle + params, '', '/', '', '' );
		}
	}
	else {
		Set_Cart_Cookie( 'cart', 'mode##expanded' + ';;businessEmail##' + in_businessEmail + '##paymentAction##' + in_paymentAction + ';;coupon##' + couponType + '##' + couponTitle + params, '', '/', '', '' );
	}
	
	ShowCart(true);
}


// Set_Cart_Cookie( 'cart', 'mode##expanded;;businessEmail##test@test.com;;coupon##dollar_off##$5 off $10 minimum##10##5;;product##223##Daisy Pattern##8.49##1##0.5##integer;;product##224##Butterfly Kisses Baby Girl Quilt Pattern##8.49##1##0.5##integer##sku;;subtotal##8.49', '', '/', '', '' );
// Coupon Types:
//		dolar_off (param0 = coupon, param1 = dollar_off, param2 = title, param3 = minimum order size, param4 = dollar discount) - EXAMPLE: coupon##dollar_off##$5 off $10 minimum##10##5 wouldn't discount at $8.95 order.  It would discount a $13 order to $10. It would discount a $16 order to $11.
// Set_Cart_Cookie( 'XYZ', 'coupon##percent##20##ALL')
// Set_Cart_Cookie( 'XYZ2', 'coupon##dollarsOff##2.50##4;5;')

// AddCouponToCart('someone@yahoo.com', 'dollar_off', '$5 off $10 minimum', 10, 5);

// Delete_Cart_Cookie( 'cart', '/', '' );

