function filterNum(str) {
	re = /^\$|,/g;
	return str.replace(re, "");
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function calculateTotalCost() {
	if ($("#ShippingOptions input:checked").val()) {
		var selecteditem = "#cost_" + $("#ShippingOptions input:checked").val();
		var this_cost = filterNum($(selecteditem).html());
		var product_cost = filterNum($("#TotalProductCost").val());
		
		var total_cost = addCommas((parseFloat(product_cost) + parseFloat(this_cost)).toFixed(2));
		
		
		$("#GrandTotalTXT").html("$" + total_cost);
	}
}


$(document).ready(function(){
	calculateTotalCost();			   
	$("#ShippingOptions input").click( function() {
		calculateTotalCost();
		/*
		var selecteditem = "#cost_" + $(this).val();
		var this_cost = filterNum($(selecteditem).html());
		var product_cost = filterNum($("#TotalProductCost").val());
		
		var total_cost = addCommas((parseFloat(product_cost) + parseFloat(this_cost)).toFixed(2));
		
		
		$("#GrandTotalTXT").html("$" + total_cost);
		*/
	});
});

