var items = readCookie();
function checkoutCartContents(){

var items = readCookie();

var htmlString = "";

htmlString += "<table id=\"Buy\">\n";
numItems = items['itemName'].length;

htmlString += " <thead>\n";
htmlString += " <tr id=\"Head\">\n";
htmlString += "  <td>Product</td>\n";
htmlString += "  <td>Dimensions</td>\n";
htmlString += "  <td>Quantity</td>\n";
htmlString += "  <td>Price</td>\n";
htmlString += "  <td>Del</td>\n";
htmlString += " </tr>\n";
htmlString += " </thead>\n";
htmlString += " <tbody>\n";

if (numItems > 0) {
htmlString += " <input type=\"hidden\" name=\"numItems\" value=\"" + numItems + "\">\n";
 for (i = 0; i < items['itemId'].length; i++) {
  htmlString += " <tr id=\"itemKey_" + items['itemKey'][i] + "\">\n";
  htmlString += "  <th id=\"Item\">" + items['itemName'][i] + " # " + items['itemId'][i] + " ($" + items['itemPrice'][i] + ")\n";
  htmlString += "  <input type=\"hidden\" name=\"itemKey" + i + "\" value=\"" + items['itemKey'][i] + "\">\n";
  htmlString += "  <input type=\"hidden\" name=\"itemId" + i + "\" value=\"" + items['itemId'][i] + "\">\n";
  htmlString += "  <input type=\"hidden\" name=\"itemName" + i + "\" value=\"" + items['itemName'][i] + "\">\n";
  htmlString += "  <input type=\"hidden\" name=\"oldQuantity" + i + "\" value=\"" + items['itemQuantity'][i] + "\"</th>\n";
  if (items['itemOptions'][i].length > 0) {
   htmlString += "  <td id=\"Options\" align=\"center\">" + items['itemOptions'][i] + "</td>\n";
   htmlString += "  <input type=\"hidden\" name=\"options" + i + "\" value=\"" + items['itemOptions'][i] + "\">\n";
  } else {
   htmlString += "  <td id=\"Options\">" + "Standard</td>\n";
   htmlString += "  <input type=\"hidden\" name=\"options" + i + "\" value=\"\">\n";
  }
  htmlString += "  <td id=\"Quantity\"><input type=\"text\" name=\"quantity" + i + "\" size=\"2\" value=\"" + items['itemQuantity'][i] + "\" onChange=\"javascript:updateTotal('buy', " + numItems + ", items);\" tabindex=\"1\"></td>\n";
  htmlString += "  <td id=\"Price\">$ <input type=\"text\" name=\"price" + i + "\" size=\"7\" value=\"" + toPrice(items['itemOptions'][i] * items['itemQuantity'][i] * items['itemPrice'][i]) + "\" readonly></td>\n";
  htmlString += "  <td id=\"Delete\" align=\"center\">" + "<a href=\"javascript:deleteItem('" + items['itemKey'][i] + "', items);\">x</a></td>\n";
  htmlString += " </tr>\n";
 }

 htmlString += " <tr>\n";
 htmlString += "  <th class=\"TotalLabel\" colspan=\"3\">Total:</td>\n";
 htmlString += "  <td colspan=\"2\">$ <input type=\"text\" name=\"total\" size=\"12\" readonly></td>\n";
 htmlString += " </tr>\n";
 htmlString += " </tbody>\n";
 htmlString += " <tfoot>\n";
 htmlString += " <tr>\n";
 htmlString += "  <td id=\"Bottom\" colspan=\"5\">" + "<a href=\"javascript:deleteAll();\">Delete all Items</a> &middot; <a href=\"javascript:history.back();\">Continue shopping</a></td>\n";

} else {
 htmlString += " <tr>\n";
 htmlString += "  <td id=\"NotAdded\" colspan=\"4\">You have not yet added any items to your shopping cart.</td>\n";
 htmlString += " <tr>\n";
 htmlString += "  <td id=\"Bottom\" colspan=\"4\">" + "<a href=\"javascript:deleteAll();\">Delete all Items</a> &middot; <a href=\"javascript:history.back();\">Continue shopping</a></td>\n";
 htmlString += "  <td>&nbsp;</td>\n";
}

htmlString += " </tr>\n";
htmlString += " </tfoot>\n";
htmlString += "</table>\n";

return htmlString;
}

document.write(checkoutCartContents());
// document.write(htmlString);

if (numItems > 0) {
	updateTotal('buy', numItems, items);
}
