<script type="text/javascript">
// Fixes pages using black background templates

if ( PageName() == 'affiliate_signup.asp' ||
     PageName() == 'myaccount_affiliate.asp' ||
     PageName() == 'myaccount_affiliate_banners.asp' ||
     PageName() == 'kb_results.asp' ||
     PageName() == 'ticket.asp' ||      
     PageName() == 'ticket_list.asp')
document.write("\<style>#content_area td {background: #000000;}<\/style>");

// Fixes multi-child add to cart for black templates

if ( PageName() == 'productdetails.asp') document.write("\<style>.smalltext { color:#ffffff; background-color: #000000; }\n.productnamecolorSMALL { color: #ffffff; background-color: #000000; }\n.colors_background_main {background-color:#000000 ! important;}\n.colors_backgroundlight {background-color:#000000 ! important;}<\/style>");

//Fixes error messages on Ticket.asp

if ( PageName() == 'Ticket.asp')
document.write("\<style>#content_area > table > tbody > tr > td > table > tbody > tr > td > font > b {color: #ffffff ! important;}<\/style>");

// Fixes pages using black background templates if (PageName() == 'one-page-checkout.asp') {
    var list = document.getElementsByTagName("font");
    for (var i = 0; i < list.length; i++)        // search for border color
        if (list[i].color == "#000000") {
            list[i].color = "white";
            break;
        }
</script>


/**
 * Update header with cart items
 */
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 = '<a href="/shoppingcart.asp">[ 0 Items: $0.00 ]</a>';//TEXT MAY BE UPDATED AS NEEDED FOR AN EMPTY CART
	}
	else if (items == null || total == null) {
		return;
	}
	else if(items == 0) {
		output = '<a href="/shoppingcart.asp">[ 0 Items: $0.00 ]</a>';//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 = '<a href="/shoppingcart.asp">[ ' + output + ': ' + total + ' ]</a>';
	}
	
	//Put data into field
	element.innerHTML = output;
}

/* 
 * 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];
	}
}
