function changePrice(obj) {
	var elem = document.form1.elements['qty'];
	
	 if(elem.length > 1) {
		 for(var i=0; i<elem.length; i++) {
			if(elem[i].checked == true) {
				var qty = elem[i].value;
				break;
			}
		}
	} else {
		qty = elem.value;
	}
	for(i=0; i<document.form1.elements.length; i++) {
		if(document.form1.elements[i].name == 'qty_price_' + qty)
			break;
	}
	
	if(obj.type == 'radio') {
		for(i=0; i<document.form1.elements.length; i++) {
			if(document.form1.elements[i].name == 'qty_price_' + qty)
				break;
		}
		
		
		var product_price = document.form1.elements[i].value;
		product_price = parseFloat(product_price);
		document.form1.product_price.value = addCommas(product_price.toFixed(2));
		document.getElementById("display_product_price").innerHTML = addCommas(product_price.toFixed(2));
	} else { // checkbox
		var product_price = parseFloat(stripCommas(document.getElementById("display_product_price").innerHTML));
	}
	
	var addon_price = 0;
	for(i=0; i<document.form1.elements.length; i++) {
		if(document.form1.elements[i].type == 'checkbox' && document.form1.elements[i].checked && document.form1.elements[i].name != 'contact_me') {
			var id = document.form1.elements[i].value;
			for(var j=0; j<document.form1.elements.length; j++) {
				if(document.form1.elements[j].name == 'addons_price_' + id + '_' + qty)
					break;
			}
			addon_price += parseFloat(document.form1.elements[j].value);
		}
	}
	
	document.form1.addons_price.value = addCommas(addon_price.toFixed(2));
	document.getElementById("display_addons_price").innerHTML = addCommas(addon_price.toFixed(2));
	var total = addon_price + product_price;
	document.form1.total_price.value = addCommas(total.toFixed(2));
	document.getElementById("display_total_price").innerHTML = addCommas(total.toFixed(2));
}

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 stripCommas(nStr) {
	return nStr.replace(',', '');
}
