function calcPaint (height, width, length, doors, windows, paintarea) {
	var paint;
	paint = Math.round((height * 2 * (Number(width) + Number(length) )  - Number(doors) * 15 - Number(windows) * 12)/paintarea);
	return paint;
}

function calcDistance() {
	var height, width, length, ndoors, nwins, rsize;
	var heighti, widthi, lengthi, waste;
	
	// read up, and then clean up, room dimensions
	height = parseFloat(document.getElementById("height").value);
	if (isNaN(height)) { height = 0; }
		heighti = parseFloat(document.getElementById("heighti").value);
	if (isNaN(heighti)) { heighti = 0; }
		height	+= (heighti/12);
		width = parseFloat(document.getElementById("width").value);
	if (isNaN(width)) { width = 0; }
		widthi = parseFloat(document.getElementById("widthi").value);
	if (isNaN(widthi)) { widthi = 0; }
		width	+= (widthi/12);
		length = parseFloat(document.getElementById("length").value);
	if (isNaN(length)) { length = 0; }
		lengthi = parseFloat(document.getElementById("lengthi").value);
	if (isNaN(lengthi)) { lengthi = 0; }
		length	+= (lengthi/12);
		// account for the presence of doors and windows
		ndoors = parseFloat(document.getElementById("doors").value);
	if (isNaN(ndoors)) { ndoors = 0; }
		nwins = parseFloat(document.getElementById("windows").value);
	if (isNaN(nwins)) { nwins = 0; }
		//figure out sq. footage of paint
		rsize = parseFloat(document.getElementById("metric").value);
	if (isNaN(rsize)) {
		alert("You must enter a capacity for each bucket.");
		return false;
	}
	if (rsize == 0) {
		alert("You must enter a non-zero capacity for each bucket.");
		return false;
	}
	
	if (document.getElementById("target").hasChildNodes()) { document.getElementById("target").removeChild(document.getElementById("target").firstChild); }
	document.getElementById("target").appendChild(document.createTextNode(calcPaint(height, width, length, ndoors, nwins, rsize) + " buckets needed (single coat)."));
}
