var items = 0;

function firstRun( i ) {
	items = i;
	total();
}

function checkVal( txt ) {
	var output = "";
	var val = (txt.nodeName=="INPUT"?txt.value:txt.innerHTML);
	var bits = val.split('.');
	if (!bits[0]) {
		output += "0";
	} else {
		output += bits[0];
	}
	output += ".";
	output += ((bits[1]?bits[1]:"")+"00").substr(0,2);
	bits = output.split('.');
	if (txt.nodeName=="INPUT") {
		txt.value = output;
	} else {
		txt.innerHTML = output;
	}
}

function change( id , direction ) {
	if ((parseInt(document.getElementById("qty"+id).value) + direction)>-1) {
		document.getElementById("qty"+id).value = parseInt(document.getElementById("qty"+id).value) + direction
	}
}

function total() {
	var total = 0;
	var subtotal = 0;
	for (var i = 1; i <= items; i++) {
		subtotal = 0;
		subtotal = parseInt(document.getElementById("price"+i).value*100)*parseInt(document.getElementById("qty"+i).value);
		if (parseInt(subtotal)) {
			total += subtotal;
		}
	}
	document.getElementById("total").innerHTML = total/100;
	checkVal(document.getElementById("total"));
	setTimeout("total()",50);
}