/*
pushCart.js
*/
function pushCart( paraId ) {
 var url = new String("/Product_AddToCart.cgi?Paragraph_Id="+paraId);
 
 var req = new Request.HTML({"url":url,
    "onSuccess": function(html) {
      // alert(   html );
      //Clear the text currently inside the results div.
      $('pc'+paraId).set('text', '');
      //Inject the new DOM elements into the results div.
      $('pc'+paraId).adopt(html);

    },
    "onFailure": function() {
      $('pc'+paraId).set('text', '');
    }
  });
  req.send();
}
//  onready="pushCart('$id$')"
window.addEvent( 'domready', function() {
$$('.pushcart').each( function(item) {
var trimmer = new String( item.id );
var trimmed = trimmer.substr(2);
 addToCart();  // set the cart content
 pushCart( trimmed ); // set the product links
} );

} ) ;

function addToCart( prodId )
{
  var url = new String("/openCart.cgi");

  if( prodId )
  {
    url += "?action=add&stock=100&id="+prodId;
  }
  var req = new Request.HTML({"url":url,
    "onSuccess": function(html) {
      // alert(   html );
      //Clear the text currently inside the results div.
      $('checkOut').set('text', '');
      //Inject the new DOM elements into the results div.
      $('checkOut').adopt(html);
      if( prodId )
      {
        new Message({
        iconPath: '/pg_images/',
        icon: 'okMedium.png',
        title: 'Item Added!',
        offset: 110,
        centered: true,
        message: '<b>Check Out</b> by clicking on the cart icon at the right top corner of the page...'
        }).say();
      }
    },
    "onFailure": function() {
      $('checkOut').set('text', '');
    }
  });
  req.send();
}

function adjustCart( prodId, cartId  )
{
  var ctrl = prodId + "Count";
  var newVal = $(ctrl).value;
  var url = new String("/openCart.cgi");

  if( prodId )
  {
    url += "?action=update&stock=100&id="+prodId + "&count=" + newVal;
  }
  var req = new Request.HTML({"url":url,
    "onSuccess": function(html) {
      window.location = window.location;
    },
    "onFailure": function() {
      $('checkOut').set('text', '');
    }
  });
  req.send();
}

// start of checkout
function InspectCart( cartId )
{
  var url = new String("/InspectCart.meta");
  url += "?id="+cartId;
  location = url;
}


