var showCartView = false;

function refreshCart() {
	LHMSE.Fanzz.FanzzService.RenderCartView(successCallback);
}

function addedItemHandler(sender, args) {
	refreshCart();
}

function successCallback(str) {
	//Str contains the cart view control and the item count in XML format.
	if (window.DOMParser) {
		parser = new DOMParser();
		xmlDoc = parser.parseFromString(str, "text/xml");
	}
	else // Internet Explorer
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.loadXML(str);
	}
	var controlContent = xmlDoc.childNodes[0].getElementsByTagName("CartView")[0].childNodes[0].nodeValue;
	var itemCount = xmlDoc.childNodes[0].getElementsByTagName("ItemCount")[0].childNodes[0].nodeValue;

	document.getElementById("lyrItemCount").innerHTML = itemCount;
	document.getElementById("cart_summary_content").innerHTML = controlContent;

	var iCartItemCount = parseInt(itemCount);

	document.getElementById("lyrCheckout").style.display = (iCartItemCount > 0) ? "block" : "none";

	var errorDiv = document.getElementById("ctl00_Body_Item_detail1_ucItemAdd_selectionError");
	if (errorDiv != null && showCartView) {
		showCartView = !(errorDiv.innerHTML.length > 0);
	}

	if (showCartView) {
		document.getElementById("lyrItemAdded").style.display = "block";
		showCartView = false;
		var subobj = document.getElementById("shopping_cart_summary");
		var anchorobj = document.getElementById("quick_cart_info");
		var horizontaloffset = subobj.dropposition[0] == "left" ? -(subobj.offsetWidth - anchorobj.offsetWidth) : 0, verticaloffset = subobj.dropposition[1] == "top" ? -subobj.offsetHeight : anchorobj.offsetHeight;
		subobj.style.left = dropdowncontent.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px";
		subobj.style.top = dropdowncontent.getposOffset(anchorobj, "offsetTop") + verticaloffset + -10 + "px";
		subobj.style.clip = subobj.dropposition[1] == "top" ? "rect(auto auto auto 0)" : "rect(0 auto 0 0)";
		subobj.style.visibility = "visible";
		subobj.startTime = (new Date).getTime();
		subobj.contentheight = 1000;  //parseInt(subobj.offsetHeight);
		dropdowncontent.slideengine(subobj, "down");
		document.location.href = "#top";
		setTimeout("hide()", 6000);
	}
}

function hide() {
	document.getElementById("lyrItemAdded").style.display = "none";
	dropdowncontent.hidediv('shopping_cart_summary');
}

