
<!-- Begin
//Function to round numbers to 2 decimal places
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
// Set the constants
function calculate(form) {
lengthofarea=eval(form.lengthofarea.value);
widthofarea=eval(form.widthofarea.value);
depthofarea=eval(form.depthofarea.value);
constanttons=764;
constantskips=9.64;
aveskipcost=110;
TandLCharges=40;
tonsperminconst=10;
hrsperday = 8;
mccost=260;
resalecostperton=10;

// First Calculate the equivalent TONS of rubble
tons=(lengthofarea*widthofarea*depthofarea)/constanttons;
tonsRounded = roundNumber(tons,2);


// If less than the weight of 1 full skip only 1 skip is needed
if (tons < constantskips) {
skipqty = 1;
}

// Otherwise 2 or more skips needed
else {
// Calculate how many skips are needed
skipqty=Math.round((tons/constantskips)+1);
	}

//If weight of rubble is less than 8 hours of machine running at machine rate (eg 10tph) -1 day only needed	
if (tons < (hrsperday*tonsperminconst)) {
dayshire = 1;
}	

//Otherwise number of days is 2 or more, and rounded up 
else {
// Calculate the number of hire days needed for mini crusher
dayshire = Math.ceil(tons/(tonsperminconst*hrsperday));
}

//Common calculations:	
//Calculate the total cost of skips that would be required
skipcost=skipqty*aveskipcost;

// Calculate Tipping and Landfill charges
tandlcost = tons*TandLCharges;

// Calculate the total hire cost for the mini crusher
hirecost = dayshire*mccost;

// Calculate the money generated fron hardcore resale
resalemoney = resalecostperton*tons;

//Calculate the Sub Totals and the Total saved
traditionalTotal = skipcost+tandlcost;
hardcoreTotal = hirecost-resalemoney;
saving = traditionalTotal-hardcoreTotal;

// Output the calculated values into the text box fields
form.tons.value = tonsRounded + " tonnes";
form.tons2.value = tonsRounded + " tonnes";

form.skipqty.value = skipqty + " skips";
form.skipcost.value = "£ "+ Math.round(skipcost);
form.tandl.value = "£ "+ roundNumber(tandlcost,0);
form.hiredays.value = dayshire + " day hire";
form.mchirecost.value = "£ "+ roundNumber(hirecost,2);
form.mchirecost2.value = "£ "+ roundNumber(hirecost,2);
form.tons3.value = tonsRounded + " tonnes";
form.resalemoney.value = "£ "+ roundNumber(resalemoney,2);
form.resalemoney2.value = "£ "+ roundNumber(resalemoney,2);
form.tons4.value = tonsRounded + " tonnes";
form.traditionalTotal.value = "£ "+ roundNumber(traditionalTotal,2);
form.traditionalTotal2.value = "£ "+ roundNumber(traditionalTotal,2);
form.saving.value = "£ "+ roundNumber(saving,2);
form.saving2.value = "£ "+ roundNumber(saving,2);
}

// End -->
