// NebuCart - The JavaScript Shopping Cart
//Originally authored by Pat Friedl pfriedl@nebulus.org
//
// Copyright 1999-2006 all rights reserved.

// None of this script may be redistributed or sold
// without the authors express consent.
// Violations of copyright will be prosecuted.

// If you would like to use NebuCart,
// email us at admin@javascriptcart.com
// or visit http://www.javascriptcart.com

// ********************************************
// NebuCart Cart View                    *
// ********************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE!    *
// ********************************************

var totalCost     = 0;
var currentCost   = 0;
var tax           = 0;
var SnH           = 0;
var totalQty      = 0;
var currSpan      = 4;
var writeOption   = false;
var yourCart      = Cart;
var cartLocation  = cartPage;

if(String(location).indexOf(cartLocation) == -1){
 var viewingCart = false;
} else {
 var viewingCart = true;
}
if(yourCart.length > 0){
 for(j=0; j < yourCart.length; j++){
  if(yourCart[j].opt){
   writeOption = true;
   currSpan = 5;
  }
 }
 if(viewingCart){
  document.write('<form name="NC_form">');
 }
 document.write('<table border='  + cartBorder + ' cellpadding=' + cartCellPad + ' cellspacing=' + cartCellSpace + '>');
 document.write('<tr bgcolor='    + colBg + '>');
 document.write('<td><font face=' + myFont     + ' size=-1 color=' + colCrim + '>&nbsp;' + cartIDText   + '&nbsp;</td>');
 document.write('<td><font face=' + myFont     + ' size=-1 color=' + colCrim + '>&nbsp;' + cartDescText + '&nbsp;</td>');
 if(writeOption){
  document.write('<td color='  + colBg + '><font face=' + myFont + ' size=-1 color=' + colCrim + '>&nbsp;' + cartOptText + '&nbsp;</td>');
 }
 document.write('<td><font face=' + myFont + ' size=-1 color=' + colCrim + '>&nbsp;' + cartPriceText + '&nbsp;</td>');
 document.write('<td><font face=' + myFont + ' size=-1 color=' + colCrim + '>&nbsp;' + cartQtyText   + '&nbsp;</td>');
 document.write('<td align=center><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + cartCostText + '</td>');
 document.write('</tr>');

 for(z=0; z < yourCart.length; z++){
  totalQty    += Number(yourCart[z].qty);
  currentCost  = Number(yourCart[z].qty) * Number(yourCart[z].price);
  totalCost   += currentCost;
  if(z % 2 == 0){
   document.write('<tr bgcolor=' + colWhite + '>');
  } else {
   document.write('<tr bgcolor=' + colWhite + '>');
  }
  document.write('<td valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '>' + yourCart[z].prodID + '</font></td>');
  document.write('<td valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '>' + yourCart[z].desc + '</font></td>');
  if(writeOption){
   document.write('<td valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '>');
   if(yourCart[z].opt == ''){
    document.write('&nbsp\;');
   } else {

    tmpOpt     = (yourCart[z]).opt.split(',');
     tmpOptList = '';
     for(optC = 0; optC < tmpOpt.length; optC++){
      tmpOptList += (optC > 0) ? '<br>' + String(tmpOpt[optC]) : String(tmpOpt[optC]);
     }
     document.write(tmpOptList);
   }
   document.write('</font></td>');
  }
  document.write('<td align=right valign=top><font face='     + myFont + ' size=-1 color=' + colGrn + '>' + currency + formatDecimal(yourCart[z].price) + '</font></td>');
  if(viewingCart){
   document.write('<td align=right valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '><input type=text value="' + yourCart[z].qty + '" name="' + yourCart[z].prodID + '_' + z + '" size=2></font></td>');
  } else {
   document.write('<td align=right valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '>' + yourCart[z].qty + '</font></td>');
  }
  document.write('<td align=right valign=top><font face='     + myFont + ' size=-1 color=' + colGrn + '>' + currency + formatDecimal(currentCost) + '</font></td>');
  document.write('</tr>');
 }
 if(viewingCart){
  document.write('<tr bgcolor='    + colBg + '>');
  document.write('<td colspan='    + currSpan     + ' align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + cartTotalText + '</font></td>');
  document.write('<td align=right valign=top><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + currency + formatDecimal(totalCost) + '</font></td>');
  document.write('</tr>');

  document.write('<tr bgcolor=' + colWhite   + '>');
  document.write('<td colspan=' + (currSpan + 1) + ' align=right>');
  document.write('</td>');
  document.write('</tr>');	

  document.write('<tr bgcolor=' + colWhite   + '>');
  document.write('<td colspan=' + (currSpan + 1) + ' align=right>');
  document.write('<input type="button" style="color:'+ colMPink +'; background:'+ colPPink +'"  value="' + cartUpdateText + '" onClick="UpdateItems(Cart.length)">');
  document.write('</font></td>');
  document.write('</tr>');

 } else {
  discount = calcDiscount();
  SnH      = calcShipping();
  tax      = calcTax();
  if(tax > 0 || shipAmt != '' || discount > 0){
   document.write('<tr bgcolor=' + colWhite + '>');
   document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + cartSubtotalText + '</font></td>');
   document.write('<td align=right valign=top><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + currency + formatDecimal(totalCost) + '</font></td>');
   document.write('</tr>');
  }
  if(discount > 0){
   document.write('<tr bgcolor=' + colWhite + '>');
   document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1 color=' + colGrn + '>');
   if(getCookieVal(myStoreName + '_d') != ''){
    document.write('Discount (' + getCookieVal(myStoreName + '_d') + '):');
   } else {
    document.write(cartDiscountText);
   }
   document.write('</font></td><td align=right valign=top><font face=' + myFont + ' size=-1 color=' + colGrn + '>-' + currency + formatDecimal(discount) + '</font></td>');
   document.write('</tr>');
  }
  if(shipAmt != ''){
   SnH = calcShipping();
   document.write('<tr bgcolor=' + colWhite + '><td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + cartSnHText);
   if(shipDesc.length > 0){
    document.write(' (' + shipDesc + ')');
   } else if(shipPercent && !useShipOptions && !shipPerItem){
    document.write(' (' + (100 * shipAmt) + '%)');
   }
   document.write(':</font></td><td align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + currency + formatDecimal(SnH) + '</font></td></tr>');
  }
  if(tax > 0){
   tax     = calcTax();
   document.write('<tr bgcolor=' + colWhite + '>');
   document.write('<td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + formatDecimal(taxRate * 100,2) + '% ' + cartTaxText + '</font></td><td align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + currency + formatDecimal(tax) + '</font></td>');
   document.write('</tr>');
  }
  if(tax > 0){totalCost = Number(totalCost) + Number(tax);}
  if(SnH > 0){totalCost = Number(totalCost) + Number(SnH);}
  if(discount > 0){totalCost = Number(totalCost) - Number(discount);}
  document.write('<tr bgcolor=' + colBg + '><td colspan=' + currSpan + ' align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + cartTotalText + '</font></td>');
  document.write('<td align=right><font face=' + myFont + ' size=-1 color=' + colCrim + '>' + currency + formatDecimal(totalCost) + '</font></td></tr>');
 }
 document.write('</table><p>');
 if(viewingCart){
  document.write('<font size=-1>');

//  document.write('&nbsp\;');
  document.write('<input type="button" style="color:'+ colCrim +'; background:'+     colWhite +'"  value="' + keepShopText   + '" onClick="history.back()">');
  document.write('&nbsp\;');
  document.write('<input type="button" style="color:'+ colCrim +'; background:'+     colWhite +'"  value="' + deleteCartText + '" onClick="DeleteCart()">');
  document.write('<br><br>');
 document.write('<input type="button" style="color:'+ colMPink +'; background:'+        colPPink +'"  value="' + checkoutText   + '" onClick="document.location=\'' +       COstep1 + '\'">');
  document.write('</font>');
  document.write('</form>');
 }
} else {
 document.write('<font face=' + myFont + ' color=' + colCrim + ' size=2><br>');
 document.write(cartEmptyText);
 document.write('</font><br>');
document.write('<font face=' + myFont + ' color=' + colGrn + ' size=2><br>');
 document.write(cartEmptyText1);
 document.write('</font><p>');
// document.write('<form name="NC_form">');
// document.write('<font size=-1>');
// document.write('<input type="button" style="color:'+ colCrim +'; background:'+ colWhite +'"  // value="' + backText + '" onClick="history.back()">');
// document.write('</font>');
// document.write('</form>');
}