﻿function calculateVolume(itemNumber) {
	var tempQuantity = eval('window.document.frmcalculator.quantity' + itemNumber + '.value');
	var tempVolumeEach = eval('window.document.frmcalculator.itemvolume' + itemNumber + '.value');
				
	if (tempQuantity > 0) {
				window.document.frmcalculator.elements['volume' + itemNumber].value = parseFloat(tempQuantity * tempVolumeEach);
				window.document.frmcalculator.elements['volume' + itemNumber].value = Math.round(window.document.frmcalculator.elements['volume' + itemNumber].value*Math.pow(10,2))/Math.pow(10,2);
	} else {
		window.document.frmcalculator.elements['quantity' + itemNumber].value = '';
		window.document.frmcalculator.elements['volume' + itemNumber].value = '';
	}
	grandTotal();
	unitsize();
}

function grandTotal() {
	var a = window.document.frmcalculator.elements.length;
	var i=0
	var total=0
	for (i=1;i < a;i++) {
		if (window.document.frmcalculator.elements[i].name.substr(0,6) == 'volume') {
			if (!isNaN(parseFloat(window.document.frmcalculator.elements[i].value))) {
				total += parseFloat(window.document.frmcalculator.elements[i].value);
			}
		}
	}
		total = Math.round(total)
		window.document.frmcalculator.elements['TotalVolume'].value = total;
}

function unitsize() {
	var a = window.document.frmcalculator.elements.length;
	var i=0
	var total=0
	for (i=1;i < a;i++) {
		if (window.document.frmcalculator.elements[i].name.substr(0,6) == 'volume') {
			if (!isNaN(parseFloat(window.document.frmcalculator.elements[i].value))) {
				total += parseFloat(window.document.frmcalculator.elements[i].value);
			}
		}
	}
		total = Math.round(total)
			if (total <= 1) {
		window.document.frmcalculator.elements['unitsize'].value = '1.0 x 1.0';
		window.document.frmcalculator.elements['unitcost'].value = '40';
		} else if ((total > 1)&&(total <= 4)) {
		window.document.frmcalculator.elements['unitsize'].value = '1.5 x 1.5';
		window.document.frmcalculator.elements['unitcost'].value = '70';
		} else if ((total > 4)&&(total <= 6)) {
		window.document.frmcalculator.elements['unitsize'].value = '1.5 x 2.0';
		window.document.frmcalculator.elements['unitcost'].value = '90';
		} else if ((total > 6)&&(total <= 7)) {
		window.document.frmcalculator.elements['unitsize'].value = '1.5 x 2.4';
		window.document.frmcalculator.elements['unitcost'].value = '100';
		} else if ((total > 7)&&(total <= 8)) {
		window.document.frmcalculator.elements['unitsize'].value = '1.5 x 3.0';
		window.document.frmcalculator.elements['unitcost'].value = '110';
		} else if ((total > 8)&&(total <= 10)) {
		window.document.frmcalculator.elements['unitsize'].value = '2.0 x 2.0';
		window.document.frmcalculator.elements['unitcost'].value = '120';
		} else if ((total > 10)&&(total <= 14)) {
		window.document.frmcalculator.elements['unitsize'].value = '2.0 x 3.0';
		window.document.frmcalculator.elements['unitcost'].value = '150';
		} else if ((total > 14)&&(total <= 25)) {
		window.document.frmcalculator.elements['unitsize'].value = '3.0 x 3.0';
		window.document.frmcalculator.elements['unitcost'].value = '185';
		} else if ((total > 25)&&(total <= 27)) {
		window.document.frmcalculator.elements['unitsize'].value = '2.8 x 4.0';
		window.document.frmcalculator.elements['unitcost'].value = '200';
		} else if ((total > 27)&&(total <= 30)) {
		window.document.frmcalculator.elements['unitsize'].value = '3.0 x 4.0';
		window.document.frmcalculator.elements['unitcost'].value = '235';
		} else if ((total > 30)&&(total <= 40)) {
		window.document.frmcalculator.elements['unitsize'].value = '3.0 x 5.0';
		window.document.frmcalculator.elements['unitcost'].value = '270';
		} else if ((total > 40)&&(total <= 45)) {
		window.document.frmcalculator.elements['unitsize'].value = '3.0 x 6.0';
		window.document.frmcalculator.elements['unitcost'].value = '310';
		} else if (total > 45) {
		window.document.frmcalculator.elements['unitsize'].value = 'Please Contact Us';
		window.document.frmcalculator.elements['unitcost'].value = 'Please Contact Us';
		}
}
