<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function NoEdit () {
  var msg = 'You are not allowed to update this field.';
  msg = msg + '  It shows how many items you have in your shopping cart.';
  alert(msg);
}

function delete_cart (opt) {
  var expDate = new Date();
  expDate.setTime(expDate.getTime() - 1);
  // seen problems with expiring cookies, so null it out too
  if ( opt == 'C' )
  { 
    if ( confirm('Are you sure you want to remove all items from your shopping cart?') )
    { 
      setCookie('SCC', "", expDate, "/", ".sidetracks.net");
      setCookie('SCC_CNT', "", expDate, "/", ".sidetracks.net");
      document.CART.COUNT.value = 0;
    }
  }
  else
  { 
    setCookie('SCC', "", expDate, "/", ".sidetracks.net");
    setCookie('SCC_CNT', "", expDate, "/", ".sidetracks.net");
    document.CART.COUNT.value = 0;
  }
}

function cart_cnt () {
// Following 4 lines will force the email address (acctid) back on the client
//  var expDays = 60; // number of days the cookie should last
//  var expDate = new Date();
//  expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 
//  setCookie('PCID', "felps@thirdrock.com", expDate, "/", ".sidetracks.net");

  var items = getCookie('SCC_CNT');
  if (( items == null ) || ( items.length == 0 ))
  { items = 0; }
  document.CART.COUNT.value = items;
}

function remove_from_cart (icn) {
  var scc = getCookie('SCC');
  var  si = scc.indexOf(icn,0);
  if ( si >= 0 )
  {
    if ( scc.length <= 15 )
    {
      ncs = '';
    }
    else
    {
      if ( si >= 14 )
      {
        si--;
      }
      eb = si + 15;
      ncs = scc.substring(0,si) + scc.substring(eb,scc.length);
    }
    setCookie('SCC', ncs, expDate, "/", ".sidetracks.net");
    var items = getCookie('SCC_CNT');
    items--;
    var expDays = 60; // number of days the cookie should last
    var expDate = new Date();
    expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 
    setCookie('SCC_CNT', items, expDate, "/", ".sidetracks.net");
    document.CART.COUNT.value = items;
    self.location.reload(true);
  }
  else
  {
    confirm('NOTE: No matching item found in your shopping cart to remove!');
  }
}

function add_to_cart (icn, desc, state) {
  var expDays = 360; // number of days the cookie should last
  var expDate = new Date();
  expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 
  var items = 0;
  var msg;
  var scc = getCookie('SCC');
      desc = unescape(desc);

  if ( state == "MAINT" ) {
   alert('WARNING: Shopping cart is disabled for maintenance. Please check back in a few hours.');
   return;
  }
  if ( state == "DISABL" ) {
   alert('WARNING: Shopping cart is disabled. Please check back in 24 hours.');
   return;
  }

  if (( scc == null ) || ( scc.length == 0 ))
  {
    setCookie('SCC', icn, expDate, "/", ".sidetracks.net");
    scc = getCookie('SCC');
    if ( scc == null )
    {
      alert('NOTE: Shopping cart cookie is not set on your system.');
      return;
    }
    var si = scc.indexOf(icn,0);
    if ( si >= 0 )
    {
      items = 1;
      setCookie('SCC_CNT', items, expDate, "/", ".sidetracks.net");
      if ( document.CART != null )
      {
        document.CART.COUNT.value = items;
      }
      desc = "The item, " + desc + ", has been added to your shopping cart.";
      confirm(desc);
    }
    else
    {
      alert('NOTE: Could NOT set shopping cart cookie on your system.');
    }
  }
  else
  {
    var si = scc.indexOf(icn,0);
    if ( si >= 0 )
    {
      msg = "NOTE: " + desc + " (" +icn + ") already exists in your shopping cart.";
      msg = msg + "  You CANNOT add the same item twice.";
      msg = msg + "  You can select quantity when you checkout.";
      alert(msg);
      return;
    }
    else
    {
      scc = scc + "|" + icn;
      setCookie('SCC', scc, expDate, "/", ".sidetracks.net");
      scc = getCookie('SCC');
      var si = scc.indexOf(icn,0);
      if ( si > 0 )
      {
        items = getCookie('SCC_CNT');
        items++;
        setCookie('SCC_CNT', items, expDate, "/", ".sidetracks.net");
        if ( document.CART != null )
        {
          document.CART.COUNT.value = items;
        }
        desc = "The item, " + desc + ", has been added to your shopping cart.";
        confirm(desc);
      }
      else
      {
        alert('NOTE: Could NOT set shopping cart cookie on your system.');
      }
    }
  }
  showcart();
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval = getCookie(name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
    endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}

// This will return the value of the cookie, name, expiration, path or domain
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 (name, value) {
  var argv = setCookie.arguments;  
  var argc = setCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path    = (argc > 3) ? argv[3] : null;  
  var domain  = (argc > 4) ? argv[4] : null;
  var secure  = (argc > 5) ? argv[5] : false;  

  if ( document.cookie = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path    == null) ? "" : ("; path=" + path)) +  
  ((domain  == null) ? "" : ("; domain=" + domain)) +    
  ((secure  == true) ? "; secure" : "") )
  {
    return true;
  }
  else { return false; }
}

//  End -->
