// JScript File for the cart operations var gCartId; var gHMAC; function AddToCart(strASIN) { // If no cart exists, then create a cart. if (!IsGoodCart()) { // Create a NEW cart GetData(3, "cart", 'Operation=CartCreate&Item.1.ASIN=' + strASIN + '&Item.1.Quantity=1&MergeCart=True'); } else { // reuse the EXISTING cart GetData(4, "cart", 'Operation=CartAdd&Item.1.ASIN=' + strASIN + '&Item.1.Quantity=1&MergeCart=True&CartId=' + gCartId + '&HMAC=' + gHMAC); } } function IsGoodCart (){ // Does a cart cookie exist? if ((gCartId !="") & (gCartId !=null) & (gHMAC !="") & (gHMAC !=null)){ // If so the cart is good. return true; } return false; } function EmptyCart(){ // Clear the cart cookies EraseCookie('myCartId'); EraseCookie('myHMAC'); gHMAC=''; gCartId=''; LoadCart(); } function LoadCart(){ // Helper function to load a cart gCartId = ReadCookie('myCartId'); gHMAC = ReadCookie('myHMAC'); if (IsGoodCart()) { // a cart exists so load it... GetData(4, "cart", 'Operation=CartGet&CartId=' + gCartId + '&HMAC=' + gHMAC); } else { document.getElementById('cart').innerHTML = 'No cart exists right now'; } } function RemoveFromCart(strCartItemId){ // If the cart exists... if (IsGoodCart()) { // Remove the item GetData(4, "cart", 'Operation=CartModify&CartId=' + gCartId + '&HMAC=' + gHMAC + '&Item.1.CartItemId=' + strCartItemId + '&Item.1.Quantity=0'); } }