// this function totals up all the colums present. . .hopefully.
function total() {
	counter = 1;
	totalcost = 0;
	while(eval("document.forms[0].Price" + counter)) {
		// find the fields for this row...
		thisprice = eval("document.forms[0].Price" + counter);
		thisquantity = eval("document.forms[0].Quantity" + counter);
		thisdivisor = eval("document.forms[0].Divisor" + counter);
		thissubtotal = eval("document.forms[0].SubTotal" + counter);
		
		// make sure that the quantity they've typed in is a) numerical b) not blank and c) at least 0
		if(isNaN(thisquantity.value) || (thisquantity.value == "") || (thisquantity.value < 0)) {
			thisquantity.value = "0";
		}
		
		//decide what price to use by checking the select fields, if they exist
		useprice = thisprice.value;
		thisoptionA = eval("document.forms[0].dispOptionA" + counter);
		thisoptionB = eval("document.forms[0].dispOptionB" + counter);
		thisoptionC = eval("document.forms[0].dispOptionC" + counter);
		thisoptionD = eval("document.forms[0].dispOptionD" + counter);
		thisoptionE = eval("document.forms[0].dispOptionE" + counter);
		if(thisoptionA && (thisoptionA[thisoptionA.selectedIndex].value != "")) { useprice = thisoptionA[thisoptionA.selectedIndex].value; }
		if(thisoptionB && (thisoptionB[thisoptionB.selectedIndex].value != "")) { useprice = thisoptionB[thisoptionB.selectedIndex].value; }
		if(thisoptionC && (thisoptionC[thisoptionC.selectedIndex].value != "")) { useprice = thisoptionC[thisoptionC.selectedIndex].value; }
		if(thisoptionD && (thisoptionD[thisoptionD.selectedIndex].value != "")) { useprice = thisoptionD[thisoptionD.selectedIndex].value; }
		if(thisoptionE && (thisoptionE[thisoptionE.selectedIndex].value != "")) { useprice = thisoptionE[thisoptionE.selectedIndex].value; }
		
		// do the calculation for price...
		thissubtotal.value = curr((thisquantity.value / thisdivisor.value) * useprice);
		totalcost = totalcost + parseFloat(thissubtotal.value);
		counter++;
	}
	document.forms[0].Total.value = curr(totalcost);
}

// quick function that returns a valid currency, to 2 decimal places.
function curr(str) {
	str = (Math.round(parseFloat(str) * 100) / 100) + "";
	finddot = str.indexOf(".");
	if(finddot < 0) {
		str += ".00";
	}
	else if((str.length - finddot) == 2) {
		str += "0";
	}
	if(finddot == 0) {
		str = "0" + str;
	}
	return str;
}

// a basic function to open a basic window with user specified url, width and heights.
function openwindow(url, width, height) {
	featurestr = "directories=0,height=" + height + ",location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,width=" + width;
	open(url, "_blank", featurestr);
}