
var COOKIE_ITEMS1 = 'dr_k1';
var COOKIE_ITEMS2 = 'dr_k2';
// cookie format:    "item_id|cat|quant||item_id|cat|quant|..."

/////////////////////////////

function add_cart (item_id, cat, quant)
{
 // read both cookies
 var cookie = '';
 var c1 = GetCookie (COOKIE_ITEMS1);
 var c2 = GetCookie (COOKIE_ITEMS2);

 if (c1 != null) {  cookie = c1; }
 if ((c2 != null) && (c2 != ''))
  {
   cookie = cookie + c2;
  }

 // append new item to the cookie
 if (cookie != '')
  {
   cookie = cookie + "||";
  }
 cookie = cookie + item_id + "|" + cat + "|" + quant;
 save_cart_cookie (cookie);

 window.location = "/cart.html";
}

/////////////////////////////////////////////

function  save_cart_cookie (kookie)
{
 var c1 = '';
 var c2 = '';
 var thenewdate = new Date ();

 // Split cookies
 if (kookie.length > 3600)
  {
   c1 = kookie.substring (0, 3600);
   c2 = kookie.substring (3600);
  }
 else
  {
   c1 = kookie;
   c2 = '';
  }

 thenewdate.setTime (thenewdate.getTime() + (365 * 24 * 3600 * 1000));

 SetCookie (COOKIE_ITEMS1, c1, thenewdate, "/");
 SetCookie (COOKIE_ITEMS2, c2, thenewdate, "/");
}

/////////////////////////////////////////////

function update_item (id, cat, quant)
{
 // alert ("update|" + id + "|" + cat + "|" + quant);
 SetCookie ("cart_action","update|" + id + "|" + cat + "|" + quant);
 window.location = "/cart.html";
}

/////////////////////////////////////////////

function apply_coupon (coupon)
{
 SetCookie ("coupon", coupon);
 window.location = "/cart.html";
}

