// NebuCart - The JavaScript Shopping Cart
// by Nebulus Designs
//
// Copyright 1999-2001 all rights reserved.

// None of this script may be redistributed or sold
// without the authors express consent.
// Violations of copyright will be prosecuted.

// If you would like to use NebuCart,
// email us at nebucart@nebulus.org
// or visit http://nebucart.nebulus.org

// ********************************************
// NebuCart Cart View		                  *
// ********************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE!    *
// ********************************************

var totalCost     = 0;
var currentCost   = 0;
var tax           = 0;
var SnH           = 0;
var totalQty      = 0;
var currSpan      = 4;
var writeOption   = false;
var yourCart      = Cart;
var cartLocation  = cartPage;

if(String(location).indexOf(cartLocation) == -1){
	var viewingCart = false;
} else {
	var viewingCart = true;
}
if(yourCart.length > 0){
	for(j=0; j < yourCart.length; j++){
		if(yourCart[j].opt){
			writeOption = true;
			currSpan = 5;
		}
	}
	if(viewingCart){
		document.write('\n<form name="NC_form">\n');
	}
	document.write('<table border=' + cartBorder + ' cellpadding=' + cartCellPad + ' cellspacing=' + cartCellSpace + '>\n');
	document.write('<tr bgcolor=' + cartHeader + '>\n');
	document.write('<td><font face=' + myFont + ' size=-1><b>&nbsp;Item Number&nbsp;</b></td>');
	document.write('<td><font face=' + myFont + ' size=-1><b>&nbsp;Description&nbsp;</b></td>');
	if(writeOption){
		document.write('<td color=' + cartHeader + '><font face=' + myFont + ' size=-1><b>&nbsp;Options&nbsp;</b></td>');
	}
	document.write('<td><font face=' + myFont + ' size=-1><b>&nbsp;Price&nbsp;</b></td>');
	document.write('<td><font face=' + myFont + ' size=-1><b>&nbsp;Quantity&nbsp;</b></td>');
	document.write('<td align=center><font face=' + myFont + ' size=-1><b>Cost</b></td>\n');
	if(viewingCart){
		document.write('<td><font face=' + myFont + ' size=-1>&nbsp;</td>\n');
	}
	document.write('</tr>\n');
	for(z=0; z < yourCart.length; z++){
		totalQty += Number(yourCart[z].qty);
		currentCost = Number(yourCart[z].qty) * Number(yourCart[z].price);
		totalCost = totalCost + currentCost;
		currentCost = formatDecimal(currentCost);
		if(z % 2 == 0){
			document.write('<tr bgcolor=' + cartRow1 + '>\n');
		} else {
			document.write('<tr bgcolor=' + cartRow2 + '>\n');
		}
		document.write('<td><font face=' + myFont + ' size=-1>' + yourCart[z].prodID + '</font></td>');
		document.write('<td><font face=' + myFont + ' size=-1>' + yourCart[z].desc + '</font></td>');
		if(writeOption){
			document.write('<td><font face=' + myFont + ' size=-1>');
			if(yourCart[z].opt == ''){
				document.write('&nbsp\;');
			} else {
				document.write(yourCart[z].opt);
			}
			document.write('</font></td>');
		}
		document.write('<td align=right><font face=' + myFont + ' size=-1>' + currency + formatDecimal(yourCart[z].price) + '</font></td>');
		if(viewingCart){
			document.write('<td align=right><font face=' + myFont + ' size=-1><input type=text value="' + yourCart[z].qty + '" name="' + yourCart[z].prodID + '_' + z + '" size=2></font></td>');
		} else {
			document.write('<td align=right><font face=' + myFont + ' size=-1>' + yourCart[z].qty + '</font></td>');
		}
		document.write('<td align=right><font face=' + myFont + ' size=-1>' + currency + currentCost + '</font></td>\n');
		if(viewingCart){
			document.write('<td align=center>');
			document.write('<font size=-1>\n');
			document.write('<input type="button" value="Update" onClick="UpdateItem(');
			document.write('\'' + z + '\')">');
			document.write('&nbsp\;&nbsp\;');
			document.write('<input type="button" value="Delete" onClick="DeleteItem(');
			document.write('\'' + z + '\')">');
			document.write('</font>\n');
			document.write('</td>');
		}
		document.write('</tr>\n');
	}
	if(viewingCart){
		document.write('<tr bgcolor=' + cartTotalRow + '>\n');
		document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1><b>Total:</b></font></td><td align=right valign=top><font face=' + myFont + ' size=-1>' + currency + formatDecimal(totalCost) + '</font></td>\n');
		document.write('<td><font face=' + myFont + ' size=-1>&nbsp;</font></td>\n');
		document.write('</tr>\n');
	} else {
		if(String(chargeTax) == 'true' || shipAmt != ''){
			document.write('<tr bgcolor=' + cartSubRow + '>\n');
			document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1><b>Subtotal:</b></font></td><td align=right valign=top><font face=' + myFont + ' size=-1>' + currency + formatDecimal(totalCost) + '</font></td>\n');
			document.write('</tr>\n');
		}
		if(String(chargeTax) == 'true'){
			if(stateTax != ''){
				tax = formatDecimal(stateTax * totalCost);
			} else {
				tax = 0;
			}
			if(tax > 0){
				document.write('<tr bgcolor=' + cartTaxRow + '>\n');
				document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1><b>' + formatDecimal(stateTax * 100,1) + '% Local Tax:</b></font></td><td align=right><font face=' + myFont + ' size=-1>' + currency + formatDecimal(tax) + '</font></td>\n');
				document.write('</tr>\n');
			}
		}
		if(shipAmt != ''){
			if(shipPercent && !useShipOptions){
				SnH = shipAmt * totalCost;
			} else if(shipPerItem && !useShipOptions){
				SnH = shipAmt * totalQty;
			} else if(useShipOptions){
					if(shipPerItem){
							SnH = shipAmt * totalQty;
					} else {
							SnH = shipAmt;
					}
			} else if(useShipRules){
				SnH = getShipRule(totalCost,totalQty);
			} else {
				SnH = 0;
			}
			document.write('<tr bgcolor=' + cartShipRow + '>\n<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1><b>S &amp; H (Shipping and Handling Estimate*)');
			if(shipDesc.length > 0){
				document.write(' (' + shipDesc + ')');
			} else if(shipPercent && !useShipOpt && !shipPerItem){
				document.write(' (' + (100 * shipAmt) + '%)');
			}
			document.write(':</b></font></td><td align=right><font face=' + myFont + ' size=-1>' + currency + formatDecimal(SnH) + '</font></td>\n</tr>\n');
		}
		if(tax > 0){totalCost = Number(totalCost) + Number(tax);}
		if(SnH > 0){totalCost = Number(totalCost) + Number(SnH);}
		document.write('<tr bgcolor=' + cartTotalRow + '>\n<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1><b>Total:</b></font></td><td align=right><font face=' + myFont + ' size=-1>' + currency + formatDecimal(totalCost) + '</font></td>\n</tr>\n');
	}
	document.write('</table>\n<p>\n');
	if(viewingCart){
		document.write('<br>\n');
		document.write('<font size=-1>\n');
		document.write('<input type="button" value="Checkout" onClick="document.location=\'' + COstep1 + '\'">');
		document.write('&nbsp\;');
		document.write('<input type="button" value="Continue Shopping" onClick="history.back()">\n');
		document.write('&nbsp\;');
		document.write('<input type="button" value="Delete Cart" onClick="DeleteCart()">\n');
		document.write('</font>\n');
		document.write('</form>');
	}
} else {
	document.write('<font face=' + myFont + ' size=3><b><br>');
	document.write('Your cart is currently empty.');
	document.write('</b></font><p>');
	document.write('<form name="NC_form">');
	document.write('<font size=-1>');
	document.write('<input type="button" value="Back" onClick="history.back()">');
	document.write('</font>\n');
	document.write('</form>');
}