/* 
 * Shopping Cart Summary
 * 
 * Version 1.2
 * EDITS: SPD 2010 07 21
 */


/**
 * 
 */
function getShoppingCartSummary() {
	var mainElement;
	var summaryElement;
	
	mainElement = document.getElementById('display_cart_summary');
	
	if(mainElement == null) {
		return null;
	}

	return mainElement.innerHTML;	
}

/**
 * @return true, false, or null depending on if the cart is empty, not empty, or unknown
 */
function isShoppingCartEmpty() {
	var contents;
	
	contents = getShoppingCartSummary();
	
	if(contents == null) {
		return null;
	}

	if(contents.search('(Your shopping cart is empty)') != -1) {
		return true;
	}
	
	return false;
}

/**
 * 
 */
function getShoppingCartItems() {
	var summary;
	var result;

	summary = getShoppingCartSummary();
	
	if(summary == null) {
		return null;
	}

	result = summary.match(/\s\d+/);

	if(result == null) {
		return null;
	}

	return result[0];
}

/**
 * 
 */
function getShoppingCartTotal() {
	var summary;
	var result1;
	var result2;
	var output;

	summary = getShoppingCartSummary();
	
	if(summary == null) {
		return null;
	}
	
	result = summary.match(/\$(\d)*\.(\d{2})/);

	if(result == null ) {
		return null;
	}
	else{
		return result[0];
	}
}

function updateHeaderCartSummary() {
	var element;
	var items;
	var output;
	
	element = document.getElementById('view_cart_text_right');
	
	if(element == null) {
		return;
	}
	
	items = getShoppingCartItems();
	total = getShoppingCartTotal();

	//No items or null
	if(isShoppingCartEmpty()) {
		output = '0 Items: $0.00';//TEXT MAY BE UPDATED AS NEEDED FOR AN EMPTY CART
	}
	else if (items == null || total == null) {
		return;
	}
	else if(items == 0) {
		output = '0 Items: $0.00';//TEXT MAY BE UPDATED AS NEEDED FOR AN EMPTY CART	
	}
	else {
		//TEXT MAY BE UPDATED AS NEEDED FOR CARTS WITH ITEMS
		output = items + ' Item';
		if (items > 1) {
			output = output + 's';
		}
		output = output + ': ' + total;
	}
	
	//Put data into field
	element.innerHTML = output;
}
function replaceContent(show) {
 
var display = new Array();

display[1] = "\"Great service after sale! The knowledge of the staff at Video Conferencing Supply is unparalleled.\" – Keno V, Carson City, NV";
display[2] = "\"Glad to see a company actually took the time to display all the options for our video conferencing system. Great store!\" - Garry H, Rio Rancho, NM";
display[3] = "\"The best selection of video conferencing equipment anywhere! You all have it all video conferencing on this site!\" - Harvey, T,  Atlanta, GA";
display[4] = "\"Great prices, knowledgeable staff, and excellent service! Thank you!\" – Alicia K, Lancaster, PA";
display[5] = "\"Some the best support and service we've ever had! You all sure know your video conferencing!\" – Stephen H, St. Paul, MN";

document.getElementById("testimonial_js").innerHTML = display[show];
 
}
