function FormatNumber(expr, decplaces) 
{
	var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));

	while (str.length <= decplaces) {
		str = "0" + str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
}

var frmOrderForm = null;

function setOptionPrice(e)
{
   var frmOrderForm = jQuery(this).parents("form");
	if (frmOrderForm && frmOrderForm.length == 1 && typeof(jQuery(frmOrderForm).attr("itemprice")) != 'undefined')
	{
		var totalPrice = parseFloat(jQuery(frmOrderForm).attr("itemprice"));
		
		frmOrderForm.find("select").each( function() {
			var val = jQuery(this).val();
			var optRe = /\(([\d\s\+\-\.\$]+)\)/;
			var matches = optRe.exec(val);
			if (matches)
			{
				var addOn = eval(matches[1].replace("$","").replace(",","").replace(" ",""));
				if (addOn && !isNaN(addOn))
				{
					totalPrice += addOn;
				}
			}
		});
		var priceElems = frmOrderForm.find("#prodPrice");
		if (priceElems.length == 0)
		{
			priceElems = frmOrderForm.parent().find("#prodPrice");
		}
		priceElems.each( function() {
/*
			tp.innerHTML = "<font face=arial size=2><b>Price with selected options: $" + FormatNumber(totalPrice,2) + "</b></font>";
			tp.style.display = "block";
*/
			jQuery(this).html("$" + FormatNumber(totalPrice,2) );
			jQuery(this).show();
		});
	}
}
jQuery(document).ready( function() {
  jQuery("form[action*='order.store.yahoo'] select").change(setOptionPrice);
  jQuery("form[action*='test-order'] select").change(setOptionPrice);
});

