DisplayCartPopup.prototype.DrawCart = function(CartX, CartY) {

	var instance = this;
	buildCartFromJson(this.data, 200);

	var index = parseInt(jsonCart.Totals[0].LastProduct);
	var quantity;
	var cartTotal;
	var discountTotal;
	var cartLength = 0;
	if (jsonCart != null) {
		cartLength = jsonCart.Products.length;
	}

	quantity = jsonCart.Totals[0].Quantity;
	cartTotal = jsonCart.Totals[0].CartTotal;
	discountTotal = jsonCart.Totals[0].DiscountTotal;
	jQuery("#mini_cart_summary").html('Items: ' + quantity + '&nbsp;&nbsp; | &nbsp;&nbsp;'  + cartTotal);
	var i = 0;
	var cartHTML = '';
	cartHTML += '<div class="soft_add_wrapper">';
	cartHTML += '<div class="soft_add_header_shadow">';
	cartHTML += '<div class="soft_add_header"><span class="soft_add_span">Added to cart</span><a href="" class="close_btn" onclick="hideCart(); return false;">Close</a></div></div>'
	cartHTML += '<div class="soft_add_content_shadow"><div class="soft_add_content_wrapper">';
	cartHTML += '<div class="soft_add_content_area"><table class="cart_table" cellpadding="0" cellspacing="0" border="0">';
	if (cartLength != 0) {
		cartHTML += cartLoop(index, cartLength);
		if (index != 0) {
			cartHTML += cartLoop(0, index);
		}
		if (discountTotal != "0") {
			var discountProduct = {
				ProductName: "Total Discount",
				ProductPrice: '<span style="color:red">' + discountTotal + '</span>'
			}
			cartHTML += getLineItemHTML(discountProduct);
		}
	}
	cartHTML += '</table></div><div class="soft_add_sub_total"><div class="number_of_items">' + quantity + ' items in cart</div>';
	cartHTML += '<div class="sub_total">';
	cartHTML += 'Subtotal: <span class="sub_total_amount">' + cartTotal + '</span>';
	cartHTML += '</div>';
//	cartHTML += '</div><div class="soft_add_action_area"><a class="update_quantities" href="" onclick="update_Cart(); return false;">Update quantities</a><a href="/ShoppingCart.asp" class="check_out">Check Out</a>';

	cartHTML += '</div><div class="soft_add_action_area"><a href="/ShoppingCart.asp" class="check_out">Check Out</a>';
	cartHTML += '<a href="" class="continue_shopping" onclick="hideCart(); return false;">Continue shopping</a><a class="update_quantities" href="" onclick="update_Cart(); return false;">Update quantities</a></div></div></div></div>';

	if (!cartDiv2) {
		cartDiv2 = document.createElement('div');
		jQuery(cartDiv2).css('visibility', 'hidden').attr('class', 'cartDiv2');
		jQuery('body').append(cartDiv2);
	} else {
		cartDiv2.innerHTML = '';
	}

	cartDiv2.innerHTML = cartHTML;
	jQuery('.cartDiv2 .product_name').each(function(index, Element) {
		if (Element.textContent) {
			Element.innerHTML = Element.textContent;
		} else if (Element.innerText) {
			Element.innerHTML = Element.innerText;
		}
		Element.innerHTML = Element.innerHTML.replace(/<[^>]*>/g, '');
	});

	if (CartX >= 0 && CartY >= 0) {
		var MaxX = (jQuery(window).width()) - jQuery('.soft_add_wrapper').width();
		MaxX += CART_MIN_LEFT;
		MaxX -= CART_PADDING_RIGHT;
		if (CartX > MaxX) { CartX = MaxX; }

		var MaxY = (jQuery(window).height()) - jQuery('.soft_add_wrapper').height();
		if (CartY > MaxY) { CartY = MaxY; }

		var MinX = CART_MIN_LEFT + CART_PADDING_LEFT;
		var MinY = CART_MIN_TOP + CART_PADDING_TOP;

		if (CartX < CART_MIN_LEFT) { CartX = CART_MIN_LEFT; } //left
		if (CartY < CART_MIN_TOP) { CartY = CART_MIN_TOP; } //left
		jQuery('.soft_add_wrapper').css({ left: Math.round(CartX).toString() + 'px', top: Math.round(CartY).toString() + 'px' })
	} else {
		jQuery('.soft_add_wrapper').css({ left: 50 + '%', top: 140 + 'px' })
		CartX = jQuery('.soft_add_wrapper').offset().left;
		CartX -= (jQuery('.soft_add_wrapper').width() / 2);
		jQuery('.soft_add_wrapper').css({ left: CartX + 'px' })
	}

	window.setTimeout(function() { instance.ResizeImages(); }, 200);

}


//-----------------------------cart summary--------------------------------

jQuery(function(){
	jQuery.ajax({
		url: '/AjaxCart.asp',
		cache: false,
		dataType: 'text',
		success: function(data) {
			var json = eval('(' + data + ')');
			jQuery("#mini_cart_summary").html('Items: ' + json.Totals[0].Quantity + '&nbsp;&nbsp; | &nbsp;&nbsp;' + json.Totals[0].CartTotal);
		},
		error: function() {
			return false;
		}
	});
});


//-----------------------------cart summary--------------------------------


//links for soft cart

function getLineItemHTML(product) {
	var productHTML, imageSource, productName, quantity, productPrice, hasOptions, productIndex, isProduct;
	product.IsProduct == undefined ? isProduct = 'N' : isProduct = product.IsProduct;
	if (global_Config_EnableDisplayOptionProducts == 'False' && isProduct == "N") { return ''; }

	product.ImageSource == undefined ? imageSource = '' : imageSource = '<img src="' + product.ImageSource + '" />'; //height="50px" width="50px"
	product.ProductIndex == undefined ? productIndex = '' : productIndex = product.ProductIndex;
	product.ProductName == undefined ? productName = '' : productName = product.ProductName;
	product.ProductPrice == undefined ? productPrice = '' : productPrice = product.ProductPrice;
	product.HasOptions == undefined ? hasOptions = 'N' : hasOptions = product.HasOptions;
	product.Quantity == undefined ? quantity = '' : quantity = product.Quantity;

	if (isProduct == "Y") {
	productHTML = '<tr><td class="icon">' + imageSource + '</td>';
	productHTML += '<td class="description"><a style="color: #000000; text-decoration: none; outline: none;" class="product_name" href="/ProductDetails.asp?ProductCode=' + product.ProductCode + '">' + productName + '</a>';
	} else {
	productHTML = '<tr><td class="icon"><img src="/v/vspfiles/templates/140/images/clear1x1.gif" style="height: 50px;"></td>';
	productHTML += '<td class="description"><span class="product_name2">' + productName + '</span>';
	}

	productHTML += '<span class="product_id">';
	if (hasOptions == "Y") {
		productHTML += '<a href="javascript:void(0);" onclick="javascript:OpenNewWindow(\'/Help_CartItemDetails.asp?CartID=' + product.ProductIndex + '\',\'425\',\'300\');">Options</a>';
	}
	productHTML += '</span></td>';
	var index_name= "Quantity" + productIndex;

	if (isProduct == "Y") {
	var index_name= "Quantity" + productIndex;
	productHTML += '<td><input type="text" id="' + index_name +'" name="' + index_name + '" value="' + quantity + '" size="5" autocomplete="off" maxlength="5" style="font-size: 9px; "></td>';
	} else {
	productHTML += '<td class="quantity">' + quantity + '</td>';
	}

	productHTML += '<td class="price"><span id="product_price">' + productPrice + '</span></td>';
	productHTML += '<td class="remove">';
	if (isProduct == "Y") {
		productHTML += '<a title="Remove this item" alt="Remove this item" href="" class="aremove" onclick="removeFromCart(' + productIndex + '); return false;">remove</a>';
	}
	productHTML += '</td></tr>';
	return productHTML;
}


//-----------------------------cart summary--------------------------------


function update_Cart() {
jQuery('.update_quantities').addClass('ajax_process'); 

	if (!global_Config_ForceSecureShoppingCartPage) {
	form_data= '';
	var url;
	jQuery('[id^="Quantity"]').each(function(){
	form_data+= jQuery(this).attr('id') + "=" + jQuery(this).val() + "&";
	});

		jQuery.ajax({
			url: '/ShoppingCart.asp?' +form_data+ 'btnRecalculate.x=5&btnRecalculate.y=5',
			cache: false,
			dataType: 'text',
			success: function(data, textStatus, XMLHttpRequest) {
				if (displayCartPopup) {
					displayCartPopup.Dispose();
				}
				displayCartPopup = new DisplayCartPopup();
				displayCartPopup.ShowOK = true;
				displayCartPopup.DeleteItemComplete = true;
				displayCartPopup.retrieveCart();
			},
			error: function() {
			jQuery('.update_quantities').removeClass('ajax_process'); 
				return false;
			}
		});

	} else {

		form_data= '';
		var url;
		jQuery('[id^="Quantity"]').each(function(){
			form_data+= jQuery(this).attr('id') + "=" + jQuery(this).val() + "&";
		});

		jQuery.ajax({
 			url: 'https:' + '//' + window.location.host + '/ShoppingCart.asp?' +form_data+ 'btnRecalculate.x=5&btnRecalculate.y=5',
			cache: false,
			type: 'get',
			dataType: "jsonp",
			success: function(){}
		});
		setTimeout(function() {
		if (displayCartPopup) {
			displayCartPopup.Dispose();
		}
		displayCartPopup = new DisplayCartPopup();
		displayCartPopup.ShowOK = true;
		displayCartPopup.DeleteItemComplete = true;
		displayCartPopup.retrieveCart();
		} , 2000);
	}
}

// submit soft cart changes on enter
jQuery('input[id^="Quantity"]').live('keyup', function(e) {
        if(e.keyCode==13){ update_Cart(); }
});
