function wtShowCart(response,filePath) {
  var cartLoadingElement = document.getElementById('wtcartloading');
  var cartElement = document.getElementById('wtcart');
	var data = String(response);
	var response = response.replace(/path=/g,'path='+filePath);

  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;
  }
	
	if($('#optionsSelector').css('display') == 'block') {
		$('#optionsSelector').fadeOut(300);	
	}
}

function wtAddToCart(productGuid,path) {
  var quantityElement = document.getElementById('productquantity_' + productGuid);
  var quantity = quantityElement.value;
  var cartLoadingElement = document.getElementById('wtcartloading');

  var optiontext = "_" + productGuid;

  var postdata = new Object();
	
	var filePath = path;

  $("select[name*='" + optiontext + "']").each(function() {
    postdata[$(this).attr('name')] = $(this).val();
  });

  postdata['productquantity_' + productGuid] = quantity;

  cartLoadingElement.style.display = '';

  $.post("?cmd=addtocart", postdata,  function(response){ 
			var data = String(response);
			wtShowCart(data,filePath); 
		}
	);
}

function wtRemoveFromCart(productGuid) {
  $.post("?cmd=removefromcart", { productGuid : productGuid }, wtShowCart);
}


