/*
**
**    missy_piggy_stuff.js - Script support for missy_piggy_stuff.htm
**                           in the Cuddly Critters website.
**
** 02/2/07 - jf - Created.
**
*/


SHIPPING = 4.00
HANDLING = 3.00

SHIPPING_A = (SHIPPING + HANDLING)    /* Shipping/handling for orders $60 and less (LIMIT_A)                */
SHIPPING_B = (SHIPPING_A + SHIPPING)  /* Shipping/handling for orders from $60.01 up to $120 (LIMIT_B)      */
SHIPPING_C = "CALL"                   /* Shipping/handling for orders over $120.01                          */

LIMIT_A = 60.00
LIMIT_B = 120.00

INV_SZ = 30
DESC_SZ = 60
SIZE_SZ = 20
COLOR_SZ = 20
QTY_SZ = 4
SUBT_SZ = 10

MAX_COLORS = 8
MAX_SIZES = 6

ELE_CNT = 7
MAX_ITEMS = 7
MAX_ENTRIES = 100  /* Actually, 99 real entries since the invoice number is the first entry */

var itemDesc = new Array(DESC_SZ * MAX_ENTRIES)
var itemSize = new Array(SIZE_SZ * MAX_ENTRIES)
var itemColor = new Array(COLOR_SZ * MAX_ENTRIES)
var itemQty = new Array(QTY_SZ * MAX_ENTRIES)
var itemSubt = new Array(SUBT_SZ * MAX_ENTRIES)

var cookieHeader = new String("ccCartCookie=")
var cookieRaw = new String("")
var cookieStart = new Number(0)
var cookieInvEnd = new Number(0)
var cookieDescEnd = new Number(0)
var cookieSizeEnd = new Number(0)
var cookieColorEnd = new Number(0)
var cookieQtyEnd = new Number(0)
var cookieSubtEnd = new Number(0)
var cookieDataIndex = new Number(0)
var cookieDataInv = new String("")
var cookieDataDesc = new String("")
var cookieDataSize = new String("")
var cookieDataColor = new String("")
var cookieDataQty = new String("")
var cookieDataSubt = new String("")

var paymentType = new String("Email")


/*
**    Save the current shopping cart contents, including the
** invoice number.
**
** Format:
**
**    header invoice# : data1_1 + data1_n : data2_1 + data2_n :  (etc.)
*/

function save_cart()
{
var i = new Number();
var cookieDate = new Date();
var invoice = new String("");
var cookieDataDesc = new String("");
var cookieDataSize = new String("");
var cookieDataColor = new String("");
var cookieDataQty = new String("");
var cookieDataSubt = new String("");

    invoice = document.itemForm.invoice.value;

    for (i = 1; i < MAX_ENTRIES; i++)
    {
        if (itemDesc[i] != "")
        {
            if (i == 1)                       /* First entry has no delimiter ("+") */
            {
                cookieDataDesc = (itemDesc[i]);
                cookieDataSize = (itemSize[i]);
                cookieDataColor = (itemColor[i]);
                cookieDataQty = (itemQty[i]);
                cookieDataSubt = (itemSubt[i]);
            }
            else                              /* All subsequent entries */
            {
                cookieDataDesc = (cookieDataDesc + "+" + itemDesc[i]);
                cookieDataSize = (cookieDataSize + "+" + itemSize[i]);
                cookieDataColor = (cookieDataColor + "+" + itemColor[i]);
                cookieDataQty = (cookieDataQty + "+" + itemQty[i]);
                cookieDataSubt = (cookieDataSubt + "+" + itemSubt[i]);
            }
        }
        else
        {
            break;
        }
    }

    /*
    ** Add the delimiter to the end of each data string
    */

    cookieDataDesc = (cookieDataDesc + "+");
    cookieDataSize = (cookieDataSize + "+");
    cookieDataColor = (cookieDataColor + "+");
    cookieDataQty = (cookieDataQty + "+");
    cookieDataSubt = (cookieDataSubt + "+");

    /*
    ** Now actually create the cookie.
    */

    cookieDate.setTime(cookieDate.getTime() + 24 * 60 * 60 * 1000);
    document.cookie = cookieHeader + invoice + ":" + cookieDataDesc +
      ":" + cookieDataSize + ":" + cookieDataColor + ":" + cookieDataQty +
      ":" + cookieDataSubt +
      ":;expires=" + cookieDate.toGMTString();
}


/*
**    Read and parse the basic cookie data. Parse the individual
** data strings later.
*/

function get_cookie_data()
{
    cookieRaw = document.cookie;                                                 /* Read the cookie                     */
    cookieStart = cookieRaw.indexOf(cookieHeader);                               /* Raw data start                      */
    cookieInvEnd = cookieRaw.indexOf(":");                                       /* End of invoice number               */
    cookieDescEnd = cookieRaw.indexOf(":", (cookieInvEnd + 1));                  /* End of item description data string */
    cookieSizeEnd = cookieRaw.indexOf(":", (cookieDescEnd + 1));                 /* End of item size data string        */
    cookieColorEnd = cookieRaw.indexOf(":", (cookieSizeEnd + 1));                /* End of item color data string       */
    cookieQtyEnd = cookieRaw.indexOf(":", (cookieColorEnd + 1));                 /* End of item quantity data string    */
    cookieSubtEnd = cookieRaw.indexOf(":", (cookieQtyEnd + 1));                  /* End of item subtotal data string    */
    cookieDataIndex = (cookieStart + cookieHeader.length);                       /* Start of cart data (end of header)  */
    cookieDataInv = cookieRaw.substring(cookieDataIndex, cookieInvEnd);          /* Invoice number string               */
    cookieDataDesc = cookieRaw.substring((cookieInvEnd + 1), cookieDescEnd);     /* Item description data string        */
    cookieDataSize = cookieRaw.substring((cookieDescEnd + 1), cookieSizeEnd);    /* Item size data string               */
    cookieDataColor = cookieRaw.substring((cookieSizeEnd + 1), cookieColorEnd);  /* Item color data string              */
    cookieDataQty = cookieRaw.substring((cookieColorEnd + 1), cookieQtyEnd);     /* Item quantity data string           */
    cookieDataSubt = cookieRaw.substring((cookieQtyEnd + 1), cookieSubtEnd);     /* Item subtotal data string           */
}


/*
**    Read and parse all of the cart data, and put it in
** the local data arrays.
*/

function get_cart()
{
var i = new Number();
var tmpStart = new Number(0);
var tmpEnd = new Number(0);
var tmpLength = new Number(0);
var tmpStr = new String("");

    clr_cart_array();       /* Make sure the data arrays are clean */
    get_cookie_data();      /* Read the basic cart data            */

    /*
    **    For each data string (description, size, color, quantity, subtotal),
    ** extract the individual values for each item in the cart.
    */

    if (cookieStart != -1)
    {
        document.itemForm.invoice.value = cookieDataInv;
        itemDesc[0] = cookieDataInv;

        tmpStart = 0;
        tmpEnd = 0;
        tmpLength = cookieDataDesc.length;

        for (i = 1; i < MAX_ENTRIES; i++)
        {
            tmpEnd = cookieDataDesc.indexOf("+", tmpStart);
            tmpStr = cookieDataDesc.substring(tmpStart, tmpEnd);

            if ((tmpStart >= tmpLength) || (tmpStr == "") || (tmpStr == "+") || (tmpStr == -1))
            {
                break;
            }
            else
            {
                itemDesc[i] = tmpStr;
                tmpStart = (tmpEnd + 1);
            }
        }

        tmpStart = 0;
        tmpEnd = 0;
        tmpLength = cookieDataSize.length;

        for (i = 1; i < MAX_ENTRIES; i++)
        {
            tmpEnd = cookieDataSize.indexOf("+", tmpStart);
            tmpStr = cookieDataSize.substring(tmpStart, tmpEnd);

            if ((tmpStart >= tmpLength) || (tmpStr == "") || (tmpStr == "+") || (tmpStr == -1))
            {
                break;
            }
            else
            {
                itemSize[i] = tmpStr;
                tmpStart = (tmpEnd + 1);
            }
        }

        tmpStart = 0;
        tmpEnd = 0;
        tmpLength = cookieDataColor.length;

        for (i = 1; i < MAX_ENTRIES; i++)
        {
            tmpEnd = cookieDataColor.indexOf("+", tmpStart);
            tmpStr = cookieDataColor.substring(tmpStart, tmpEnd);

            if ((tmpStart >= tmpLength) || (tmpStr == "") || (tmpStr == "+") || (tmpStr == -1))
            {
                break;
            }
            else
            {
                itemColor[i] = tmpStr;
                tmpStart = (tmpEnd + 1);
            }
        }

        tmpStart = 0;
        tmpEnd = 0;
        tmpLength = cookieDataQty.length;

        for (i = 1; i < MAX_ENTRIES; i++)
        {
            tmpEnd = cookieDataQty.indexOf("+", tmpStart);
            tmpStr = cookieDataQty.substring(tmpStart, tmpEnd);

            if ((tmpStart >= tmpLength) || (tmpStr == "") || (tmpStr == "+") || (tmpStr == -1))
            {
                break;
            }
            else
            {
                itemQty[i] = tmpStr;
                tmpStart = (tmpEnd + 1);
            }
        }

        tmpStart = 0;
        tmpEnd = 0;
        tmpLength = cookieDataSubt.length;

        for (i = 1; i < MAX_ENTRIES; i++)
        {
            tmpEnd = cookieDataSubt.indexOf("+", tmpStart);
            tmpStr = cookieDataSubt.substring(tmpStart, tmpEnd);

            if ((tmpStart >= tmpLength) || (tmpStr == "") || (tmpStr == "+") || (tmpStr == -1))
            {
                break;
            }
            else
            {
                itemSubt[i] = tmpStr;
                tmpStart = (tmpEnd + 1);
            }
        }
    }
}


/*
**    This function will normalize a floating-point number to monetary
** format with two decimal places and trailing zeroes.
*/

function to_dollars(value)
{
var temp = new String(value);

    if (temp.indexOf(".") != -1)
    {
      temp = temp.substring(0, (temp.indexOf(".") + 3));

      if (temp.charAt(temp.indexOf(".") + 1) == "")
      {
        temp = (temp + "0");
      }

      if (temp.charAt(temp.indexOf(".") + 2) == "")
      {
        temp = (temp + "0");
      }
    }
    else
    {
      temp = (temp + ".00");
    }

    return(temp);
}


/*
**    Calculates the subtotal for the given item.
*/

function get_subtotal(item)
{
    switch (item)
    {
      case "t1":
          /*
          ** Default quantity is one, if the user is out of bounds
          */

          if ((Number(document.itemForm.t1Qty.value) < 1) ||
            (Number(document.itemForm.t1Qty.value) > 99) ||
            (document.itemForm.t1Qty.value == ""))
          {
              document.itemForm.t1Qty.value = 1;
          }

          document.itemForm.t1Sub.value = to_dollars(Number(document.itemForm.t1Qty.value) *
            Number(document.itemForm.t1Price.value));
          break;

      default:
          window.alert("Unknown item: " + item);
          return(-1);
          break;
    }
}


/*
**    Displays the subtotal for a given item.
*/

function show_subtotal(item)
{
    switch (item)
    {
        case "t1":
            document.write(document.itemForm.t1Sub.value);
            break;

        default:
            window.alert("Unknown item (2): " + item);
              return(-1);
            break;
    }
}


/*
**    Calculates the order total, before tax if any,
** but including shipping and handling.
*/

function get_total()
{
var subTotal = Number(0);
var sh_value = SHIPPING_A;

    document.itemForm.total.value = Number(0);

    if (Number(get_cart_subts()) == 0)
    {
        return(0);
    }

    if (document.itemForm.t1Sub.value != "")
    {
        document.itemForm.total.value = (Number(document.itemForm.total.value) +
          Number(document.itemForm.t1Sub.value));
    }

    subTotal = Number(document.itemForm.total.value);

    /*
    ** Default is SHIPPING_A
    */

    if (subTotal > LIMIT_A)
    {
        if (subTotal > LIMIT_B)
        {
            sh_value = SHIPPING_C;
        }
        else
        {
            sh_value = SHIPPING_B;
        }
    }

    if (sh_value == "CALL")
    {
        document.itemForm.total.value = to_dollars(Number(document.itemForm.total.value));
        document.itemForm.ccShipping.value = sh_value;
    }
    else
    {
        document.itemForm.ccShipping.value = to_dollars(Number(sh_value));
        document.itemForm.total.value = to_dollars(Number(document.itemForm.total.value) +
          Number(sh_value));
    }

    return(document.itemForm.total.value);
}


/*
**    Displays the order total.
*/

function show_total()
{
    document.write(document.itemForm.total.value);
}


/*
**    Calculates the tax for California orders.
*/

function calculate_tax()
{
var subTotal = Number(0);
var tax = Number(0);
var total = Number(0);

    subTotal = (Number(get_total()) - Number(HANDLING));
    tax = Number(subTotal * .0725);
    total = Number(subTotal + tax);
    document.itemForm.caTax.value = to_dollars(Number(tax));
    document.itemForm.total.value = to_dollars(Number(total) + Number(HANDLING));
}


/*
**    This function verifies that the user has entered required data
** fields before sending the form.
*/

function check_user_data()
{
    if (document.itemForm.total.value == "")
    {
      alert("Please select all desired items, then click in the 'Total' box");
      return(false);
    }

    if (Number(get_total()) == 0)
    {
      alert("Sorry, no items selected");
      return(false);
    }

    if (document.itemForm.theFirstName.value == "")
    {
      alert("Please enter your first name");
      return(false);
    }

    if (document.itemForm.theLastName.value == "")
    {
      alert("Please enter your last name");
      return(false);
    }

    if (document.itemForm.theAddress1.value == "")
    {
      alert("Please enter your address");
      return(false);
    }

    if (document.itemForm.theCity.value == "")
    {
      alert("Please enter your city");
      return(false);
    }

    if (document.itemForm.theState.value == "")
    {
      alert("Please enter your state or province");
      return(false);
    }

    if (document.itemForm.theZip.value == "")
    {
      alert("Please enter your ZIP or postal code");
      return(false);
    }

    return(true);
}


function set_pay_type_email()
{
    paymentType = "Email";
}


function set_pay_type_paypal()
{
    paymentType = "PayPal";
}


/*
**    Set up the PayPal form in case the user wants to use PayPal,
** and then post the data to the PayPal server.
*/

function set_paypal_data()
{
var i = new Number(0);
var n = new Number(0);
var ppFormData = new String("https://www.paypal.com/cgi-bin/webscr?");
var tmpStr = new String("");

    if (check_user_data() == false)    /* Make sure we have all the info */
    {
        return(false);                 /* Need more info from user       */
    }

    /*
    ** Save all the cart data so it gets passed in the email
    */

    get_cookie_data();                 /* Partially decode the cart data */

    document.itemForm.desc.value = cookieDataDesc;
    document.itemForm.size.value = cookieDataSize;
    document.itemForm.color.value = cookieDataColor;
    document.itemForm.qty.value = cookieDataQty;
    document.itemForm.subt.value = cookieDataSubt;

    if (paymentType == "Email")        /* Email only, so just bail       */
    {
        return(true);
    }

    /*
    ** Copy customer data from CC form to PayPal form
    */

    document.itemForm.item_name.value = "Missy Piggy T-shirts";
    document.itemForm.quantity.value = 1;
    document.itemForm.amount.value = document.itemForm.total.value;

    /*
    ** Use the customer's address from the order form.
    */

    document.itemForm.first_name.value = document.itemForm.theFirstName.value;
    document.itemForm.last_name.value = document.itemForm.theLastName.value;
    document.itemForm.address1.value = document.itemForm.theAddress1.value;
    document.itemForm.address2.value = document.itemForm.theAddress2.value;
    document.itemForm.city.value = document.itemForm.theCity.value;
    document.itemForm.state.value = document.itemForm.theState.value;
    document.itemForm.zip.value = document.itemForm.theZip.value;

    n = document.itemForm.theCountry.selectedIndex;

    if (document.itemForm.theCountry.options[n].text == "Other")
    {
        document.itemForm.lc.value = document.itemForm.otherCountry.value;
    }
    else
    {
        document.itemForm.lc.value = document.itemForm.theCountry.options[n].text;
    }

    /*
    ** Construct the data string to send to PayPal's server
    */

    with (document.itemForm)
    {
        ppFormData = (ppFormData + "cmd" + "=" + cmd.value);
        ppFormData = (ppFormData + "&" + "invoice" + "=" + invoice.value);
        ppFormData = (ppFormData + "&" + "business" + "=" + business.value);
        ppFormData = (ppFormData + "&" + "return" + "=" + "http://www.cuddlycritters.org/thankyou.htm");
        ppFormData = (ppFormData + "&" + "currency_code" + "=" + currency_code.value);
        ppFormData = (ppFormData + "&" + "bn" + "=" + bn.value);
        ppFormData = (ppFormData + "&" + "lc" + "=" + lc.value);
        ppFormData = (ppFormData + "&" + "cn" + "=" + "We welcome your comments");
        ppFormData = (ppFormData + "&" + "item_name" + "=" + item_name.value);
        ppFormData = (ppFormData + "&" + "quantity" + "=" + quantity.value);
        ppFormData = (ppFormData + "&" + "amount" + "=" + amount.value);
        ppFormData = (ppFormData + "&" + "address_override" + "=" + address_override.value);
        ppFormData = (ppFormData + "&" + "first_name" + "=" + first_name.value);
        ppFormData = (ppFormData + "&" + "last_name" + "=" + last_name.value);
        ppFormData = (ppFormData + "&" + "address1" + "=" + address1.value);
        ppFormData = (ppFormData + "&" + "address2" + "=" + address2.value);
        ppFormData = (ppFormData + "&" + "city" + "=" + city.value);
        ppFormData = (ppFormData + "&" + "state" + "=" + state.value);
        ppFormData = (ppFormData + "&" + "zip" + "=" + zip.value);
    }

    /*
    ** Convert special characters to form post format
    */

    for (i = 38; i < ppFormData.length; i++)         /* Start looking after address header */
    {
        if (ppFormData.charAt(i) == " ")             /* Check for space and replace with "+" */
        {
            tmpStr = ppFormData.substr(0, i);
            tmpStr = tmpStr + "+";
            ppFormData = tmpStr + ppFormData.substr((i + 1), ppFormData.length);
        }

        if (ppFormData.charAt(i) == "/")             /* Check for slash and replace with "%2F" */
        {
            tmpStr = ppFormData.substr(0, i);
            tmpStr = tmpStr + "%2F";
            ppFormData = tmpStr + ppFormData.substr((i + 1), ppFormData.length);
        }

        if (ppFormData.charAt(i) == ":")             /* Check for colon and replace with "%3A" */
        {
            tmpStr = ppFormData.substr(0, i);
            tmpStr = tmpStr + "%3A";
            ppFormData = tmpStr + ppFormData.substr((i + 1), ppFormData.length);
        }
    }

    window.location = ppFormData;                    /* Go to the PayPal site, passing all the info */
    return(true);
}


/*
** Create a unique invoice number based on the current date and time.
*/

function make_invoice_number()
{
var tmpStr = new String("");
var invoice = new String("");
var timeDate = new Date();

    /*
    ** For some as yet unknown reason, the getMonth() and getUTCMonth()
    ** methods return a value that is one less than what it should be.
    ** The following line is a kludge to make it come out right.
    */

    tmpStr = String(timeDate.getUTCMonth() + 1)

    invoice = (timeDate.getUTCFullYear().toString() + "-" + tmpStr +
                "-" + timeDate.getUTCDate().toString() + "-" + timeDate.getUTCHours().toString() +
                "-" + timeDate.getUTCMinutes().toString() + "-" + timeDate.getUTCSeconds().toString());

    return(invoice);
}


/*
**    Reset the "Add to Cart" button text.
*/

function clr_button()
{
    document.itemForm.t1CartAdd.value = "Add to Cart";
}


/*
**    Zero-out just the arrays.
*/

function clr_cart_array()
{
var i = new Number();

    for (i = 0; i < MAX_ENTRIES; i++)
    {
        itemDesc[i] = "";
        itemSize[i] = "";
        itemColor[i] = "";
        itemQty[i] = "";
        itemSubt[i] = "";
    }
}


/*
**    Zero-out item info in the form (quantity, subtotal).
*/

function clr_form()
{
var i = new Number();

    /*
    ** Clear all quantities and reset all colors to white
    */

    document.itemForm.t1Desc.value = "Missy Piggy YOTP T-shirt";
    document.itemForm.t1Size.value = "Childs - Lg (14-16)";
    document.itemForm.t1Qty.value = "1";
    document.itemForm.t1Color.value = "White";
    document.itemForm.t1Sub.value = "";

    /*
    ** Show defaults as selected for all items
    */

    document.itemForm.t1SizeSel.options[0].selected = true;
    document.itemForm.t1ColorSel.options[0].selected = true;

    /*
    ** Deselect all other options
    */

    for (i = 1; i < MAX_SIZES; i++)
    {
        document.itemForm.t1SizeSel.options[i].selected = false;
    }

    for (i = 1; i < MAX_COLORS; i++)
    {
        document.itemForm.t1ColorSel.options[i].selected = false;
    }

    clr_button();          /* Also reset the button text */
}


/*
**    Remove all items from the shopping cart, including
** the invoice number.
*/

function empty_cart()
{
    clr_cart_array();                                            /* Clean the junk out of the arrays  */
    clr_button();                                                /* Also reset the button text        */
    document.itemForm.cartView.disabled = true;                  /* Disable the cart view button      */
    document.itemForm.cartEmpty.disabled = true;                 /* Disable the empty cart button     */
    document.itemForm.invoice.value = "";                        /* Null invoice number means no cart */
    document.itemForm.ccShipping.value = "";                     /* Default S/H value                 */
    save_cart();                                                 /* Save the new (empty) cart         */
    get_total();                                                 /* Update the order total            */
}


/*
**    Add an item and all related info to the shopping cart.
*/

function add_to_cart(item)
{
var i = new Number();
var n = new Number(0);

    get_cart();                          /* Grab the current contents of the cart             */

    if (itemDesc[0] == "")               /* If this is the first entry (no invoice number),   */
    {                                    /*   get an invoice number and put it in entry 0     */
        itemDesc[0] = make_invoice_number();
        document.itemForm.invoice.value = itemDesc[0];      /* Put invoice number in form     */
        n = 1;
    }
    else                                 /* Cart already exists, scan for an open item slot   */
    {
        for (i = 1; i < MAX_ENTRIES; i++)
        {
            if (itemDesc[i] == "")
            {
                n = i;
                break;
            }
        }

        if (i == MAX_ENTRIES)
        {
            window.alert("Sorry, the shopping cart is full!");
            return(-1);
        }
    }

    document.itemForm.cartView.disabled = false;        /* Enable the cart view button     */
    document.itemForm.cartEmpty.disabled = false;       /* Enable the cart empty button    */

    /*
    ** Now put the new item data into the data arrays
    */

    get_subtotal("t1");                              /* First update the subtotal value */

    switch (item)
    {
        case "t1": 
            itemDesc[n] = document.itemForm.t1Desc.value;
            itemSize[n] = document.itemForm.t1Size.value;
            itemColor[n] = document.itemForm.t1Color.value;
            itemQty[n] = document.itemForm.t1Qty.value;
            itemSubt[n] = document.itemForm.t1Sub.value;
            break;

        default:
            window.alert("add_to_cart() - This should never happen (yeah, right!).");
            break;
    }

    save_cart();                                          /* Save the updated cart data */
    get_total();                                          /* Update the order total     */
    return(0);
}


/*
**    Display the contents of the shopping cart for the user.
*/

function view_cart(e)
{
var i = new Number();

    get_cart();                                        /* Fetch the current cart contents                  */

    if (itemDesc[0] == "")                             /* If there is no invoice number, the cart is empty */
    {
        window.alert("Your shopping cart is empty!");
        document.itemForm.cartView.disabled = true;    /* Disable the cart view button                     */
        document.itemForm.cartEmpty.disabled = true;   /* Disable the empty cart button                    */
        return(-1);
    }

    clr_form();                                        /* Clean up the form for the user on their return   */
                                                       /*   to the order page                              */

    document.writeln("<?xml version='1.0'?>");
    document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'");
    document.writeln("'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
    document.writeln("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
    document.writeln("<head>");
    document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
    document.writeln("<meta name='GENERATOR' content='Wolftracks 1.0'>");
    document.writeln("<title>Cuddly Critters, Inc. - Missy Piggy's Stuff</title>");
    document.writeln("<script type='text/javascript' language='javascript' src='missy_piggy_stuff.js'></script>");
    document.writeln("<link rel='stylesheet' href='global.css' />");
    document.writeln("<style type='text/css'>");
    document.writeln("a:link {color: #0000FF}");
    document.writeln("a:visited {color: #EE82EE}");
    document.writeln("a:hover {color: #008000}");
    document.writeln("a:active {color: #FF00FF}");
    document.writeln("body");
    document.writeln("{");
    document.writeln("margin: 0; padding: 0; width: 100%; height: 100%; background-color: lightgreen;");
    document.writeln("background-repeat: no-repeat; background-position: center center;");
    document.writeln("color: black; text-align: center; text-weight: bold;");
    document.writeln("}");
    document.writeln("</style></head>");

    document.writeln("<body><div id='container'><br><b><font size='+3'><p align='center'>");
    document.writeln("<u>Your Cuddly Critters Shopping Cart</u></p></font></b><br><br>");
    document.writeln("<table border='2' cellpadding='0' cellspacing='0' width='800'>");
    document.writeln("<tr><td><p align='center'><b>Quantity</b></p></td>");
    document.writeln("<td><p align='center'><b>Description</b></p></td>");
    document.writeln("<td><p align='center'><b>Size</b></p></td>");
    document.writeln("<td><p align='center'><b>Color</b></p></td>");
    document.writeln("<td><p align='center'><b>Subtotal</b></p></td></tr>");

    document.writeln("<b>");


    /*
    ** Step through the list of items in the cart and display the data
    */

    for (i = 1; i < MAX_ENTRIES; i++)
    {
        if (itemDesc[i] == "")
        {
            break;                                      /* End of cart                                      */
        }
        else
        {
            document.writeln("<tr><td><p align='center'>" + itemQty[i] + "</p></td>");
            document.writeln("<td><p align='center'>" + itemDesc[i] + "</p></td>");
            document.writeln("<td><p align='center'>" + itemSize[i] + "</p></td>");
            document.writeln("<td><p align='center'>" + itemColor[i] + "</p></td>");
            document.writeln("<td><p align='center'>" + itemSubt[i] + "</p></td></tr>");
        }
    }

    document.writeln("</b><br>");
    document.writeln("</table><br><br><b>&#62;&#62; Use the &#34;Back&#34; button on your browser to return to your order page &#60;&#60;</b><br>");
    document.writeln("</font></b></div></body>");
}


/*
**    Gathers the subtotals from the cart and puts them in the form.
*/

function get_cart_subts()
{
var i = new Number();

    get_cart();                                   /* Get the cart data */

    document.itemForm.t1Sub.value = Number(0);

    for (i = 1; i < MAX_ENTRIES; i++)
    {
        if (itemDesc[i] != "")
        {
                    document.itemForm.t1Sub.value = to_dollars((Number(document.itemForm.t1Sub.value) +
                      Number(itemSubt[i])));
        }
    }

    clr_button();        /* Also reset the button text */
    return(document.itemForm.t1Sub.value);
}


/*
** Get the user's choice of color from the options arrays.
*/

function get_color_selection(item)
{
var i = new Number();

    switch (item)
    {
        case "t1":
            for (i = 0; i < MAX_COLORS; i++)
            {
                if (document.itemForm.t1ColorSel.options[i].selected)
                {
                    document.itemForm.t1Color.value = document.itemForm.t1ColorSel.options[i].text;
                }
            }

            break;

        default:
            window.alert("get_color_selection() - This should never happen (oops, it did!).");
            return(-1);
            break;
    }
}


/*
** Get the user's choice of size from the options arrays.
*/

function get_size_selection(item)
{
var i = new Number();

    switch (item)
    {
        case "t1":
            for (i = 0; i < MAX_SIZES; i++)
            {
                if (document.itemForm.t1SizeSel.options[i].selected)
                {
                    document.itemForm.t1Size.value = document.itemForm.t1SizeSel.options[i].text;
                }
            }

            break;

        default:
            window.alert("get_size_selection() - This should never happen (oops, it did!).");
            return(-1);
            break;
    }
}
