| <SCRIPT>
var thisCookie = document.cookie;
var name = price = quant = subtotal =
"";
var total = 0;
if (!getCookie("cart"))
Item = "";
else {
Item = getCookie("cart").split(";");
Price = getCookie("price").split(";");
}
/*************** Cookie Functions
***************/
function getCookie(name)
{
var index = thisCookie.indexOf(name
+ "=");
if (index == -1) return null;
index = thisCookie.indexOf("=",
index) + 1;
var endstr = thisCookie.indexOf(";",
index);
if (endstr == -1) endstr = thisCookie.length;
return unescape(thisCookie.substring(index,
endstr));
}
function setCookie(name,
quantity) {
if (quantity != null && quantity !=
"") document.cookie =
name + "=" + quantity;
thisCookie = document.cookie;
}
function deleteCookie(name,
path, domain) {
if (getCookie(name))
{
document.cookie
= name + "=" +
((path)
? "; path=" + path : "") +
((domain)
? "; domain=" + domain : "") +
";
expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
/*************** End of Cookie Functions
***************/
function getTotal()
{
for (i = 0; i < Item.length;
i++) {
var quantity = getCookie(Item[i]);
total += Price[i]
* quantity;
}
return total;
}
function updateCookie(i)
{
var quantity =
document.cart[Item[i]].value;
if (isNaN(quantity))
{
alert("Please
enter a Number");
document.cart[Item[i]].value
= getCookie(Item[i]);
return;
}
if (quantity == 0) {
deleteCookie(Item[i]);
Item[i]
= "";
Price[i]
= "";
cartStr
= Item.join(";").replace(/;;/g,
";");
priceStr
= Price.join(";").replace(/;;/g,
";");
if
(i == 0) {
cartStr = cartStr.substring(1);
priceStr = priceStr.substring(1);
}
if (cartStr.lastIndexOf(";")
== cartStr.length -
1) {
cartStr = cartStr.substring(0,
cartStr.length -
1);
priceStr = priceStr.substring(0,
priceStr.length -
1);
}
if (!cartStr.length
) {
deleteCookie("cart");
deleteCookie("price");
}
else
{
setCookie("cart",
cartStr);
setCookie("price",
priceStr);
}
}
else setCookie(Item[i],
quantity);
location.reload();
}
</SCRIPT>
<SCRIPT>
if (Item.length)
{
document.write('<FORM
NAME="cart">')
document.write('<TABLE><TR>');
document.write('<TH
BGCOLOR="#336699" NOWRAP ALIGN="left">
<FONT COLOR="#FFFFFF">Item</FONT>
</TH>');
document.write('<TH
BGCOLOR="#336699">
<FONT COLOR="#FFFFFF">No.</FONT>
</TH>');
document.write('<TH
BGCOLOR="#336699">
<FONT COLOR="#FFFFFF">Unit Price</FONT>
</TH>');
document.write('<TH
BGCOLOR="#336699">
<FONT COLOR="#FFFFFF">Subtotal</FONT>
</TH>');
document.write('</TR>');
var start = '<TR
ALIGN="center"><TD ALIGN="left">';
var column = '</TD><TD>';
var columnR = '</TD><TD
ALIGN="right">';
var end = '</TD></TR>';
for (i = 0; i < Item.length;
i++) {
if (getCookie(Item[i]))
{
name = Item[i];
price = Price[i];
quant = getCookie(name);
subtotal = "$" + quant * price + ".00";
document.write(start
+ name + column)
document.write('<INPUT
TYPE="text" NAME="' + name +
'" VALUE="' + quant + '" SIZE="3"
onChange="updateCookie('\'
+ i + '\')">');
document.write(column
+ price + columnR + subtotal + end);
}
}
document.write('<TR><TD
COLSPAN="3" ALIGN="right">');
document.write('Total:'
+ columnR + '$' + getTotal()
+ '.00');
document.write('</TD></TR>');
document.write('</TABLE>');
document.write('</FORM>');
}
else document.write('<H3>The
Shopping Cart is Empty</H3>');
</SCRIPT>
|