﻿var _products, _pricelevels;

function switchPriceGroup() {
	var ProductID = parseInt(this.id.match(/\d+$/)[0]);
	_products.each( function(tr) { tr[ tr.id == ("Product_" + ProductID) ? "addClassName" : "removeClassName" ]("Selected"); });
	_pricelevels.each( function(tr) { tr[ tr.id.startsWith("ProductPrice_" + ProductID) ? "show" : "hide" ](); });
	
	this.down("input").activate();
}
document.observe( "dom:loaded", function() {
	_products = $$('form#OrderForm table tbody.HasPriceLevels tr');
	_pricelevels = $$('div#PriceLevels table tbody tr');
	if ( _products.size() > 1 )
		_products.invoke( "observe", "click", switchPriceGroup );
});
