

var amount = 0.0; // yonder, 'tis global in de scope!

function addAmount(myAmount, elementName) {
	//alert(elementName);
	if(document.getElementById(elementName).checked == true) {
		amount += parseInt(myAmount);
	} else {
		amount -= parseInt(myAmount);
	}
	//alert(amount);
	
	document.getElementById('amountBox').innerHTML='Total Amount:' + amount;
};

function addAmountFromTextField(elementName) {
	//alert(elementName);
	if(document.getElementById(elementName).checked == true) {
		var myAmount = document.getElementById(elementName + '_amount').value;
		var tempAmount = getAmountFromDollarString(myAmount);
		amount += parseFloat(tempAmount);
	} else {
		var myAmount = document.getElementById(elementName + '_amount').value;
		var tempAmount = getAmountFromDollarString(myAmount);
		amount -= parseFloat(tempAmount);
	}
	//alert(amount);
	
	
	
	document.getElementById('amountBox').innerHTML='Total Amount: $' + amount.toFixed(2);
};

function setDisplayAmount(tempAmount) {
	amount = parseFloat(tempAmount);
	document.getElementById('amountBox').innerHTML='Total Amount: $' + amount.toFixed(2);
}

function getAmountFromDollarString(stringAmount) {
	var safeString = "";
	
	for(var i = 0; i < stringAmount.length; i++) {
		if(/\d/.test(stringAmount[i]) || /\./.test(stringAmount[i])) {
			safeString += stringAmount[i];
		}
	}
	
	return safeString;
}


// alert("loaded with amount: " + amount);
