function showProdDetails( n )
{
	var maxid = document.getElementById( "prodcount" ).title;
	for( var i = 1; i < maxid; i++ )
	{
		document.getElementById( "detail" + i ).style.display = i == n ? "block" : "none";
	}
}

function onTitleClick( n )
{
	var elem = document.getElementById( "order" ).elements[ "check-" + n ];
	elem.checked = !elem.checked;
	onCheckClick( n );
}

function formatPrice( price )
{
	var rm = Math.floor( ( price + 0.005 - Math.floor( price ) ) * 100 );
	return '' + Math.floor( price ) + ( rm < 10 ? '.0' : '.' ) + rm;
}

function onCheckClick( n )
{
	var form = document.getElementById( "order" ).elements;
	var count = document.getElementById( "prodcount" ).title;
	for( var i = 1; i < count && !form[ "check-" + i ].checked; i++ );
	var bDiscount = i < count;
	var total = 0, discount = 0, subtotal = 0, price, crossell = Number( form[ "discount" ].value );
	for( var i = 0; i < count; i++ )
	{
		if( i == 0 || form[ "check-" + i ].checked )
		{
			price = Number( form[ "price-" + i ].value );;
			subtotal += price;
			if( bDiscount )
				discount += price * crossell;
		}
		document.getElementById( "oldprice-" + i ).style.display = bDiscount ? "inline" : "none";
		document.getElementById( "itmprice-" + i ).style.display = bDiscount ? "none" : "inline";
		document.getElementById( "newprice-" + i ).style.display = bDiscount ? "inline" : "none";
	}
	total = subtotal - discount;
	document.getElementById( "_subtotal" ).textContent = "$" + formatPrice( subtotal );
	document.getElementById( "_discount" ).textContent = "$" + formatPrice( discount );
	document.getElementById( "_total" ).textContent = "$" + formatPrice( total );
	document.getElementById( "_subtotal" ).innerText = "$" + formatPrice( subtotal );
	document.getElementById( "_discount" ).innerText = "$" + formatPrice( discount );
	document.getElementById( "_total" ).innerText = "$" + formatPrice( total );
}




















