
 var tableheadcolor = "#FFFFFF"; //Table Header and Footer
 var tablebodycolor = "#FFFFFF"; //Body Color    
 var tablefontcolor = "#ff0000"; //Font Color
 
function next ()  {
     document.returnValue = false;
}

// buyItem - adds an item to the shopping list
function buyItem(newItem, newPrice, newQuantity) {
		if (newQuantity <= 0) {
			//rc = alert('The quantity entered is incorrect');
		} else {
		if (confirm('Add '+newItem+' To Your Shopping List?')) { //
     var CookieName = "OnAdThisWeek";
     var cookieFound = false;
     var start = 0;
     var end = 0;
     var cookieString = document.cookie;
     var i = 0;
     while (i <= cookieString.length) {
       start = i;
       end = start + CookieName.length;
       if (cookieString.substring(start,end) == CookieName) {
         cookieFound = true;
        break;
       }
       i++;
     }
     if (cookieFound) {
       start = end + 1;
       end = document.cookie.indexOf(";",start);
       if (end < start)
         end = document.cookie.length;
       document.cookie.substring(start,end);
      }
	document.cookie="OnAdThisWeek="+document.cookie.substring(start, end)+"["+newItem+"|"+newPrice+"|"+newQuantity+"]; expires=Thursday, 31-Dec-2020 08:00:00 GMT";
	window.location.href=document.location.event.target; 
			}
			}
			}
	
//Show shoppinglist.html contents	
function showbasket() {
	var aisle;
	 var CookieName = "OnAdThisWeek";
     var cookieFound = false;
     var start = 0;
     var end = 0;
     var cookieString = document.cookie;
     var i = 0;
     while (i <= cookieString.length) {
       start = i;
       end = start + CookieName.length;
       if (cookieString.substring(start,end) == CookieName) {
         cookieFound = true;
        break;
       }
       i++;
     }
     if (cookieFound) {
       start = end + 1;
       end = document.cookie.indexOf(";",start);
       if (end < start)
         end = document.cookie.length;
       document.cookie.substring(start,end);
     }
		fulllist = document.cookie.substring(start, end);
		totprice = 0;
		document.writeln('<FORM NAME="updateform">');
		document.writeln('<TABLE BORDER=0 WIDTH=750 HEIGHT=453 CELLSPACING=1 CELLPADDING=3 BGCOLOR="' + tablebodycolor + '">'); //' + tablebodycolor + '
		document.writeln('<TR><TD WIDTH=335 VALIGN="TOP">');

		document.writeln('<TABLE  WIDTH=500 CELLSPACING=1 CELLPADDING=1 BGCOLOR="#FFFFFF" >'); //BGCOLOR="' + tablebodycolor + '"
		document.writeln('<TR bgcolor=' + tableheadcolor + '><TD COLSPAN=3><center><b><font color=' + tablefontcolor + '><font size=3>Shopping List</FONT></FONT></B></TD></TR>');
		document.writeln('<TR bgcolor=' + tableheadcolor + '><TD WIDTH=16></TD><TD></TD>');                 //<TD><B>Special</B></TD> <B>Location</B>
		document.writeln('<TD WIDTH=20><B><FONT COLOR=' + tablefontcolor + '>Delete</FONT></B></TD></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;  
				itemlist=itemlist+1;
				document.write('<TR><TD WIDTH=20 VALIGN="BOTTOM"><select><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option></select></TD>');
				document.write('<TD BACKGROUND="Images/lines.gif" width=550 VALIGN="middle">'+theitem+'</TD>');  //<IMG SRC="Images/check.gif" BORDER=0 height=15 align="top">
				
				document.write('<TD  VALIGN="middle"><FONT SIZE=1><a href="javascript:removeItem('+itemlist+')"<CENTER><IMG SRC="Images/check.gif" BORDER=1 height=15 valign="middle"></A></FONT></center></TD></TR>'); //<TD ALIGN=CENTER>'+thequantity+'</TD>
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		
		document.writeln('</TABLE>');
		document.write('<center><TABLE><TR><TD COLSPAN=2><p><br><p><FORM>&nbsp;&nbsp;&nbsp;			<input type="button" value="Print This Page" onclick="printPage()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Continue Shopping" onclick="history.back()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Clear List" onClick="removeall();"></FORM></TD></TR>');
		document.write('</TABLE></CENTER>');
		document.writeln('</TD>');
		
	}
	
	

	
//Remove item from shoppinglist.html	
function removeItem(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("OnAdThisWeek");
		document.cookie="OnAdThisWeek="+newItemList+"; expires=Thursday, 31-Dec-2020 08:00:00 GMT";
		self.location = "shoppinglist.html";
		}
		
//Remove item from shoppinglist.html	
function removeall(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("OnAdThisWeek");
		document.cookie="OnAdThisWeek="+newItemList+"; expires=Thursday, 31-Dec-2020 08:00:00 GMT";

		self.location = "shoppinglist.html";
		}

