<HTML>
<HEAD>
<TITLE>Shopping Bag Manager</TITLE>
<STYLE TYPE="text/css">
<!--
TD {font-weight: bold; margin-left: 20; margin-right: 20; padding: 10}
//-->
</STYLE>
</HEAD>
<BODY onLoad="freshStart(); makeProducts();" LINK=BLUE ALINK=BLUE VLINK=BLUE>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="inventory.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
// Define control variables
var gimmeControl = false;
var browseControl = false;
var curCLoc = -1;
var curPLoc = -1;
var infoStr = '';
var shoppingBag;
// Define a shopping bag constructor
// then create a new Bag
function Bag() {
this.taxRate = .06;
this.taxTotal = 0;
this.shipRate = .02;
this.shipTotal = 0;
this.subTotal = 0;
this.bagTotal = 0;
this.things = new Array();
}
shoppingBag = new Bag();
// This function displays links to
// all the available categories
function showStore() {
gimmeControl = false;
var header = '<HTML><TITLE>Category</TITLE><BODY BGCOLOR=FFFFFF>';
var intro = '<H2>Shopping Bag Product Categories</H2><B>';
var footer = '</DL></BLOCKQUOTE></BODY></HTML>';
var storeStr = '<BLOCKQUOTE><DL>';
for (var i = 0; i < categorySet.length; i++) {
storeStr += '<DT><A HREF="javascript: parent.frames[1].reCall(' + i + ', 0);">' +
categorySet[i].name + '</A>' +
'<DD>' + categorySet[i].description + '<BR><BR>';
}
infoStr = header + intro + storeStr + footer;
parent.frames[0].location.replace("javascript: parent.frames[1].infoStr");
}
// Define a function to manage
// opening the product search
function portal() {
gimmeControl = false;
parent.frames[0].location.href = "search/index.html";
}
// Display a product depending on the current values of the
// category number (curCLoc) and product number (curPLoc)
function display(cOffset, pOffset) {
if(!browseControl) {
alert("Start shopping by selecting a product category from Show All Categories or " +
"searching products from Product Search.");
return;
}
gimmeControl = true;
if (curPLoc + pOffset < 0 || curPLoc + pOffset == categorySet[curCLoc].prodLine.length) {
if (curPLoc + pOffset < 0) {
if (curCLoc - 1 < 0) { curCLoc = categorySet.length - 1; }
else { curCLoc--; }
curPLoc = categorySet[curCLoc].prodLine.length - 1;
}
else if (curPLoc + pOffset == categorySet[curCLoc].prodLine.length) {
if (curCLoc + 1 == categorySet.length) { curCLoc = 0; }
else { curCLoc++; }
curPLoc = 0;
}
}
else {
if (curCLoc + cOffset < 0 || curCLoc + cOffset == categorySet.length) {
curCLoc = (curCLoc + cOffset < 0 ? categorySet.length - 1 : 0);
}
else { curCLoc += cOffset; }
if (cOffset == -1 || cOffset == 1) { curPLoc = 0; }
else if (pOffset == 0) {
curPLoc = (curPLoc >= categorySet[curCLoc].prodLine.length ? 0 : curPLoc)
}
else { curPLoc = curPLoc + pOffset; }
}
infoStr = '<HTML><HEAD><TITLE>Product Name</TITLE></HEAD>' +
'<BODY><TABLE CELLPADDING=3><TR><TD VALIGN=TOP COLSPAN=2>' +
'<FONT FACE=Tahoma><H2>Shopping Bag: <I>' + categorySet[curCLoc].name + '</I></H2>' +
'<TR>' +
'<TD VALIGN=TOP><IMG SRC="' + categorySet[curCLoc].prodLine[curPLoc].icon.src +
'"></TD><TD VALIGN=TOP><FONT FACE=Tahoma>' +
'<B>Name: </B>' + categorySet[curCLoc].prodLine[curPLoc].name + '<BR>' +
'<B>Description: </B>' + categorySet[curCLoc].prodLine[curPLoc].description + '<BR>' +
'<B>Price: </B> $' + numberFormat(categorySet[curCLoc].prodLine[curPLoc].price) + '/' +
categorySet[curCLoc].prodLine[curPLoc].unit + '<BR>' +
'<B>PLU: </B>' + categorySet[curCLoc].prodLine[curPLoc].plu + '</TD></TR></TABLE></BODY></HTML>';
parent.frames[0].location.href = "javascript: parent.frames[1].infoStr";
}
// Used for navigation by setting values
// curCLoc and curPLoc independently instead
// of setting them according to their current
// value as done in display()
function reCall(cReset, pReset) {
browseControl = true;
curCLoc = cReset;
curPLoc = pReset;
display(0, 0);
}
// This function adds a product to a user's
// bag only if it is not there already
function gimmeOne() {
if (!gimmeControl) {
alert("Nothing on this screen to give you.");
return;
}
for (var i = 0; i < shoppingBag.things.length; i++) {
if (categorySet[curCLoc].prodLine[curPLoc].plu == shoppingBag.things[i].plu) {
alert("That's already in your bag. You can change the quantity by choosing View/Change Bag.");
return;
}
}
shoppingBag.things[shoppingBag.things.length] = categorySet[curCLoc].prodLine[curPLoc];
shoppingBag.things[shoppingBag.things.length - 1].itemQty = 1;
shoppingBag.things[shoppingBag.things.length - 1].category = categorySet[curCLoc].name;
alert("OK. You put the " + shoppingBag.things[shoppingBag.things.length - 1].name + " in your bag.");
}
// Define a function to iterate through all the
// products in the user's bag and display them
// in a form for user changes
function showBag() {
if (shoppingBag.things.length == 0) {
alert("Your bag is currently empty. Put some stuff in.");
return;
}
gimmeControl = false;
var header = '<HTML><HEAD><TITLE>Your Shopping Bag</TITLE>' +
'</HEAD><BODY BGCOLOR=FFFFFF onLoad="parent.frames[1].runningTab(document.forms[0]);">';
var intro = '<H2>Your Shopping Bag!!!</H2><FORM onReset="setTimeout(\'parent.frames[1].runningTab(document.forms[0])\', 25);">';
var tableTop = '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=5>' +
'<TR><TH><B>Index' +
'<TH><B>Product<TH><B>Category' +
'<TH><B>PLU<TH><B>Unit Price' +
'<TH><B>Quantity<TH><B>Product Total' +
'<TH><B>Remove' +
'</TR>';
var itemStr = '';
for (var i = 0; i < shoppingBag.things.length; i++) {
itemStr += '<TR>' +
'<TD ALIGN=CENTER>' + (i + 1) + '</TD>' +
'<TD>' + shoppingBag.things[i].name + '</TD>' +
'<TD>' + shoppingBag.things[i].category + '</TD>' +
'<TD>' + shoppingBag.things[i].plu + '</TD>' +
'<TD ALIGN=RIGHT>$' + parent.frames[1].numberFormat(shoppingBag.things[i].price) + '</TD>' +
'<TD ALIGN=CENTER>' + parent.frames[1].genSelect(shoppingBag.things[i].price, shoppingBag.things[i].itemQty, i) + '</TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=TEXT SIZE=10 VALUE="' + parent.frames[1].numberFormat(shoppingBag.things[i].price * shoppingBag.things[i].itemQty) + '" onFocus="this.blur();"></TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=CHECKBOX></TD>' +
'</TR>';
}
var tableBottom = '<TR>' +
'<TD ALIGN=RIGHT COLSPAN=6>SubTotal:</TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=TEXT SIZE=10 NAME="subtotal" onFocus="this.blur();"></TD></TR>' +
'<TR>' +
'<TD ALIGN=RIGHT COLSPAN=6> + 6% Tax:</TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=TEXT SIZE=10 NAME="tax" onFocus="this.blur();"></TD></TR>' +
'<TR>' +
'<TD ALIGN=RIGHT COLSPAN=6> + 2% Shipping:</TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=TEXT SIZE=10 NAME="ship" onFocus="this.blur();"></TD></TR>' +
'<TR>' +
'<TD ALIGN=RIGHT COLSPAN=3><INPUT TYPE=BUTTON VALUE="Check Out" onClick="parent.frames[1].checkOut(this.form);"></TD>' +
'<TD ALIGN=RIGHT><INPUT TYPE=RESET VALUE="Reset Qtys"></TD>' +
'<TD ALIGN=RIGHT><INPUT TYPE=BUTTON VALUE="Change Bag" onClick="parent.frames[1].changeBag(this.form, true);"></TD>' +
'<TD ALIGN=RIGHT>Total:</TD>' +
'<TD ALIGN=CENTER><INPUT TYPE=TEXT NAME="total" SIZE=10 onFocus="this.blur();"></TD></TR>';
var footer = '</TABLE></FORM></BODY></HTML>';
infoStr = header + intro + tableTop + itemStr + tableBottom + footer;
parent.frames[0].location.replace('javascript: parent.frames[1].infoStr');
}
// Generate dynamic SELECT lists according
// to a price aggregate, and set the OPTION
// that matches the qty as SELECTED
function genSelect(priceAgr, qty, idx) {
var selStr = '<SELECT onChange="this.form.elements[' + (idx * 3 + 1) +
'].value = this.options[this.selectedIndex].value; parent.frames[1].runningTab(this.form)