function calcRolls (height, width, length, doors, windows, rollsize) {
	var rolls, borders
	rolls = Math.round((height * 2 * (Number(width) + Number(length) )  - Number(doors) * 15 - Number(windows) * 12)/rollsize);

	//sets number of border rolls required
	borders = Math.round(((Number(width) + Number(length)) * 2 / 15));
	
	return new Array(rolls,borders);
}

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 rolls
	rsize = document.getElementById("rollsz").options[document.getElementById("rollsz").selectedIndex].value;
	waste = document.getElementById("patternsz").options[document.getElementById("patternsz").selectedIndex].value;
	rsize -= waste;
	if (document.getElementById("metric").checked == true) { rsize *= (22/30); };
	
	var rollarray = calcRolls(height, width, length, ndoors, nwins, rsize);
	var resultText = rollarray[0];
	if (document.getElementById("metric").checked == true) { 
		resultText += " metric"; 
	} else {
		resultText += " standard";
	}
	resultText += " rolls are required.";
	if (document.getElementById("showborder").checked == true) { 
		resultText = resultText + "  " + rollarray[1] + " border rolls are required."; 
	}

	if (document.getElementById("target").hasChildNodes()) { document.getElementById("target").removeChild(document.getElementById("target").firstChild); }
	document.getElementById("target").appendChild(document.createTextNode(resultText));
}
