function wtShowCart(response) {
  var cartElement = document.getElementById('wtcart');

  var pos = response.indexOf('<!--cartinfo');

  var topHTML = response.substring(pos + 12);
  topHTML = topHTML.substring(0, topHTML.length - 13);


  var shoppingElement = document.getElementById('shopping');
  if(shoppingElement) {
    shoppingElement.innerHTML = topHTML;
  }

	$('body').append('<div id="cartMessage">Item has been added to cart</div>');
	$('#cartMessage').hide().fadeIn(400,function(){
		$('#cartMessage').animate({ opacity: 1}, 600, function(){
			$(this).fadeOut(400,function(){
				$(this).remove();	
			});	
		});	
	});

}

function wtAddToCart(productGuid) {
  var quantityElement = document.getElementById('productquantity_' + productGuid);
  if(quantityElement) {
  var quantity = quantityElement.value;
  } else {
	var quantity = 1; 
	 }
  var optiontext = "_" + productGuid;
  var postdata = new Object();
  $("select[name*='" + optiontext + "']").each(function() {
    postdata[$(this).attr('name')] = $(this).val();
  });
  postdata['productquantity_' + productGuid] = quantity;
  $.post("?cmd=addtocart", postdata,  wtShowCart);
}

function wtRemoveFromCart(productGuid) {
  $.post("?cmd=removefromcart", { productGuid : productGuid }, wtShowCart);
}


function wtReCalculate(guid) {
	var qty = parseInt($('#q'+guid).attr('value'));
	var updateRequest = new Object();
	updateRequest['q' + guid] = qty;
	$.post('?cmd=recalculateCart', updateRequest );
}

