function toDollarsAndCents(n) {
	var s = "" + Math.round(n * 100) / 100;
	var i = s.indexOf('.');
	if (i < 0) return s + ".00";
	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3);
	if (i + 2 == s.length) t += "0";
	return t;
}
function getPriceDiff(optionText) {
	var pricevalAr = "";
	var direction = "";
	var priceval = 0;

	if (optionText.indexOf("(+$") > -1) {
		pricevalAr = optionText.split("(+$");
		direction = "add";
	} else if (optionText.indexOf("(+") > -1) {
		pricevalAr = optionText.split("(+");
		direction = "add";
	} else if (optionText.indexOf("(-") > -1) {
		pricevalAr = optionText.split("(-");
		direction = "sub";
	} else if (optionText.indexOf("(-$") > -1) {
		pricevalAr = optionText.split("(-$");
		direction = "sub";
	} else if (optionText.indexOf("(*") > -1) {
		pricevalAr = optionText.split("(*");
		direction = "mult";
	}
	if (pricevalAr.length > 1) {
		priceval = pricevalAr[1].split(")");
		priceval = parseFloat(priceval[0]);
	} else {
		priceval = 0;
	}

	if (direction == "add") {
		return priceval;
	} else if (direction == "sub") {
		return 0 - priceval;
	} else {
		return priceval;
	}
}
function updateOptionPrice() {
	var price = vwattr0_basePrice;
	var unitQty = $("[name=vwquantity0]").val();

	$(".multi-qty").each(function() {
		$(this).val($(this).css("z-index") * unitQty);
	});

	price *=  unitQty;							//Multiply Base Price by Quantity

	for (i = 0; i < $(".opt-qty").length; i++) {				//add Multi Option Prices
		price += $(".opt-qty").eq(i).val() * getPriceDiff($(".opt-select").eq(i).find("option:selected").text());
	}
	
	$("div.productinfo").find("select:not(.opt-select)").find("option:selected").each(function() {
		price += getPriceDiff($(this).text()) * unitQty;
	})
	$("#vwattr0_dispprice").text("$" + toDollarsAndCents(price));
}

$(function(){updateOptionPrice();})