

function updateHeaderCartSummary() {

	var cart_text;
	var elementReference;
	var items;
	var total;
	var output;
	var url = true;
	
	elementReference = getShoppingElement();
	cart_text = getShoppingSummary();
	
	items = getShoppingCartItems(cart_text);
	total = getShoppingCartTotal(items, cart_text);
	
	
	
	if (isShoppingCartEmpty(cart_text))
	{
		output = "Cart Empty";
	} else if (items == null || total == null) {
		return;
	} else {
		total = total.replace("&nbsp;", "");
		if (items == 1)
		{
			output = items + " Item: " + total;
		}  else {
			output = items + " Items: " + total;
		}
	}
	
	elementReference.innerHTML = output ;
	
	/*  Delete this line */
	elementReference.style.display = "block";
}


function getShoppingCartTotal(items, cart_text)
{
	var total = cart_text.split(" ");

	if (items == 1)
	{
		total = total[9].replace(/\)/g, "");
		return total;
	}
	
	if (items > 1)
	{
		total = total[12].replace(/\)/g, "");
		return total;
	}
	
	return null;

}

function getShoppingCartItems(cart_text)
{
	var splitResult = cart_text.split(" ");
	return splitResult[5];

}

function isShoppingCartEmpty(cart_text)
{
	var searchString = '(Your shopping cart is empty)';
	
	cart_text = getShoppingSummary();
	

	if(cart_text == null)
	{
		return null;	
	}
	
	if(cart_text.search(searchString) != -1)
	{	
		return true;	
	} else {
		return false;	
	}
	
}

function getShoppingElement() 
{
	var mainElement
	mainElement = document.getElementById('Display_Cart_Summary');
	
	if (mainElement == null)
	{
		return null;
	} else {
		return mainElement;
	}
	
}

function getShoppingSummary() 
{
	var summary;
	
	summary = document.getElementById('Display_Cart_Summary');
	
	if (summary == null)
	{
		return null;
	} else {
		return summary.innerHTML;
	}
}


