//update price in product view

var price ={
	basePrice: 0,
	curPrice: 0,
	modArr: [],
	
	initPrice: function(num) {
		this.basePrice = parseFloat(deciTrim(num));
	},
	
	updatePrice : function(optID) {
		var tmpPrice = this.modArr[optID]; // get mod price string
		
		if(tmpPrice == undefined) { // no change in price if there is no mod price
			G('prodPrice').innerHTML = $US(this.basePrice);
		} else {
			tmpPrice = tmpPrice.substring(1); // get mod price as decimal string
			tmpPrice = int_str(parseFloat(this.basePrice) + parseFloat(tmpPrice)); // add mod price to base price
			this.curPrice = deciTrim(tmpPrice)
			
			G('prodPrice').innerHTML = $US(this.curPrice);
		}
	},
	
	initModArr: function(modNum, modIndex) {
		this.modArr[modIndex] = modNum; // add mod price and item index to array
	}
}


function $US(obj) { // add dollar sign to number
	return "$"+obj;
}
function G(obj) { // return element object
	return document.getElementById(obj);
}

function int_str(str) { // convert number to a string
	return (str + '');	
}

function deciTrim(num) { // trim decimal to two places
	return num.replace(/^([\d,]+)\.(\d\d)\d*/,"$1.$2")
}