function wtShowCart(response) {
  var cartLoadingElement = document.getElementById('wtcartloading');
  var cartElement = document.getElementById('wtcart');

  if(cartLoadingElement) {
    cartLoadingElement.style.display = 'none';
  }

  var pos = response.indexOf('<!--cartinfo');

  var sideHTML = response.substring(0, pos);
  var topHTML = response.substring(pos + 12);
  topHTML = topHTML.substring(0, topHTML.length - 13);

  if(cartElement) {
    cartElement.innerHTML = sideHTML;;
  }

  var shoppingElement = document.getElementById('shopping');
  if(shoppingElement) {
    shoppingElement.innerHTML = topHTML;
  }
}

function wtAddToCart(productGuid) {
  var quantityElement = document.getElementById('productquantity_' + productGuid);
  var quantity = quantityElement.value;
  var cartLoadingElement = document.getElementById('wtcartloading');

  var optiontext = "_" + productGuid;

  var postdata = new Object();

  $("select[name*='" + optiontext + "']").each(function() {
    postdata[$(this).attr('name')] = $(this).val();
  });

  postdata['productquantity_' + productGuid] = quantity;

  cartLoadingElement.style.display = '';

  $.post("?cmd=addtocart", postdata,  wtShowCart);
}

function wtRemoveFromCart(productGuid) {
  $.post("?cmd=removefromcart", { productGuid : productGuid }, wtShowCart);
}


