addLoadEvent(prepareAttributes); 

/* -----------------------------------------
----------- TOOL BAR -----------------------
----------------------------------------- */

var textarea;

String.prototype.trim = function() {
	return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
}

var attribute_req;
var selectedFlavor = '';
var numFlavors = '';
var countWarning = false;
var firstRun = true;

function update_selection() {
	if (!document.getElementById('attribute_selection_price_value')) return false;
	if (!document.getElementById('attrib-2')) return false;
	var selects = document.getElementsByTagName('select');
	var quantity = document.cart_quantity.cart_quantity.value;
	if (quantity != '' && quantity != null) {
		if (quantity < 1 || !IsNumeric(quantity)) { 
			quantity = 1;
			document.cart_quantity.cart_quantity.value = 1;
		}
	}
	
	for (var i=0; i<selects.length; i++) {
		parts = selects[i].options[selects[i].selectedIndex].text.split('(');
		if (parts.length > 1) {
			var ac = parts[1].split('$');
			var ac2 = ac[1].split(')');
			price = parseFloat(ac2[0]);
		}
	}
	price = Math.round(price * 100);
	price = price * quantity;
	price = price.toString();
	var dollars = price.substring(0,price.length-2);
	var cents = price.substring(price.length-2,price.length);
	document.getElementById('attribute_selection_price_value').firstChild.nodeValue = '$'+dollars+'.'+cents;
}

function prepareAttributes() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById('attribute_selection_price_value')) return false;
	if (!document.getElementById('productAttributes')) return false;
	var selects = document.getElementsByTagName('select');
	for (var i=0; i<selects.length; i++) {
		selects[i].onchange = function() {
			update_selection(this);
			return false;
		}
	}
	document.getElementById('cart_quantity').onkeyup = function() {
		update_selection(this);
		return false;
	}
}

var product_description = true;
function swap_product_info() {
	if (!document.getElementById('nutrition_information')) return false;
	if (product_description) {
		document.getElementById('productDescription').style.display = 'none';
		document.getElementById('nutrition_information').style.display = 'block';
		product_description = false;
	} else {
		document.getElementById('nutrition_information').style.display = 'none';
		document.getElementById('productDescription').style.display = 'block';
		product_description = true;	
	}
	return false;
}