rows = new Array();
rowTotals = new Array();
total = null;

function recalculate() {
	for(x = 0; x < rows.length; ++x) {
		cells = rows[x].getElementsByTagName('DIV');
		inputs = rows[x].getElementsByTagName('INPUT');
		//alert(parseInt(cells[2].innerHTML)+' * '+parseInt(inputs[0].value));
		cells[3].innerHTML = (parseInt(cells[2].innerHTML) * parseInt(inputs[0].value))+',-';
	}
	
	tPrice = 0;
	for(x = 0; x < rowTotals.length; ++x) {
		tPrice = tPrice + parseInt(rowTotals[x].innerHTML);
	}
				
	total.innerHTML = tPrice + ',-';
}

window.onload = function() {
	list = document.getElementById('orderItems');
	if(list != null) {
		divs = list.getElementsByTagName('DIV');
		
		for(x = 0; x < divs.length; ++x) {
			if(divs[x].className == 'row') {
				rows.push(divs[x]);
			}
			
			if(divs[x].className == 'rowTotal') {
				rowTotals.push(divs[x]);
			}
			
			if(divs[x].className == 'total') {
				total = divs[x];
			}
		}
		
		inputs = list.getElementsByTagName('INPUT');
		
		for(x = 0; x < inputs.length; ++x) {
			inputs[x].onchange = recalculate;
		}
		
		rButton = document.getElementById('refreshButton');
		rButton.onclick = recalculate;
	}
}
