//  Mini Cart Summary for Volusion Ecommerce V5
// Zen Template #90
// Author: Matt Mather 2/19/2008
// Zoomda.com
// dotnetvision.com
// 2008 All rights reserved
//
// Description:
// This parses the string that is generated by the Volusion template generator
// and transforms it into an un-ordered list. (<ul>)
//
// The css needs to be altered for it to display correctly.
//  Hide the value while the new value is being constructed.
 
//  The cart summary is not displayed on every page.
//  Checks to see whether the div exists.
 
if(document.getElementById("display_cart_summary").firstChild != null)
{
 //Set default values for the item count and cart total variables
 var item_count = "0", cart_total = "0.00";  //set default display
 var free_ship_amount = 99;     //enter dollar amount of free shipping, enter -1 to turn off free shipping display
 var free_ship_display = "";
 
 //Get and parse the current cart values
 var display_cart_summary = document.getElementById("display_cart_summary");
 var cart_content = display_cart_summary.firstChild.firstChild.nodeValue;
 display_cart_summary.firstChild.removeChild(display_cart_summary.firstChild.lastChild);
 
 var contains_index = cart_content.indexOf("contains ")
 if(contains_index > 0) //cart contains items
 {
  item_count = cart_content.substring(contains_index + 9, cart_content.indexOf(" ", contains_index + 9));
  cart_total = cart_content.substring(cart_content.indexOf("$") + 1, cart_content.indexOf(")", cart_content.indexOf("$") + 1));
  if(free_ship_amount >= 0)
  {
   if(free_ship_amount * 100 > parseFloat(cart_total) * 100)
   {
    var free_ship_remainder = String(free_ship_amount * 100 - parseFloat(cart_total) * 100);
    var free_ship_dollars = free_ship_remainder.substring(0, free_ship_remainder.length-2);
    free_ship_dollars = (free_ship_dollars == "") ? "$0" : "$" + free_ship_dollars;
    var free_ship_cents = free_ship_remainder.substring(free_ship_remainder.length-2, free_ship_remainder.length);
    free_ship_display = free_ship_dollars + "." + free_ship_cents + " more needed for free shipping!";
   }
   else
   {
    free_ship_display = "Your shipping is free!";
   }
  }
 }
 else //cart is empty
 {
 }
 
 //Create the DOM elements
 //var divSum = document.createElement("div");
 //divSum.setAttribute("id", "mini_cart_summary")
 var divLink = document.createElement("div");
 divLink.setAttribute("id", "mini_cart_link")
 var divShip = document.createElement("div");
 divShip.setAttribute("id", "mini_cart_ship")
 var linkText = document.createTextNode( "+("+ item_count + " Items)  My Gear");
 //var linkText = document.createTextNode(" +My Gear ::");
 var a = document.createElement("a");
 //var shipText = document.createTextNode(free_ship_display);
 
 //Construct the DOM
 //divSum.appendChild(sumText);
 a.setAttribute("href", "/shoppingcart.asp");
 a.appendChild(linkText);
 //a.appendChild(linkText);
 divLink.appendChild(a);
 //divShip.appendChild(shipText);
 
 //Display the new cart
 display_cart_summary.replaceChild(divLink, display_cart_summary.firstChild);
 display_cart_summary.appendChild(divLink);
 display_cart_summary.appendChild(divShip);
 display_cart_summary.firstChild.style.display = "inline";
}