//=====================================================================||
//               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.          ||
//  For example: <SCRIPT SRC="language-en.js"></SCRIPT>                ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping 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                      ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable.                                            ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.                                       ||
// * 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:                           ||
//    * PayPal     (pp)
//                                                                     ||
// 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.                               ||
// * 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  ||
//---------------------------------------------------------------------||

// Constants 
MonetarySymbol        = '$';
TaxRate               = 0.095;
TaxPrompt             = 'For tax purposes, please select if you are a Washington resident before continuing';
TaxablePrompt         = 'Washington';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 0.01;
MinimumOrderPrompt    = 'Your order is below our minimum amount; please order more before checking out.';
OutputItemId          = 'ID_';
OutputItemQuantity    = 'QUANTITY_';
OutputItemPrice       = 'PRICE_';
OutputItemType        = 'TYPE_';
OutputItemName        = 'NAME_';
OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'SHIPPING';
OutputOrderTax        = 'TAX';
OutputOrderTotal      = 'TOTAL';

//Payment Processor Options:
PaymentProcessor      = '';
strPayPal             = "pp";
HiddenFieldsToCheckout = false;

// Cookie Strings 
database = "";
Token0 = 0;
Token1 = 0;
Token2 = 0;
Token3 = 0;
Token4 = 0;
Token5 = 0;
Token6 = 0;

fields = new Array;
fields [0] = "1";
fields [1] = "1";
fields [2] = "1";
fields [3] = "1";
fields [4] = "1";
fields [5] = "1";
fields [6] = "1";

strItemID       = "";
strItemName     = "";
fQty            = "";
fBasePrice      = "";
fComputedPrice  = "";
strType         = "";
strFType        = "";

g_TotalCost = 0;


//---------------------------------------------------------------------||
//                      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.                                                      ||
//---------------------------------------------------------------------||

if ( !bLanguageDefined ) {
   strSorry    = "I'm Sorry, your cart is full, please proceed to checkout.";
   strAdded    = " added to your shopping cart.";
   strRemove   = "Click 'Ok' to remove this product from your shopping cart.";
   strILabel   = "Id";
   strNLabel   = "Name";
   strDLabel   = "Description";
   strQLabel   = "Quantity";
   strPLabel   = "Price";
   strSLabel   = "Shipping (3.9%)";
   strSTLabel  = "Item Total";
   strRLabel   = "Update Quantity";
   strRButton  = "Update";
   strDButton  = "Delete All";
   strSUB      = "SUBTOTAL";
   strSHIP     = "SHIPPING (3.9%)";
   strTAX      = "TAX";
   strTOT      = "TOTAL";
   strErrQty   = "Invalid Quantity.";
   strNewQty   = 'Please enter new quantity:';
   bLanguageDefined = true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//---------------------------------------------------------------------||
// 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:    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:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
  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:    numberFormat                                           ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats number to indicated size, right justify,     || 
//               space fill                                            ||
//---------------------------------------------------------------------||
function numberFormat(input, size) {

  var num = parseInt(input);
  var tmp = new String(input);

  strJustified = "";

//     width of field defaults to 4
  if (isNaN(size)) 
    size = 4;

  for (m = size-1; m > 0; m--) {
    strJustified = "0" + strJustified;
  }

  strJustified =   strJustified  + tmp.slice(1);
  return (strJustified);
}

//---------------------------------------------------------------------||
// FUNCTION:    ExtractCookieFields                                    ||
// PARAMETERS:  Cookie name                                            ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function ExtractCookieFields() {

  Token0 = database.indexOf("|", 0);
  Token1 = database.indexOf("|", Token0+1);
  Token2 = database.indexOf("|", Token1+1);
  Token3 = database.indexOf("|", Token2+1);
  Token4 = database.indexOf("|", Token3+1);
  Token5 = database.indexOf("|", Token4+1);
  Token6 = database.indexOf("|", Token5+1);


    // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
    // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType
  fields[0] = database.substring( 0, Token0 );                 // Product ID
  fields[1] = database.substring( Token0+1, Token1 );          // Name
  fields[2] = database.substring( Token1+1, Token2 );          // Quantity
  fields[3] = database.substring( Token2+1, Token3 );          // Price
  fields[4] = database.substring( Token3+1, Token4 );          // Recomputed Price
  fields[5] = database.substring( Token4+1, Token5 );          // strType
  fields[6] = database.substring( Token5+1, database.length ); // strFType

  strItemID       = fields[0];
  strItemName     = fields[1];
  fQty            = fields[2];
  fBasePrice      = fields[3];
  fComputedPrice  = fields[4];
  strType         = fields[5];
  strFType        = fields[6];

}

//---------------------------------------------------------------------||
// 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:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {

  if ( isNaN(NewQuantity) ) {
    alert( strErrQty );
  } else {
    NewOrder = "Order." + OrderItem;
    database = "";
    database = GetCookie(NewOrder);

    // fields are: ID, name, qty, price, baseprice, strType, strFType
    // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType
    ExtractCookieFields();

    dbUpdatedOrder = strItemID + "|" +
                     strItemName + "|" +
                     NewQuantity + "|" +
                     fBasePrice + "|" +
                     fComputedPrice + "|" +
                     strType + "|" +
                     strFType ;

    strNewOrder = "Order." + OrderItem;
    DeleteCookie(strNewOrder, "/");
    SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
    location.href=location.href;      
  }
}

//---------------------------------------------------------------------||
// FUNCTION:    ProcessAutoPayment                                     ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Calls online payment processor                         ||
//---------------------------------------------------------------------||
function ProcessAutoPayment(OrderItem,NewQuantity) {
strPage = "https://www.sandbox.paypal.com/cgi-bin/webscr/";
  alert ("autopayment");
  alert(location.search);

 // location.assign("https://www.sandbox.paypal.com/cgi-bin/webscr/");
   window.location.assign("https://www.sandbox.paypal.com/cgi-bin/webscr/");
   location.assign("https://www.sandbox.paypal.com/cgi-bin/webscr/");
//   window.location.assign("http://www.example.com");
  alert ("autopayment 2");
}

//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart() {
  var iNumberOrdered = 0;
  var iNewNumber = 0;
  var CookieNumber = 1;
  var bCookieRetrieved = false;

  iNumberOrdered = GetCookie("NumberOrdered");
  if ( iNumberOrdered == null )
    iNumberOrdered = 0;

  NewOrderLastNumber    = iNumberOrdered;
  
  CookieIndex = 1;
  
  NewOrderNextNumber = 1;

  NewOrderCurrentNumber = 1;
  NewOrderCurrent = "Order." + NewOrderCurrentNumber;

  database = "";
  database = GetCookie(NewOrderCurrent);

  while (database == null) {
    NewOrderCurrentNumber++;
    NewOrderCurrent = "Order." + NewOrderCurrentNumber;
    database = GetCookie(NewOrderCurrent);
  }  // while (database == null) 

  while (database != null) {
    // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
    // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType

    ExtractCookieFields();
 
    if (fQty == "0") {
      if (confirm(strItemName + " has a quantity of zero. " + strRemove ) ) {
        DeleteCookie(NewOrderCurrent, "/");
        iNewNumber++;

        NewOrderNextNumber =  NewOrderCurrentNumber + 1;
        NewOrderNext    = "Order." +   NewOrderNextNumber ;
        n = NewOrderNextNumber;
        database2 = GetCookie(NewOrderNext);

          while ((database2==null) && (n <= NewOrderLastNumber)) {
          NewOrderNextNumber++;
          n++;
          NewOrderNext    = "Order." +   NewOrderNextNumber ;
          database2 = GetCookie(NewOrderNext);
        }  // while ((database2==null) && (n <= NewOrderLastNumber)) 

        if (database2 != null) {
          CookieIndex = NewOrderNextNumber - iNewNumber;
          NewOrderCookieIndex = "Order." + CookieIndex;
          DeleteCookie(NewOrderNext, "/");
          SetCookie (NewOrderCurrent, database2, null, "/");
        }
      }    // if confirm
    } else  {

    if  ( NewOrderCurrentNumber >  CookieIndex) {
//  cookie number not contiguous; rewrite with contiguous cookie number
        NewOrderNextNumber =  NewOrderCurrentNumber;
        NewOrderNext    = "Order." +   NewOrderNextNumber ;
        DeleteCookie(NewOrderNext, "/");
        NewOrderCookieIndex = "Order." + CookieIndex;
        SetCookie (NewOrderCookieIndex, database, null, "/");
    }
        CookieIndex++;
       NewOrderCurrentNumber+=1;
    }      // if fQty

    NewOrderCurrent    = "Order." +   NewOrderCurrentNumber;
    database = GetCookie(NewOrderCurrent);

    i = NewOrderCurrentNumber;

    while ((database == null)  && (i <= iNumberOrdered)) {

      NewOrderCurrentNumber++;
      i++;
      NewOrderCurrent    = "Order." +   NewOrderCurrentNumber;
      database = GetCookie(NewOrderCurrent);
    } // while (database == null)

  }        // while (database != null)
 
  iNumberOrdered -= iNewNumber;
  if (iNumberOrdered >=1 )
    SetCookie ("NumberOrdered",  iNumberOrdered, null, "/");
  else
     DeleteCookie("NumberOrdered", "/");

  location.href=location.href;
}

//---------------------------------------------------------------------||
// FUNCTION:    DeleteCart                                             ||
// PARAMETERS:  N/A                                                    ||
// RETURNS:     void                                                   ||
// PURPOSE:     Deletes contents of shopping cart                      ||
//---------------------------------------------------------------------||
function DeleteCart( theForm ) {
  var iNumberOrdered = 0;

  iNumberOrdered = GetCookie("NumberOrdered");

  if ( iNumberOrdered == null )
    iNumberOrdered = 0;
  if (confirm(" Delete all entries in the cart?") ) {
    for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);
      DeleteCookie(NewOrder, "/");
    }  // for
    DeleteCookie("NumberOrdered", "/");
  }

  location.href=location.href;
}

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
function ValidateCart( theForm ) {

  if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
    alert( TaxPrompt );
    return false;
  }

  if ( MinimumOrder >= 0.01 ) {
    if ( g_TotalCost < MinimumOrder ) {
      alert( MinimumOrderPrompt );
       return false;
    }
  }

  return true;
}

//---------------------------------------------------------------------||
// 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 = "";
  iNumberOrdered = GetCookie("NumberOrdered");

  if ( iNumberOrdered == null )
    iNumberOrdered = 0;

  if ( thisForm.ItemSelect1 == null ) {
    strAddIdNumber = "";
    strAddItemName = "" ;
  } else {
    SelectOptionsCollection = thisForm.ItemSelect1; //htmlSelectElement
    idx = SelectOptionsCollection.selectedIndex;
    strAddIdNumber = SelectOptionsCollection.item(idx).id;
    strAddItemName = SelectOptionsCollection.item(idx).value;
  }

  if ( thisForm.PRICE == null )
    strAddPrice = 0;
  else 
    strAddPrice = parseFloat(thisForm.PRICE.value);

  strAddComputedPrice =  strAddPrice;
  strAddType = "Card";

  if ( thisForm.ItemSelect2 == null )
    strAddItemSize = "ArtSize1";
  else
    strAddItemSize = thisForm.ItemSelect2.value;

//  strAddItemSize may have the value "Reserved", in which case no changes are made
    if (strAddItemSize == "ArtSize2" ) {
      strAddComputedPrice *= 2;
      strAddType = "5 by 7 Photograph";
    } else if ( strAddItemSize == "ArtSize3" ) {
      strAddComputedPrice *= 3; 
      strAddType = "8 by 10 Photograph";
    } else if ( strAddItemSize == "EducSize1" ) {
      strAddType = "Full Article";
    } else if ( strAddItemSize == "EducSize2" ) {
      strAddComputedPrice /= 5; 
      strAddType = "Article Summary";
    }  // no special sizes from music cart at this time

   strAddFType = "Matte Finish";

   if (thisForm.ItemSelect3 == null )
    strAddItemFinish = "ArtFinish1";
  else
    strAddItemFinish = thisForm.ItemSelect3.value;

//  strAddItemFinish may have the value "Reserved", in which case no changes are made

    if (strAddItemFinish == "ArtFinish2" ) {
      strAddComputedPrice += 0.5;
      strAddFType = "Glossy Finish";
    } // no special finishes from music cart at this time

  if ( thisForm.QUANTITY == null )
    strAddQuantity = "1";
  else
    strAddQuantity = thisForm.QUANTITY.value;

  if ( thisForm.cmd == null )
    strcmd    = "";
  else
    strcmd    = thisForm.cmd.value;

  if ( thisForm.hosted_button_id == null )
    strhosted_button_id  = "1";
  else
    strhosted_button_id  = thisForm.hosted_button_id.value;

  if ( thisForm.currency_code == null )
    strcurrency_code     = "0.00";
  else
    strcurrency_code     = thisForm.currency_code.value;

  if (strAddQuantity== "0")  {
    notice =    strErrQty;
  } else {

     // Is this product already in the cart?  If so, increment quantity instead of adding another.
     // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
     // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType

    for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      ExtractCookieFields();

      if ( strItemID  == strAddIdNumber &&
           fBasePrice  == strAddPrice  &&
           fComputedPrice == strAddComputedPrice  &&
           strType == strAddType &&
           strFType == strAddFType) {

        bAlreadyInCart = true;

     // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
     // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType
        dbUpdatedOrder =   strItemID + "|" + strItemName + "|";
        dbUpdatedOrder += (parseInt(strAddQuantity) + parseInt(fQty))  + "|";
        dbUpdatedOrder += fBasePrice  + "|" +  fComputedPrice + "|" + strType + "|" + strFType ;
        strNewOrder = "Order." + i;
        DeleteCookie(strNewOrder, "/");
        SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
        notice = strAddQuantity+ " " + strAdded;
        break;
      }
    }  // for 

    if ( !bAlreadyInCart ) {

      iNumberOrdered++;

      if ( iNumberOrdered > 12 )
        notice = strSorry;
      else {
        dbUpdatedOrder  = strAddIdNumber + "|" + strAddItemName     + "|" + strAddQuantity + "|";
        dbUpdatedOrder += strAddPrice  + "|" + strAddComputedPrice  + "|" + strAddType + "|";
        dbUpdatedOrder += strAddFType ;
     // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
     // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType
 
        strNewOrder = "Order." + iNumberOrdered;
        SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
        SetCookie("NumberOrdered", iNumberOrdered, null, "/");
        notice = strAddQuantity + " " + strAddItemName + strAdded;
      } // else
    }   // not already in cart
  }  // qty not zero

  alert(notice);
}

//---------------------------------------------------------------------||
// 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 fTax           = 0;    //Tax amount
  var fShipping      = 0;    //Shipping amount
  var strTotal       = "";   //Total cost formatted as money
  var strfTax        = "";   //Total tax formatted as money
  var strShipping    = "";   //Total shipping formatted as money
  var strOutput      = "";   //String to be written to page

  iNumberOrdered = GetCookie("NumberOrdered");
  if ( iNumberOrdered == null )
    iNumberOrdered = 0;

   strOutput  = "<TABLE CLASS=\"nopcart\" align=\"center\">";

//                 no items in cart, which differs from item in cart with zero quantity
  if ( iNumberOrdered == 0 ) {
    strOutput += "<TR><TD COLSPAN=6 CLASS=\"nopentry\" border-width=0><CENTER><BR>Your cart is ";
    strOutput += "empty<BR><br></CENTER></TD></TR>";
  } else {
    strOutput += "<TR><TD COLSPAN=6 CLASS=\"nopentry\" border-width=0><CENTER><BR>To update your purchase, ";
    strOutput += "change the quantity.";  
    strOutput += "<br>To remove items, change quantities to zero, then select the " + strRButton + " button.";
    strOutput += "<br>To delete everything in your cart, select the " + strDButton + "   button.";
    strOutput += "<br>To pay by check, select the Checkout button.";
//    strOutput += "<br>To pay via Paypal, select the Buy Now button.";
    strOutput += "<br>The Paypal Buy Now button is under construction.";
    strOutput += "<BR><BR></CENTER></TD></TR>";
  }

    strOutput += "<TR><TD CLASS=\"nopheader\"><B>"+strILabel+"</B></TD>" +
                 "<TD CLASS=\"nopheader\"><B>"+strNLabel+"</B></TD>" +
                 "<TD CLASS=\"nopheader\"><B>"+strDLabel+"</B></TD>" +
                 "<TD CLASS=\"nopheader\"><B>"+strQLabel+"</B></TD>" +
                 "<TD CLASS=\"nopheader\"><B>"+strPLabel+"</B></TD>" +
                 "<TD CLASS=\"nopheader\"><B>"+strSTLabel+"</B></TD>" +
                 "</TR>";

  for ( i = 1; i <= iNumberOrdered; i++ ) {
    NewOrder = "Order." + i;
    database = "";
    database = GetCookie(NewOrder);

    ExtractCookieFields();

    // fields are: ID, name, qty, BasePrice,ComputedPrice, strType, strFType
    // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType



    fTotal         += fQty  * fComputedPrice;

    fShipping       = fTotal  * .039;
    fTax            = fTotal * TaxRate;
    strItemTotal    = fQty * fComputedPrice;
    strTotal        = moneyFormat(fTotal);

    if (fTax == "0")
      strfTax        = "0.00";
    else 
      strfTax        = moneyFormat(fTax);

    strShipping = moneyFormat(fShipping);

    strOutput += "<TR><TD CLASS=\"nopentry\">"  +  strItemID  + "</TD>";
    strOutput += "<TD CLASS=\"nopentry\">"  + strItemName + "</TD>";
    strOutput += "<TD CLASS=\"nopentry\">" +  strType + " - <I>" + strFType + "</I></TD>";
    strOutput += "<TD CLASS=\"nopentry\"><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[2] + "\" ";
    strOutput += "onChange=\"ChangeQuantity(" + i + ", this.value)\"></TD>";
    strOutput += "<TD CLASS=\"nopentry\">" + MonetarySymbol + moneyFormat(fComputedPrice) + "/ea</TD>";
    strOutput += "<TD CLASS=\"nopentry\">" + MonetarySymbol + moneyFormat(strItemTotal) +"</TD>";
    strOutput += "</TR>";

 }  // for

  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strSUB+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B>" + MonetarySymbol + strTotal + "</B></TD>";
  strOutput += "</TR>";

//shipping row
  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strSHIP+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B>" + MonetarySymbol + strShipping + "</B></TD>";
  strOutput += "</TR>";

//tax row
  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strTAX+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B>";
  strOutput += "<input type=radio name=\""+OutputOrderTax+ "\" value=\"" + strfTax + "\">";
  strOutput += TaxablePrompt + ": " + MonetarySymbol + strfTax;
  strOutput += "<BR><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
  strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
  strOutput += "</B></TD>";
  strOutput += "</TR>";

//tax region
  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strTOT+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax));
  strOutput += "</B></TD>";
  strOutput += "</TR>";

  g_TotalCost = fTotal + fShipping + fTax;

  strOutput += "<TR><TD COLSPAN=2><CENTER>";
  strOutput += "<input type=button value=\" "+strRButton+" \"  ";
  strOutput += "onClick=\"RemoveFromCart()\" ";
  strOutput += ">";
  strOutput += "</CENTER></TD>";
  strOutput += "<TD><CENTER>";
  strOutput += "<input type=button value=\" "+strDButton+" \"  ";
  strOutput += "onClick=\"DeleteCart()\" ";
  strOutput += ">";
  strOutput += "</CENTER></TD>";
  strOutput += "<TD COLSPAN=2><CENTER>";
  strOutput += "<INPUT TYPE=IMAGE SRC=\"_derived/checkout_p.gif\" BORDER=0 name=\"btn_Checkout\" ";
  strOutput += " onMouseOut=\"MM_swapImgRestore()\" ";
  strOutput += " onMouseOver=\"MM_swapImage('btn_Checkout','','_derived/checkout_a.gif',1)\" ";
  strOutput += " >";
  strOutput += "</CENTER></TD>";
  strOutput += "<TD><CENTER>";
  strOutput += "<input type=image src=\"../images/btn_buynowCC_LG.gif\" border=1 valign=\"center\" ";
  strOutput += "name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\" ";
  strOutput += "onClick=\"ProcessAutoPayment()\" ";
  strOutput += " >";
  strOutput += "</CENTER></TD></TR>";
  strOutput += "<TR><TD COLSPAN=2><CENTER>";
  strOutput += " test row<br>";
  strOutput += "<input type=\"hidden\" name=\"cmd\" value=\"_s-xclick\"> ";
  strOutput += "<input type=\"hidden\" name=\"hosted_button_id\" value=\"TJH24JNTAMK86\"> ";
  strOutput += "<input type=hidden name=\"currency_code\" value=\"USD\">  ";
  strOutput += "<input type=image src=\"../images/btn_buynowCC_LG.gif\" border=1 valign=\"center\" ";
//  strOutput += "border=0 name=\"submit\" alt=\"PayPal\">  ";
//  strOutput += "<input type=hidden name=\"business\" value=\"PTBOrm_1280877929_per@ormer.net\">  ";
  strOutput += "onClick=\"ProcessAutoPayment()\" ";
  strOutput += " >";
  strOutput += "</CENTER></TD></TR>";

  strOutput += "</table>";
  document.write(strOutput);
  document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckoutCart                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutCart( ) {
  var iNumberOrdered = 0;    //Number of products ordered
  var fTotal         = 0;    //Total cost of order
  var fTax           = 0;    //Tax amount
  var fShipping      = 0;    //Shipping amount
  var fCartTotal     = 0;
  var strTotal       = "";   //Total cost formatted as money
  var strfTax        = "";   //Total tax formatted as money
  var strShipping    = "";   //Total shipping formatted as money
  var strOutput      = "";   //String to be written to page
  var bDisplay       = true; //Whether to write string to the page (here for programmers)
  var strPP          = "";   //Payment Processor Description Field

  iNumberOrdered = GetCookie("NumberOrdered");
  if ( iNumberOrdered == null )
    iNumberOrdered = 0;

  QueryString_Parse();
  fTax = parseFloat( QueryString( OutputOrderTax ) );
  strfTax = moneyFormat(fTax);

  strOutput = "<TABLE CLASS=\"nopcart\"><TR>" +
   
           "<TD CLASS=\"nopheader\"><B>"+strILabel+"</B></TD>" +
              "<TD CLASS=\"nopheader\"><B>"+strNLabel+"</B></TD>" +
              "<TD CLASS=\"nopheader\"><B>"+strDLabel+"</B></TD>" +
              "<TD CLASS=\"nopheader\"><B>"+strQLabel+"</B></TD>" +
              "<TD CLASS=\"nopheader\"><B>"+strPLabel+"</B></TD>" +
              "<TD CLASS=\"nopheader\"><B>"+strSTLabel+"</B></TD>" +
              "</TR>";

    // fields are: ID, name, qty, baseprice,itemprice, strType, strFType
    // fields are: strItemID, strItemName, fQty, fBasePrice, fComputedPrice, strType, strFType
 
  for ( i = 1; i <= iNumberOrdered; i++ ) {
    NewOrder = "Order." + i;
    database = "";
    database = GetCookie(NewOrder);

    ExtractCookieFields();
 
    strItemTotal  = fQty * fComputedPrice;
    fTotal       += strItemTotal;

    fShipping     = fTotal  * .039;
    strShipping   = moneyFormat(fShipping);

    strTotal      = moneyFormat(fTotal);
    
    fTax = (fTotal * TaxRate);
    strfTax = moneyFormat(fTax);

    strOutput += "<TR><TD CLASS=\"nopentry\">"  + strItemID;
    strOutput += "<input type=\"hidden\" name=\" " + OutputItemId  + i     + "\" ";
    strOutput += " value=\" " + strItemID    + "\" ";
    strOutput += "></TD>";

    strOutput += "<TD CLASS=\"nopentry\">"  + strItemName;
    strOutput += "<input type=\"hidden\" name=\" " + OutputItemName  + i   + "\" ";
    strOutput += " value=\" " + strItemName  + "\" ";
    strOutput += "></TD>";

    strOutput += "<TD CLASS=\"nopentry\">"  + strType + " " +   strFType + " ";
    strOutput += "<input type=\"hidden\" name=\" " + OutputItemType  + i    + "\" ";
    strOutput += " value=\" " + strType + " " +   strFType + "\" ";
    strOutput += "></TD>";
 
    strOutput += "<TD CLASS=\"nopentry\">" + fQty;
    strOutput += "<input type=\"hidden\" name=\" " + OutputItemQuantity + i + "\" ";
    strOutput += " value=\" " + fQty         + "\" ";
    strOutput += "></TD>";

    strOutput += "<TD CLASS=\"nopentry\" ALIGN=RIGHT>" + MonetarySymbol + moneyFormat(fComputedPrice) + "/ea </TD>";
    strOutput += "<TD CLASS=\"nopentry\" ALIGN=RIGHT>" + MonetarySymbol + moneyFormat(strItemTotal);
    strOutput += "<input type=\"hidden\" name=\" " + OutputItemPrice + i + "\" ";
    strOutput += " value=\" " + strItemTotal  + "\" ";
    strOutput += "></TD>";

    strOutput += "</TR>";

  }  // for

  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strSUB+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strTotal + "</B>";
  strOutput += "<input type=\"hidden\" name=\" " + OutputOrderSubtotal  + "\" ";
  strOutput += " value=\" " + strTotal  + "\" ";
  strOutput += "></TD>";
  strOutput += "</TR>";

  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strSHIP+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strShipping + "</B>";
  strOutput += "<input type=\"hidden\" name=\" " + OutputOrderShipping  + "\" ";
  strOutput += " value=\" " + strShipping + "\" ";
  strOutput += "></TD>";
  strOutput += "</TR>";

  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strTAX+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strfTax + "</B>";
  strOutput += "<input type=\"hidden\" name=\" " + OutputOrderTax   + "\" ";
  strOutput += " value=\" " + strfTax + "\" ";
  strOutput += "></TD>";
  strOutput += "</TR>";

  fCartTotal  =   fTotal + fShipping + fTax;  
  strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strTOT+"</B></TD>";
  strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat(fCartTotal) + "</B>";
  strOutput += "<input type=\"hidden\" name=\" " + OutputOrderTotal   + "\" ";
  strOutput += " value=\" " +  fCartTotal + "\" ";
  strOutput += "></TD>";
  strOutput += "</TR>";

  strOutput += "</TABLE>";
      
  if ( PaymentProcessor == strPayPal) {
  //       //Process this for PayPal
    //     strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
//         strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
  //       strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
    //     strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
   }

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    CreateFileEntry                                        ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CreateFileEntry( theform ) {
  var header        = "header.htm";
  var footer        = "footer.htm";
  var returnpage    = "/";
  var orderemail     = "orders@ormer.net";
  var csvfilename   = "orders.csv";
  var csvquote      = "\"\"";
  var divider       = "========================================================================== \n";

  var mode          = "BOTH";
  var strMessageBody = "";
  var strShipTo = "";
  var comparename = "";
  var OrderDate = "";

  var today =new Date();
  var weekday=new Array(7);

  iNumberOrdered = GetCookie("NumberOrdered");

  if ( iNumberOrdered == null )
    iNumberOrdered = 0;

  strQuantity   = "";
  strPrice      = "";
  strID         = "";
  strName       = "";
  strType       = "";
  strCartTotal  = "";

  weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday";
  weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday";

  OrderDate  = weekday[today.getDay()];
  OrderDate += ", " + (today.getMonth()+1) + "-" + today.getDate() + "-" + today.getFullYear();
  OrderDate += "  " +  today.getUTCHours() + ":" + today.getUTCMinutes();

  strMessageBody = "A new order has been received. It appears below.";
  strMessageBody += "\nOrder Date: " +  OrderDate + " \n\nBill To: \n";
  strMessageBody += "-------- \n" + theform.b_first.value + " " + theform.b_last.value;
  strMessageBody += "\n" + theform.b_addr.value;

  if (theform.b_addr2.value != "")
    strMessageBody += " \n" + theform.b_addr2.value;

  strMessageBody += "\n" + theform.b_city.value + ", " + theform.b_state.value;
  strMessageBody += " " + theform.b_zip.value  + "\nPhone:  " + theform.b_phone.value + " \n";
  strMessageBody += "Fax: " + theform.b_fax.value + " \nEmail: " + theform.b_email.value;

  strShipTo1 = theform.s_first.value + " " + theform.s_last.value;

  if ((strShipTo1 + theform.s_addr.value + theform.s_addr2.value) != " " ) {
    strMessageBody += "\n\n\nShip To: \n--------\n";
    if (strShipTo1 != " ") {
      strMessageBody += strShipTo1 + "\n";
    }
    if (theform.s_addr.value != " ") {
      strMessageBody += theform.s_addr.value + "\n";
    }
    if (theform.s_addr2.value != " ") {
      strMessageBody += theform.s_addr2.value + "\n";
    }
    if (theform.s_city.value + theform.s_state.value + theform.s_zip.value != " ") {
      strMessageBody += theform.s_city.value + ", " + theform.s_state.value + " " + theform.s_zip.value + "\n";
    }
    if (theform.s_phone.value != " ") {
      strMessageBody += "Phone:  " + theform.s_phone.value + "\n";
    }
  }

 // fields are: ID, name, qty, BasePrice, ComputedPrice, strType, strFType

  strMessageBody += "\n\nQty          Price        ID           Name                    Description\n";
  strMessageBody += divider; 

  var SelectOptionsCollection = theform.elements;

  var j = SelectOptionsCollection.length;
  var k = 0;
  OrderItem = SelectOptionsCollection.item(k);
  comparename =  OrderItem.name;
  comparename =  comparename.slice(1);

  for (i=1; i<=iNumberOrdered; i++) {
    ItemId       = OutputItemId       + i;
    ItemName     = OutputItemName     + i;
    ItemQuantity = OutputItemQuantity + i;
    ItemPrice    = OutputItemPrice    + i;
    ItemType     = OutputItemType     + i;

   if (comparename == ItemId ) {
     strID  = OrderItem.value;
     k++;
     if (k < j) {
       OrderItem = SelectOptionsCollection.item(k);
       comparename =  OrderItem.name;
       comparename =  comparename.slice(1);
     }
   } 
    
   if (comparename == ItemName ) {
     strName  = OrderItem.value;
     k++;
     if (k < j) {
       OrderItem = SelectOptionsCollection.item(k);
       comparename =  OrderItem.name;
       comparename =  comparename.slice(1);
     }
   } 

   if (comparename == ItemType ) {
     strType  = OrderItem.value;
     k++;
     if (k < j) {
       OrderItem = SelectOptionsCollection.item(k);
       comparename =  OrderItem.name;
       comparename =  comparename.slice(1);
     }
   } 

   if (comparename == ItemQuantity ) {
      strQuantity  = OrderItem.value;
      strQuantity = numberFormat(strQuantity,4);
      k++;
      if (k < j) {
        OrderItem = SelectOptionsCollection.item(k);
        comparename =  OrderItem.name;
        comparename =  comparename.slice(1);
      }
    } 

    if (comparename == ItemPrice ) {
      strPrice  = OrderItem.value;
      k++;
      if (k < j) {
        OrderItem = SelectOptionsCollection.item(k);
        comparename =  OrderItem.name;
        comparename =  comparename.slice(1);
      } 
    }
//  all values associated with line item

    strMessageBody += strQuantity + "        " + MonetarySymbol + moneyFormat(strPrice) + "     ";
    strMessageBody += strID + "    " +   strName + "             " + strType + "    \n";
 
    strQuantity = "";
    strPrice    = "";
    strID       = "";
    strName     = "";
    strType     = "";
  } // for
 
  OrderItem = SelectOptionsCollection.item(k);
  comparename =  OrderItem.name;
  comparename =  comparename.slice(1);

  if (comparename == OutputOrderSubtotal) {
    strSubTotal  = OrderItem.value;
    k++;
    if (k < j) {
      OrderItem = SelectOptionsCollection.item(k);
      comparename =  OrderItem.name;
      comparename =  comparename.slice(1);
    }
  } 

  if (comparename == OutputOrderShipping) {
    strShipping = OrderItem.value;
    k++;
    if (k < j) {
      OrderItem = SelectOptionsCollection.item(k);
      comparename =  OrderItem.name;
      comparename =  comparename.slice(1);
    }
  } 

  if (comparename == OutputOrderTax) {
    strfTax = OrderItem.value;
    k++;
    if (k < j) {
      OrderItem = SelectOptionsCollection.item(k);
      comparename =  OrderItem.name;
      comparename =  comparename.slice(1);
    }
  } 

  if (comparename == OutputOrderTotal) {
    strCartTotal = OrderItem.value;
    k++;
    if (k < j) {
      OrderItem = SelectOptionsCollection.item(k);
      comparename =  OrderItem.name;
      comparename =  comparename.slice(1);
    }
  }

  strMessageBody += divider; 
  strMessageBody += " SUBTOTAL: " + MonetarySymbol + moneyFormat(strSubTotal) + "\n";
  strMessageBody += "            TAX: " + MonetarySymbol + moneyFormat(strfTax) + "\n";
  strMessageBody += "  SHIPPING: " + MonetarySymbol + moneyFormat(strShipping) + "\n";
  strMessageBody += "       TOTAL: " + MonetarySymbol + moneyFormat(strCartTotal) +  "\n";
  strMessageBody += "\nComments: \n----------\n" + theform.comment.value;
  strMessageBody += "\n----------\n\n";

}

//---------------------------------------------------------------------||
// FUNCTION:    CheckForm                                              ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Determines whether required fields have been entered   ||
//              on the order form.                                     ||
//---------------------------------------------------------------------||

function CheckForm( theform ) {
  var bMissingFields = false;
  var strFields = "";
  var atpos = 0;
  var email_len=0;
  var checkstring;
  var strMessageBody = "";

  if ( theform.b_first.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: First Name";
  }

  if ( theform.b_last.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: Last Name";
  }

  if ( theform.b_addr.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: Address";
  }

  if ( theform.b_city.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: City";
  }

  if ( theform.b_state.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: State";
  }

  if ( theform.b_zip.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: Zipcode";
  }

  if ( theform.b_phone.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: Phone";
  }

  if ( theform.b_email.value == "" ){
    bMissingFields = true;
    strFields += "     \nBilling: Email";
  } else {
    checkstring = theform.b_email.value;
    email_len = checkstring.length;
    atpos=checkstring.indexOf("@", 0);
  
    if (email_len<5) {
      bMissingFields = true;
      strFields += "     \nBilling: Email";
    } else if (atpos<1) {
      bMissingFields = true;
      strFields += "     \nBilling: Email";
    }
  }

  if ( bMissingFields ) {
    alert( "I'm sorry, but you must provide valid information in the following field(s) before continuing:\n" + strFields );
   return false;
  }
  CreateFileEntry( theform );
  return true;
}

//
//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||
