function drawCart(index)
{
        var cart_complete;
	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;

//on add to cart check to see if cart is empty and if so do not allow hover over cart link
//on add to cart check to see if cart is empty and if so do not allow hover over cart link
if (quantity == 0) {
$("#minicart").unbind("mouseover");
$("#minicart").unbind("mouseout");
}
else
{
var sPath = window.location.pathname; 
if (sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase() != 'shoppingcart.asp' && sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase() != 'one-page-checkout.asp') {
$("#minicart").hoverIntent(retrieveCart,do_nothing);
}
}
//on add to cart check to see if cart is empty and if so do not allow hover over cart link

cart_complete = "Items: " + quantity + " | " + cartTotal; 
$("#mini_cart_summary").html(cart_complete);

	discountTotal = jsonCart.Totals[0].DiscountTotal;

	var i = 0;
	var cartHTML = '<div class="soft_add_wrapper" onmouseover="setTimer();">';
	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" onscroll="setTimer();"><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: "Discount(s)",
    		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 href="/ShoppingCart.asp" class="check_out">Check Out</a>';
	cartHTML += '<a href="" class="continue_shopping" onclick="hideCart(); return false;">Continue shopping</a></div></div></div></div>';
	if (cartDiv == null) {
		cartDiv = document.createElement('div');
		document.body.appendChild(cartDiv);
	}
	cartDiv.innerHTML = cartHTML;
	setTimer();
}

function do_nothing() {}
function addCartLink() {}

function setTimer()
{
	clearTimer();
	cartTimerId = setTimeout('hideCart();', 107500);
}


//cart summary

function retrieveCart2()
{
	sendAjax('GET','/AjaxCart.asp' , '', showCart2, null, false);
}

function showCart2(result, statusCode)
{
	var drawIndex = 0;
	buildCartFromJson(result, statusCode);
	drawIndex = parseInt(jsonCart.Totals[0].LastProduct);
	drawCart2(drawIndex);
}


function drawCart2(index)
{
        var cart_complete;
	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;


//on add to cart check to see if cart is empty and if so do not allow hover over cart link
if (quantity == 0) {
$("#minicart").unbind("mouseover");
$("#minicart").unbind("mouseout");
}
else
{
var sPath = window.location.pathname; 
if (sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase() != 'shoppingcart.asp' && sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase() != 'one-page-checkout.asp') {
$("#minicart").hoverIntent(retrieveCart,do_nothing);
}
}
//on add to cart check to see if cart is empty and if so do not allow hover over cart link


cart_complete = "Items: " + quantity + " | " + cartTotal; 
$("#mini_cart_summary").html(cart_complete);
}


function addToCart2(form, button) {
	var softAdd = true;
        
var productid = form.elements['ProductCode'].value;
	
          var qstr;
	  var bttnName = button.name;
		button.disabled = true;
		if (form.elements['ReturnTo']) {
			form.elements['ReturnTo'].value = "";
		}
		qstr = serialize(form, bttnName + '.x', '5', bttnName + '.y', '5');
                sendAjax('POST','/ProductDetails.asp?ProductCode=' + productid  + '&AjaxError=Y', qstr , function(result, statusCode) { retrieveProductError2(result, statusCode, productid);}
 ,displayServerError,false);
		button.disabled = false;
                return false;
	        }


//check for product with options 
function retrieveProductError2(result, statusCode, productid) {
	var ele = document.getElementById('listOfErrorsSpan');
	var errorIndex = result.indexOf('<carterror>');
	var productIndex = result.indexOf('<ProductIndex>')


//check for error (product options)
if (errorIndex > -1 && productIndex == -1)  {
var error_url = '/ProductDetails.asp?ProductCode=' + productid;
window.location = error_url;
return;
} 
		ele.innerHTML = "";
		if (productIndex == -1) {
		sendAjax('GET','/AjaxCart.asp?GetIndex=True', '', showCart, null, false);
		}
		else {
		productIndex = result.slice(productIndex + 14, result.indexOf('</ProductIndex>'));
		sendAjax('GET','/AjaxCart.asp?Index=' + productIndex, '', showCart, null, false);
		}
	
}

//cat + search + article page soft add

function addToCart3(href) {
var productid2 = href.substring(href.lastIndexOf('=') + 1); 
qstr = 'QTY.' + productid2 + '=1&ReplaceCartID=&ProductCode=' + productid2 + '&e=&btnaddtocart.x=5&btnaddtocart.y=5';
sendAjax('POST','/ProductDetails.asp?ProductCode=' + productid2  + '&AjaxError=Y', qstr , function(result, statusCode) { retrieveProductError3(result, statusCode, productid2);}
 ,displayServerError,false);
               
}


//check for product with options 
function retrieveProductError3(result, statusCode, productid) {
	var ele = document.getElementById('listOfErrorsSpan');
	var errorIndex = result.indexOf('<carterror>');
	var productIndex = result.indexOf('<ProductIndex>')


//check for error (product options)
if (errorIndex > -1 && productIndex == -1)  {
var error_url = '/ProductDetails.asp?ProductCode=' + productid;
window.location = error_url;
return;
} 
		//ele.innerHTML = "";
		if (productIndex == -1) {
		sendAjax('GET','/AjaxCart.asp?GetIndex=True', '', showCart, null, false);
		}
		else {
		productIndex = result.slice(productIndex + 14, result.indexOf('</ProductIndex>'));
		sendAjax('GET','/AjaxCart.asp?Index=' + productIndex, '', showCart, null, false);
		}
	
}
