
//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design.  You must keep this comment unchanged in  ||
// your code.  For more information contact FreeCart@NopDesign.com.    ||
//                                                                     ||
// JavaScript Shop Module, V.4.4.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Global Options                                ||
//                      ----------------                               ||
// Shopping Cart Options, you can modify these options to change the   ||
// the way the cart functions.                                         ||
//                                                                     ||
// Language Packs                                                      ||
// ==============                                                      ||
// You may include any language pack before nopcart.js in your HTML    ||
// pages to change the language.  Simply include a language pack with  ||
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.          ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * DisplayShippingColumn: true/false, controls whether the managecart||
//   and checkout pages display shipping cost column.                  ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping cost total row.               ||
// * DisplayTaxRow: true/false, controls whether the managecart        ||
//   and checkout pages display tax cost total row.                    ||
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable when TaxByRegion is set to true.            ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.  If TaxByRegion is set to false, this ||
//   has no effect. Example: 'Arizona Residents'                       ||
// * NonTaxablePrompt: string, same as above, but the choice for non-  ||
//   taxable people.  Example: 'Other States'                          ||
// * MinimumOrder: number, the minium dollar amount that must be       ||
//   purchased before a user is allowed to checkout.  Set to 0.00      ||
//   to disable.                                                       ||
// * MinimumOrderPrompt: string, Message to prompt users with when     ||
//   they have not met the minimum order amount.                       ||
//                                                                     ||
// Payment Processor Options:                                          ||
// ==========================                                          ||
// * PaymentProcessor: string, the two digit payment processor code    ||
//   for support payment processor gateways.  Setting this field to    ||
//   anything other than an empty string will override your OutputItem ||
//   settings -- so please be careful when receiving any form data.    ||
//   Support payment processor gateways are:                           ||
//    * Authorize.net (an)                                             ||
//    * Worldpay      (wp)                                             ||
//    * LinkPoint     (lp)
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//Options for Everyone:
MonetarySymbol         = '$';
DisplayNotice          = false;
DisplayShippingColumn  = false;
DisplayShippingRow     = true;
DisplayTaxRow          = true;
TaxRate                = 0.0625;
TaxByRegion            = true;
TaxPrompt              = 'For tax purposes, please indicate whether you are a Massachusetts resident before continuing';
TaxablePrompt          = 'Massachusetts Residents';
NonTaxablePrompt       = 'Other States';
MinimumOrder           = 0.00;
MinimumOrderPrompt     = 'Your order is below our minimum order, please order more before checking out.';

//Payment Processor Options:
PaymentProcessor       = 'an';

//Options for Programmers:
OutputItemId           = 'ID_';
OutputItemQuantity     = 'QUANTITY_';
OutputItemPrice        = 'PRICE_';
OutputItemName         = 'NAME_';
OutputItemShipping     = 'SHIPPING_';
OutputItemAddtlInfo    = 'ADDTLINFO_';
OutputOrderSubtotal    = 'SUBTOTAL';
OutputOrderShipping    = 'SHIPPING';
OutputOrderTax         = 'TAX';
OutputOrderTotal       = 'TOTAL';
AppendItemNumToOutput  = true;
HiddenFieldsToCheckout = true;
MaxItemsInCart         = 15; // Maximum number of items in shopping cart - note need to change cart processing code if you change this number


//=====================================================================||
//---------------------------------------------------------------------||
//    YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE        ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
//                      Language Strings                               ||
//                     ------------------                              ||
// These strings will not be used unless you have not included a       ||
// language pack already.  You should NOT modify these, but instead    ||
// modify the strings in language-**.js where ** is the language pack  ||
// you are using.                                                      ||
//---------------------------------------------------------------------||

   strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
   strAdded  = " added to your shopping cart.";
   strRemove = "Are you sure you want to remove this product from your shopping cart?";
   strILabel = "Code";
   strDLabel = "Description";
   strQLabel = "Qty";
   strPLabel = "Price";
   strSLabel = "Shipping";
   strRLabel = "";
   strRButton= "Remove";
   strSUB    = "SUBTOTAL";
   strSHIP   = "SHIPPING**";
   strTAX    = "TAX";
   strTOT    = "TOTAL";
   strErrQty = "Invalid Quantity.";
   strNewQty = 'Please enter new quantity:';
   strEmpty  = "Are you sure you want to empty your shopping cart?";
   bLanguageDefined = true;


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
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";
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteInfo                                             ||
// PARAMETERS:  name                                                   ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a value from shared cookie.                    ||
//---------------------------------------------------------------------||
function DeleteInfo (name) {

  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

        testval = GetInfo(name);

        if (testval != null) {
          cookieval = GetCookie("HInfo");
          
          searchtoken = "|" + name + "|";
          
          starttag = cookieval.indexOf(searchtoken, 0);
          if (starttag >= 0) {
            endtag = cookieval.indexOf("|", starttag+1);
            startstring = endtag + 1;
            endstring = cookieval.indexOf("|", startstring) - 1;
          
            firstpart = cookieval.substring(0, starttag+1);
            secondpart = cookieval.substring(endstring+2, cookieval.length);
            cookieval = firstpart + secondpart;
            if (cookieval == "|") {
              DeleteCookie("HInfo");
            } else {
              SetCookie("HInfo", cookieval, exp, "/");
            }
          }
        } 
}


//---------------------------------------------------------------------||
// FUNCTION:    SetInfo                                                ||
// PARAMETERS:  name, value, expiration date                           ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a value in a shared cookie                      ||
//---------------------------------------------------------------------||
function SetInfo (name,value) {

  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

        if (name != null) {
        
          cookieval = GetCookie("HInfo");
          if (cookieval != null) {    
            DeleteInfo(name);
            cookieval += name + "|" + value + "|";
          } else {
            cookieval = "|" + name + "|" + value + "|";
          }
          
          SetCookie("HInfo", cookieval, exp, "/");
          
        }
}         


//---------------------------------------------------------------------||
// FUNCTION:    GetInfo                                                ||
// PARAMETERS:  Cookie name                                            ||
// RETURNS:     value                                                  ||
// PURPOSE:     Gets a named value from a common cookie.               ||
//---------------------------------------------------------------------||
function GetInfo (name) {

        cookieval = GetCookie("HInfo");
        
        if (cookieval != null) {
          
          searchtoken = "|" + name + "|";
          
          var starttag = cookieval.indexOf(searchtoken, 0);
          if (starttag >= 0) {
            var endtag = cookieval.indexOf("|", starttag+1);
            var startstring = endtag + 1;
            var endstring = cookieval.indexOf("|", startstring);
          
            retstring = cookieval.substring(startstring, endstring);
          } else {
            retstring = null;
          }
          
          return retstring;
          
        } else {
        
          return null;
        }
}



//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   
   var expDays = 30;
   var exp = new Date(); 
   exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
   
   iNumberOrdered = GetInfo("HNumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else
      strID_NUM    = thisForm.ID_NUM.value;

   if ( thisForm.QUANTITY == null )
      strQUANTITY  = "1";
   else
      strQUANTITY  = thisForm.QUANTITY.value;

   if ( thisForm.PRICE == null )
      strPRICE     = "0.00";
   else
      strPRICE     = thisForm.PRICE.value;

   if ( thisForm.NAME == null )
      strNAME      = "";
   else
      strNAME      = thisForm.NAME.value;

   if ( thisForm.SHIPPING == null )
      strSHIPPING  = "0.00";
   else
      strSHIPPING  = thisForm.SHIPPING.value;

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "HOrder." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );
      
      if ( strID_NUM == "73500" || strID_NUM == "73501")
        {
        if (parseInt(fields[1]) > 5)
          {
          fields[1] = "5";
          }
        }

      if ( fields[0] == strID_NUM &&
           fields[2] == strPRICE  &&
           fields[3] == strNAME   &&
           fields[5] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         
         if ( strID_NUM == "73500" ||
              strID_NUM == "73501"
            ) {
              fields[1] = "0";
              }
              
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strQUANTITY)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;
         strNewOrder = "HOrder." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, exp, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > MaxItemsInCart ) {
         alert( strSorry );
      }
      else {
        if ( strID_NUM.substring(0,1) == "C" ) {
          // Adding one or more containers to cart - add to the number of containers in this order
          // and store in cookie
                
          iNumberContainers = GetInfo("HNumberContainers");
                
          if ( iNumberContainers == null ) {
            iNumberContainers = 0;
          }
              
          iNumberContainers = parseInt(thisForm.QUANTITY.value) + parseInt(iNumberContainers);
              
          SetInfo ("HNumberContainers", iNumberContainers, exp, "/");
                
        } 

        dbUpdatedOrder = strID_NUM    + "|" + 
                         strQUANTITY  + "|" +
                         strPRICE     + "|" +
                         strNAME      + "|" +
                         strSHIPPING  + "|" +
                         strADDTLINFO;

        strNewOrder = "HOrder." + iNumberOrdered;
        SetCookie(strNewOrder, dbUpdatedOrder, exp, "/");
        SetInfo("HNumberOrdered", iNumberOrdered, exp, "/");
        notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }

   location="mb_cart.php";
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   if ( input < 0 )
     {
     var dollars = Math.ceil(input);
     }
   else
     {
     var dollars = Math.floor(input);
     }
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) 
{

   var expDays = 30;
   var exp = new Date(); 
   exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

   if ( confirm( strRemove ) ) {
      NumberOrdered = GetInfo("HNumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "HOrder." + (i+1);
         NewOrder2 = "HOrder." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, exp, "/");
      }
      NewOrder = "Order." + NumberOrdered;
      SetInfo ("HNumberOrdered", NumberOrdered-1, exp, "/");
      DeleteCookie(NewOrder, "/");
      location.href=location.href;
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity)
{

   var expDays = 30;
   var exp = new Date(); 
   exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

   if ( isNaN(NewQuantity) ) {
      alert( strErrQty );
   } else {
      if (NewQuantity < 1) {
        NewQuantity = 1;
      }
      NewOrder = "HOrder." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );
      
      if ( fields[0] == "73500" || fields[0] == "73501") 
        {
        if (NewQuantity > 5)
          {
          NewQuantity = "5";
          }
        }


      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5];
      strNewOrder = "HOrder." + OrderItem;
      DeleteCookie(strNewOrder, "/");
      SetCookie(strNewOrder, dbUpdatedOrder, exp, "/");
      location.href=location.href;      
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    GetFromCart                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//              **DEPRECATED FUNCTION, USE ManageCart or Checkout**    ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
   ManageCart( );
}


//---------------------------------------------------------------------||
// FUNCTION:    RadioChecked                                           ||
// PARAMETERS:  Radio button to check                                  ||
// RETURNS:     True if a radio has been checked                       ||
// PURPOSE:     Form fillin validation                                 ||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }    
   return bChecked;
} 


//---------------------------------------------------------------------||
// FUNCTION:    QueryString                                            ||
// PARAMETERS:  Key to read                                            ||
// RETURNS:     value of key                                           ||
// PURPOSE:     Read data passed in via GET mode                       ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
   var value = null;
   for (var i=0;i<QueryString.keys.length;i++) {
      if (QueryString.keys[i]==key) {
         value = QueryString.values[i];
         break;
      }
   }
   return value;
} 

//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
   var query = window.location.search.substring(1);
   var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
      var pos = pairs[i].indexOf('=');
      if (pos >= 0) {
         var argname = pairs[i].substring(0,pos);
         var value = pairs[i].substring(pos+1);
         QueryString.keys[QueryString.keys.length] = argname;
         QueryString.values[QueryString.values.length] = value;
      }
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    EmptyCart                                              ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Empty cart and allocate a new order number.            ||
//---------------------------------------------------------------------||

function EmptyCart()
{

  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  
    iNumberOrdered = GetInfo("HNumberOrdered");
        
    if ( iNumberOrdered == null ) {
      iNumberOrdered = 0;
    }

    for ( i = 1; i <= iNumberOrdered; i++ ) {
      strNewOrder = "HOrder." + i;
      DeleteCookie(strNewOrder, "/");
    }

    DeleteInfo("HNumberOrdered", "/");
    DeleteInfo("HNumberContainers", "/");
    DeleteInfo("HOrderNumber", "/");
    DeleteInfo("HCustomerName", "/");
    DeleteInfo("HGiftMessage", "/");
    DeleteInfo("HSource", "/");
    
    // Allocate a new order number - use a random number generator
    OrderNumber = Math.random();
    OrderNumber = Math.round(OrderNumber * 100000000);
    SetInfo("HOrderNumber", OrderNumber, exp, "/");
}


//---------------------------------------------------------------------||
// FUNCTION:    StartOver                                              ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Check with user, then empty cart.                      ||
//---------------------------------------------------------------------||

function StartOver()
{

  
  if ( confirm( strEmpty ) ) {
    EmptyCart();
  }

}

//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageCart( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fExtPrice      = 0;    //Extended price of line item (qty * price)
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   
   var expDays = 30;
   var exp = new Date(); 
   exp.setTime(exp.getTime() + (expDays*24*60*60*1000));   

  iNumberOrdered = GetInfo("HNumberOrdered");

   if (iNumberOrdered == null || iNumberOrdered == 0)
     {
     strOutput = "<b><font face=\"Verdana\" size=\"2\" color=\"#000080\">"
                 + "<br><br>Your shopping cart is empty.<br><br></font></b>";
     document.write(strOutput);
     return;
     } 

   strOutput = "<TABLE CLASS=\"nopcart\" border=\"0\" cellspacing=\"10\" width=\"100%\" ><TR>" +
               "<TD CLASS=\"nopheader\" align=\"center\"><B>"+strILabel+"</B></TD>" +
               "<TD CLASS=\"nopheader\" align=\"center\"><B>"+strDLabel+"</B></TD>" +
               "<TD CLASS=\"nopheader\" align=\"center\"><B>"+strQLabel+"</B></TD>" +
               "<TD CLASS=\"nopheader\" align=\"center\"><B>"+strPLabel+"</B></TD>" +
               "<TD CLASS=\"nopheader\" align=\"center\"><B>"+strRLabel+"</B></TD></TR>";

   OrderNumber = GetInfo("HOrderNumber");
   CustomerName = GetInfo("HCustomerName");
   GiftMessage = GetInfo("HGiftMessage");
   LeadSource = GetInfo("HLeadSource");
   OtherSource = GetInfo("HOtherSource");
   ShipOvernight = "N";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "HOrder." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); // Additional Information


      if (fields[0] == "OVNT") 
        {
        ShipOvernight = "Y";
        }

      fExtPrice  = (parseInt(fields[1]) * parseFloat(fields[2]) );  // Extended price
      fTotal += fExtPrice;                                          // fTotal is running total of order
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      if (fields[0].substring(0, 1) != "T")                        
        {
        fTax     += (fExtPrice * TaxRate);    // It is a taxable item... add tax to running total
        }

      strOutput += "<TR><TD CLASS=\"nopentry\" align=\"center\">"  + fields[0] + "</TD>";

      if ( fields[5] == "" )
         strOutput += "<TD CLASS=\"nopentry\" align=\"left\">"  + fields[3] + "</TD>";
      else
         strOutput += "<TD CLASS=\"nopentry\" align=\"left\">"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

      strOutput += "<TD CLASS=\"nopentry\"  align=\"center\"><INPUT TYPE=\"TEXT\" NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\" style=\"font-family: Verdana; font-size: 8pt; text-align: center; border: 0\"></TD>";
      strOutput += "<TD CLASS=\"nopentry\" align=\"right\">"+ MonetarySymbol + moneyFormat(fields[2]) + "</TD>";
      strOutput += "<TD CLASS=\"nopheader\" align=\"center\"><input type=\"button\" value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" style=\"font-family: Verdana; font-size: 8pt\"></TD></TR>";

   }

   strTotal    = moneyFormat(fTotal);
   strTax      = moneyFormat(fTax);
      
   fShipping = 10.00;
   strShipping = moneyFormat(fShipping);          

   strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=RIGHT><font face=\"Verdana\" size=\"1\"><B>"+strSUB+"</B></TD>";
   strOutput += "<TD CLASS=\"noptotal\" align=\"right\"><font face=\"Verdana\" size=\"1\"><B>" + MonetarySymbol + strTotal + "</B></TD>";
   strOutput += "<TD CLASS=\"nopheader\">&nbsp</TD></TR>";

   strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=RIGHT><font face=\"Verdana\" size=\"1\"><B>"+strSHIP+"</B></TD>";
   strOutput += "<TD CLASS=\"noptotal\" align=\"right\"><font face=\"Verdana\" size=\"1\"><B>" + MonetarySymbol + strShipping + "</B></TD>";
   strOutput += "<TD CLASS=\"nopheader\">&nbsp</TD></TR>";

   strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=RIGHT><font face=\"Verdana\" size=\"1\"><B>"+strTOT+"</B></TD>";
   strOutput += "<TD CLASS=\"noptotal\" align=\"right\"><font face=\"Verdana\" size=\"1\"><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping)) + "</B></TD>";
   strOutput += "<TD CLASS=\"nopheader\">&nbsp</TD></TR>";

   g_TotalCost = (fTotal + fShipping);
   
   SetInfo("HTotal", moneyFormat(g_TotalCost), exp, "/");

   document.write(strOutput);
   
   strOutput = "<tr><td CLASS=\"nopheader\" colspan=\"5\" style=\"font-size: 2px\">&nbsp</td></tr>";
   strOutput += "<tr><td CLASS=\"nopheader\" align=\"center\" colspan=\"4\">";
   strOutput += "<form name=\"gwrap\"><input type=\"button\" style=\"font-family: Verdana; font-size: 8pt\"";
   if (CustomerName == null && GiftMessage == null) {
     // Gift card is blank
     strOutput += "value=\"Add Gift Card\"";
   } else {
     // Gift card already exists
     strOutput += "value=\"Edit Gift Card\"";
   }
   strOutput += " onclick=\'location=\"gift_card.php\"\'></form>";
   strOutput += "</td><td CLASS=\"nopheader\" align=\"center\"><form name=\"sover\"><input type=button name=\"startover\" style=\"font-family: Verdana; font-size: 8pt\" value=\"Empty Cart\" onclick=\'StartOver();location.href=location.href\'></form>";
   strOutput += "</td></tr></table>";
   document.write(strOutput);
   
   strOutput = "<table CLASS=\"nopcart\" border=0 cellspacing=10 width=\"100%\">";

   if (ShipOvernight == "N")
     {
     strOutput += "<tr><td CLASS=\"nopheader\" align=\"left\" width=\"70%\"><p style=\"margin-top: 0; margin-bottom: 8\">**A shipping charge for UPS Ground delivery is included. For overnight deliveries, there is an additional $35 charge.  ";
     strOutput += "(Not available on shipments to Hawaii or Canada.)  For a Saturday delivery, please call (888) 960-4325.</p>";
     strOutput += "</td><td CLASS=\"nopheader\" align=\"center\" width=\"30%\"><form name=\"order1\"><input type=button style=\"font-family: Verdana; font-size: 8pt; margin-top: 0; margin-bottom: 6\" value=\'Overnight Shipping\' onclick=\'AddToCart(this.form)\'>";
     strOutput += "<input type=hidden name=PRICE value=\"35.00\"><input type=hidden name=QUANTITY value=\"1\"><input type=hidden name=NAME value=\"Additional Charge For Overnight Shipping\">";
     strOutput += "<input type=hidden name=\"ID_NUM\" value=\"OVNT\"></form></td></tr>";
     }
   else
     {
     strOutput += "<tr><td CLASS=\"nopheader\" align=\"left\" colspan=\"2\">**The charge for overnight shipping is made in addition to the standard (UPS Ground) shipping charge.</td></tr>";
     }

   strOutput += "<FORM ACTION=\"https://www.healingbaskets.com/mobius/checkout.php\" METHOD=\"POST\" onsubmit=\"return ValidateCart(this)\">";


   // Need to do this loop again cuz we can't nest forms...

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "HOrder." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); // Additional Information

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }

   }

   strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
   strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
   strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
   strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping)) + "\">";

   CustomerName = GetInfo("HCustomerName");
   GiftMessage = GetInfo("HGiftMessage");
   LeadSource = GetInfo("HLeadSource");
   OtherSource = GetInfo("HOtherSource");
   LandingPage = GetInfo("HLandingPage");
   
   strOutput += "<input type=hidden name=\"CustomerName\" value=\"" + CustomerName + "\">";
   strOutput += "<input type=hidden name=\"GiftMessage\" value=\"" + escape(GiftMessage) + "\">";
   strOutput += "<input type=hidden name=\"LeadSource\" value=\"" + LeadSource + "\">";
   strOutput += "<input type=hidden name=\"OtherSource\" value=\"" + OtherSource + "\">";
   strOutput += "<input type=hidden name=\"LandingPage\" value=\"" + LandingPage + "\">";
   strOutput += "<input type=hidden name=\"CartURL\" value=\"" + location.href + "\">";

   strOutput += "<tr><td CLASS=\"nopheader\" align=\"center\">";
   strOutput += "<input type=button value=\"Continue Shopping\" onclick=\"ContinueShopping()\" style=\"font-family: Verdana; font-size: 8pt\"></td>";
   strOutput += "<td CLASS=\"nopheader\" align=\"center\">";
   strOutput += "<INPUT type=SUBMIT value=\"   Check Out   \" style=\"font-family: Verdana; font-size: 8pt\"></td></tr></FORM>";
   strOutput += "</table>";
   document.write(strOutput);
   
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    SaveGiftMessage                                        ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Saves the values of the message in a cookie            ||
//---------------------------------------------------------------------||
function SaveGiftMessage(thisForm) 
{
  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

  SetInfo("HCustomerName", thisForm.Name.value, exp, "/");
  SetInfo("HGiftMessage", thisForm.Message.value, exp, "/");
  if (thisForm.Google.checked == true)
    {
    SetInfo("HLeadSource", "Google", exp, "/");
    }
  else
    {
    if (thisForm.Yahoo.checked == true)
      {
      SetInfo("HLeadSource", "Yahoo", exp, "/");
      }
    else
      {
      if (thisForm.Friend.checked == true)
        {
        SetInfo("HLeadSource", "Friend", exp, "/");
        }
      else
        {
        if (thisForm.Press.checked == true)
          {
          SetInfo("HLeadSource", "Press", exp, "/");
          }
        else
          {
          if (thisForm.Radio.checked == true)
           {
           SetInfo("HLeadSource", "Radio", exp, "/");
           }
          else
            {
            SetInfo("HLeadSource", "Other", exp, "/");
            }
          }
        }
      }
    }
  if (thisForm.OtherText.value == null)
    {
    thisForm.OtherText.value = " ";
    }

  SetInfo("HOtherSource", thisForm.OtherText.value, exp, "/");

  location = "mb_cart.php"

}

//---------------------------------------------------------------------||
// FUNCTION:    GetGiftMessage                                         ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves the gift tag message if it exists, and puts  ||
//              it in a field in the current form.                     ||
//---------------------------------------------------------------------||
function GetGiftMessage() 
{

  giftMessage = GetInfo("HGiftMessage");

   if (giftMessage == null)
     {
     WhatToWrite = "<textarea cols=40 rows=5 name=\"Message\" style=\"font-family: Verdana; font-size: 8pt\""
                 + " onKeyDown=\"textCounter(this.form.Message,this.form.remLen,240);\""
                 + " onKeyUp=\"textCounter(this.form.Message,this.form.remLen,240);\""
                 + "></textarea>";
     remainingChars = 240;
     }
   else
     {
     WhatToWrite = "<textarea cols=40 rows=5 name=\"Message\" style=\"font-family: Verdana; font-size: 8pt\""
                 + " onKeyDown=\"textCounter(this.form.Message,this.form.remLen,240);\""
                 + " onKeyUp=\"textCounter(this.form.Message,this.form.remLen,240);\""
                 + ">" + giftMessage + "</textarea>";
     remainingChars = 240 - giftMessage.length;
     }

  WhatToWrite += "<input readonly type=text name=remLen size=3 maxlength=3"
               + " style=\"font-family: Verdana; font-size: 8pt\""
               + " value=\"" + remainingChars + "\"> characters left";

  document.write(WhatToWrite);
}

//---------------------------------------------------------------------||
// FUNCTION:    GetCustomerName                                        ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves the customer name if it exists, and puts it  ||
//              in a field in the current form.                        ||
//---------------------------------------------------------------------||
function GetCustomerName() 
{

  CustomerName = GetInfo("HCustomerName");
  if (CustomerName == null)
    {
    WhatToWrite = "<input type=\"text\" name=\"Name\" size=25 style=\"font-family: Verdana; font-size: 8pt\">";
    }
  else
    {
    WhatToWrite = "<input type=\"text\" name=\"Name\" size=25 style=\"font-family: Verdana; font-size: 8pt\" value=\"" + CustomerName + "\">";
    }

  document.write(WhatToWrite);
}

//---------------------------------------------------------------------||
// FUNCTION:    textCounter                                            ||
// PARAMETERS:  fieldname, countfieldname, max # characters            ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Limits the number of characters in the field to the    ||
//              number specified in maxlimit, and updates the remaining||
//              character count in countfield.                         ||
//---------------------------------------------------------------------||

function textCounter(field, countfield, maxlimit) 
{
  if (field.value.length > maxlimit)          // if too long...trim it!
    {
    field.value = field.value.substring(0, maxlimit);
    }
  // otherwise, update 'characters left' counter
  else 
    {
    countfield.value = maxlimit - field.value.length;
    }
}


//---------------------------------------------------------------------||
// FUNCTION:    xxxxClick, where xxxx = name of radion button          ||
// PARAMETERS:  This Form                                              ||
// RETURNS:     Null                                                   ||
// PURPOSE:     When a radio button is clicked, clear the other buttons||
//---------------------------------------------------------------------||
function GoogleClick(thisForm)
{

  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function YahooClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function FriendClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function PressClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function RadioClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function FindGiftClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function UnityClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Other.checked = false;
  thisForm.OtherText.value = "";
}
function OtherClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
}
function OtherTextClick(thisForm)
{
  thisForm.Google.checked = false;
  thisForm.Yahoo.checked = false;
  thisForm.Friend.checked = false;
  thisForm.Press.checked = false;
  thisForm.Radio.checked = false;
  thisForm.FindGift.checked = false;
  thisForm.Unity.checked = false;
  thisForm.Other.checked = true;
}

//---------------------------------------------------------------------||
// FUNCTION:    GetLeadSource                                          ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves the lead source if it exists, and puts it    ||
//              in a field in the current form.                        ||
//---------------------------------------------------------------------||
function GetLeadSource() 
{

  LeadSource = GetInfo("HLeadSource");
  OtherSource = GetInfo("HOtherSource");

  if (OtherSource == null || OtherSource == "undefined")
    {
    OtherSource = " ";
    }

  if (LeadSource == null)
    {
    WhatToWrite = "<input type=radio name=\"Google\" onclick=\'GoogleClick(this.form)\'>Google<br>"
                + "<input type=radio name=\"Yahoo\" onclick=\'YahooClick(this.form)\'>Yahoo<br>"
                + "<input type=radio name=\"Friend\" onclick=\'FriendClick(this.form)\'>From a friend<br>"
                + "<input type=radio name=\"Press\" onclick=\'PressClick(this.form)\'>Newspaper/magazine article<br>"
                + "<input type=radio name=\"Radio\" onclick=\'RadioClick(this.form)\'>Radio Commercial<br>"
                + "<input type=radio name=\"FindGift\" onclick=\'FindGiftClick(this.form)\'>FindGift.com<br>"
                + "<input type=radio name=\"Unity\" onclick=\'UnityClick(this.form)\'>Unity<br>"
                + "<input type=radio name=\"Other\" checked onclick=\'OtherClick(this.form)\'>Other:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"    
                + "<input type=text name=\"OtherText\" size=25 style=\"font-family: Verdana; font-size: 8pt\" onclick=\'OtherTextClick(this.form)\'><br>";
    }
  else
    {
    WhatToWrite = "<input type=radio name=\"Google\"";

    if (LeadSource == "Google")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'GoogleClick(this.form)\'>Google<br><input type=radio name=\"Yahoo\"";
    if (LeadSource == "Yahoo")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'YahooClick(this.form)\'>Yahoo<br><input type=radio name=\"Friend\"";
    if (LeadSource == "Friend")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'FriendClick(this.form)\'>From a friend<br><input type=radio name=\"Press\"";
    if (LeadSource == "Press")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'PressClick(this.form)\'>Newspaper/magazine article<br><input type=radio name=\"Radio\"";
    if (LeadSource == "Radio")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'RadioClick(this.form)\'>Radio Commercial<br><input type=radio name=\"FindGift\"";
    if (LeadSource == "FindGift")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'FindGiftClick(this.form)\'>FindGift.com<br><input type=radio name=\"Unity\"";
    if (LeadSource == "Unity")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'UnityClick(this.form)\'>Unity<br><input type=radio name=\"Other\"";
    if (LeadSource == "Other")
      {
      WhatToWrite += " checked ";
      }
    WhatToWrite += " onclick=\'OtherClick(this.form)\'>Other:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    WhatToWrite += "<input type=text name=\"OtherText\" size=25 style=\"font-family: Verdana; font-size: 8pt\" onclick=\'OtherTextClick(this.form)\' ";
    if (OtherSource != null)
      {
      WhatToWrite += " value=\"" + OtherSource + "\"";
      }
    WhatToWrite += "><br>";
    
    }

  document.write(WhatToWrite);
}

//---------------------------------------------------------------------||
// FUNCTION:    GetOrderNumber                                         ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves the current order number and puts it in a    ||
//              hidden field in the current form.                      ||
//---------------------------------------------------------------------||
function GetOrderNumber() 
{

  OrderNumber = GetInfo("HOrderNumber");
  WhatToWrite = "<input type=\"hidden\" name=\"OrderNumber\" value=\"" + OrderNumber + "\">";
  document.write(WhatToWrite);
}

//---------------------------------------------------------------------||
// FUNCTION:    DisplayOrderNumber                                     ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves the current order number and displays it on  ||
//              the current page.                                      ||
//---------------------------------------------------------------------||
function DisplayOrderNumber() 
{

  OrderNumber = GetInfo("HOrderNumber");
  WhatToWrite = "Order Number: " + OrderNumber;
  document.write(WhatToWrite);
}

//---------------------------------------------------------------------||
// FUNCTION:    AddGiftWrap                                            ||
// PARAMETERS:  Current Form Object                                    ||
// RETURNS:     null                                                   ||
// PURPOSE:     Adds $4.95 gift wrap to cart                           ||
//---------------------------------------------------------------------||

function AddGiftWrap(thisForm)
{

  thisForm.ID_NUM.value = "WRAP";
  thisForm.QUANTITY.value = "1";
  thisForm.PRICE.value = "4.95";
  thisForm.NAME.value = "Gift Wrap";
  AddToCart(thisForm);
  location.href = location.href;

}


//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalCost < MinimumOrder ) {
         alert( MinimumOrderPrompt );
         return false;
      }
   }

  iNumberContainers = 0;
  iNumberOrdered = 0;

  CustomerName = GetInfo("HCustomerName");
  GiftMessage = GetInfo("HGiftMessage");

  if (CustomerName == null && GiftMessage == null)
    {
    // No gift card selected - check that this was intentional

    if (!confirm("You didn't add a gift card to your order (it's free!). If that's what you meant, click 'OK'.  "
                + "Otherwise, click 'Cancel' to enter a message for your gift."))
        {
        location = "gift_card.php"
        return(false);
        }
    }

    iNumberOrdered = GetInfo("HNumberOrdered");
        
    if ( iNumberOrdered == null )
      {
      iNumberOrdered = 0;
      }

    return(true);
}

//---------------------------------------------------------------------||
// FUNCTION:    SavePageURL                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Saves URL of current page in a cookie for future use.  ||
//---------------------------------------------------------------------||

function SavePageURL()
{
  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

  
    SetInfo("HPageURL", location.href, exp, "/");

}

//---------------------------------------------------------------------||
// FUNCTION:    GetPageURL                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Retrieves URL of saved page from a cookie.             ||
//---------------------------------------------------------------------||

function GetPageURL()
{

    PageURL = GetInfo("HPageURL");
    if (PageURL == null)
      {
      PageURL = "/";
      }
    OrderNumber = GetInfo("HOrderNumber");
    WhatToWrite = "<input type=\"hidden\" name=\"Reference\" value=\"";
    WhatToWrite += PageURL;
    WhatToWrite += "\">";
    WhatToWrite += "<input type=\"hidden\" name=\"return_link_url\" value=\"";
    WhatToWrite += PageURL;
    WhatToWrite += "\">";
    if (OrderNumber != null)
      {
      WhatToWrite += "<input type=\"hidden\" name=\"OrderNumber\" value=\"";
      WhatToWrite += OrderNumber;
      WhatToWrite += "\">";
      }

    document.write(WhatToWrite);

}

//---------------------------------------------------------------------||
// FUNCTION:    ContinueShopping                                       ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Navigates to page stored in HBContinueShopping cookie. ||
//---------------------------------------------------------------------||

function ContinueShopping()
{

    PageURL = GetInfo("MBContinueShopping");

    if (PageURL == null)
      {
      PageURL = "index.html";
      }

    location = PageURL;

}



//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||



