function calculateArea()
{	
	
	error=validateFields();
	
	if(error){
		alert('You must only enter numbers in the boxes provided');
	}else{
		//perform the calculations
		var rect_total=Number(calculateRectAreas());//.toFixed(0);
		var tri_total=Number(calculateTriAreas());//.toFixed(0);
		var circ_total=Number(calculateCircAreas());//.toFixed(0);
		var hcirc_total=Number(calculateHCircAreas());//.toFixed(0);
		
		
		//write the calculations to the form
		document.getElementById("rect_tot_all").value= Number(rect_total).toFixed(2);
		document.getElementById("tri_tot_all").value= Number(tri_total).toFixed(2);
		document.getElementById("circ_tot_all").value= Number(circ_total).toFixed(2);
		document.getElementById("hcirc_tot_all").value= Number(hcirc_total).toFixed(2);
		
	
		document.getElementById("areatotal").value= Number(Number(rect_total) + Number(tri_total) + Number(circ_total) + Number(hcirc_total)).toFixed(2);
	}
}

function validateFields(){
	var error;

	//rectangles
	var field=document.getElementById("rect_len_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_len_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_len_3").value;
	if(isNaN(field)){error=true;}	
	
	var field=document.getElementById("rect_wid_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_wid_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_wid_3").value;
	if(isNaN(field)){error=true;}	
	
	var field=document.getElementById("rect_qty_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_qty_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("rect_qty_3").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_len_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_len_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_len_3").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_wid_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_wid_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_wid_3").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_qty_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_qty_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("tri_qty_3").value;
	if(isNaN(field)){error=true;}	
	
	
	field=document.getElementById("circ_diam_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("circ_diam_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("circ_diam_3").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("circ_qty_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("circ_qty_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("circ_qty_3").value;
	if(isNaN(field)){error=true;}	
	

	field=document.getElementById("hcirc_diam_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("hcirc_diam_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("hcirc_diam_3").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("hcirc_qty_1").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("hcirc_qty_2").value;
	if(isNaN(field)){error=true;}	
	
	field=document.getElementById("hcirc_qty_3").value;
	if(isNaN(field)){error=true;}	



	if (error){
		return true;	
	}else{
		return false;
	}
}


function calculateRectAreas()
{
//get the rectangular areas

			//area 1
			var rect_1_total= (document.getElementById("rect_len_1").value*document.getElementById("rect_wid_1").value)*document.getElementById("rect_qty_1").value;
			//area 2
			var rect_2_total= (document.getElementById("rect_len_2").value*document.getElementById("rect_wid_2").value)*document.getElementById("rect_qty_2").value;
			//area 3
			var rect_3_total= (document.getElementById("rect_len_3").value*document.getElementById("rect_wid_3").value)*document.getElementById("rect_qty_3").value;
			
			//rect subtotal area
			var rect_total= rect_1_total + rect_2_total + rect_3_total;
			//document.getElementById("rect_tot_all").value= rect_total;
			
			return rect_total;
}
			
function calculateTriAreas()
{
		//get the triangular areas

			//area 1
			var tri_1_total= ((document.getElementById("tri_len_1").value*document.getElementById("tri_wid_1").value)*document.getElementById("tri_qty_1").value)/2;
			//area 2
			var tri_2_total= ((document.getElementById("tri_len_2").value*document.getElementById("tri_wid_2").value)*document.getElementById("tri_qty_2").value)/2;
			//area 3
			var tri_3_total= ((document.getElementById("tri_len_3").value*document.getElementById("tri_wid_3").value)*document.getElementById("tri_qty_3").value)/2;
			
			//triangle subtotal area
			var tri_total= tri_1_total + tri_2_total + tri_3_total;
			//document.getElementById("tri_tot_all").value= tri_total;
			
			return tri_total;
}


function calculateCircAreas()
{
		//get the circular areas

			//area 1
			var circ_1_total=document.getElementById("circ_qty_1").value*(Math.PI*Math.pow(document.getElementById("circ_diam_1").value/2,2));

			//area 2
			var circ_2_total=document.getElementById("circ_qty_2").value*(Math.PI*Math.pow(document.getElementById("circ_diam_2").value/2,2));
			
			//area 2
			var circ_3_total=document.getElementById("circ_qty_3").value*(Math.PI*Math.pow(document.getElementById("circ_diam_3").value/2,2));
			
			//circangle subtotal area
			var circ_total= circ_1_total + circ_2_total + circ_3_total;
			//document.getElementById("circ_tot_all").value= circ_total;
			
			return circ_total;
}


function calculateHCircAreas()
{
		//get the circular areas

			//area 1
			var hcirc_1_total=(document.getElementById("hcirc_qty_1").value*(Math.PI*Math.pow(document.getElementById("hcirc_diam_1").value/2,2))/2);

			//area 2
			var hcirc_2_total=(document.getElementById("hcirc_qty_2").value*(Math.PI*Math.pow(document.getElementById("hcirc_diam_2").value/2,2))/2);
			
			//area 2
			var hcirc_3_total=(document.getElementById("hcirc_qty_3").value*(Math.PI*Math.pow(document.getElementById("hcirc_diam_3").value/2,2)))/2;
			
			//hcircangle subtotal area
			var hcirc_total= hcirc_1_total + hcirc_2_total + hcirc_3_total;
			//document.getElementById("hcirc_tot_all").value= hcirc_total;
			
			return hcirc_total;
}


/*
function updateWholeForm()
{
	updateForm("sir_walter",document.forms["form_contactForm"].sir_walter_area.value);
	updateForm("fescue",document.forms["form_contactForm"].fescue_area.value);
	updateForm("couch",document.forms["form_contactForm"].couch_area.value);
	updateForm("kikuyu",document.forms["form_contactForm"].kikuyu_area.value);
	updateForm("top_kikuyu",document.forms["form_contactForm"].top_kikuyu_area.value);
	}
	
function updateForm(product, area) {
	// Don't allow non-numbers for area
		document.getElementById("cost_subtotal").value = "";
		cost_subtotal="";
	if (isNaN(area) || area == "") {
		area = 0;
		document.getElementById(product + "_area").value = "";
		document.getElementById(product + "_price").value = "";
		document.getElementById(product + "_total_cost").value = "";
		window[product + "_area"] = 0; // Declare variable for this product's area
		window[product + "_cost"] = 0; // Declare variable for this product's cost

		deliveryCost();
		var product_price = 0;
		var product_total_cost = 0;
		window[product + "_total_cost"] = product_total_cost; //declare variable for this product's cost
	}
	else 
	{
		window[product + "_area"] = parseFloat(area); //declare variable for this product's area
		
		product_price = eval(product + "_price");
		var product_price = getDiscountedPrice(area, product_price);
			
		document.getElementById(product + "_price").value = "$" + product_price.toFixed(2);
		
		var product_total_cost = cost(area,product_price );
		document.getElementById(product + "_total_cost").value = "$" + product_total_cost.toFixed(2);
		window[product + "_total_cost"] = product_total_cost; //declare variable for this product's cost
	}
	
	costSubtotal();
	deliveryCost();
}

function cost(area, price) {
	return area * price;
	
}
function costSubtotal() {
	cost_subtotal=sir_walter_total_cost + fescue_total_cost + couch_total_cost + kikuyu_total_cost + top_kikuyu_total_cost;

	
	if (cost_subtotal==0){
	document.getElementById("cost_subtotal").value = "";
	}
	else{
	document.getElementById("cost_subtotal").value = "$" + Number(cost_subtotal).toFixed(2);
	}
	
	
}
function deliveryCost() {
	area_total = sir_walter_area + fescue_area + couch_area + kikuyu_area + top_kikuyu_area;
	if (area_total >= 100){delivery_cost = 0; fuel_levy = 7;}
	if (area_total >= 1 && area_total < 100 ){delivery_cost = 55 ; fuel_levy = 7;}
	if (area_total == 0 || area_total==""){delivery_cost = 0 ; fuel_levy = 0;}
	
	if (delivery_cost==0){
	document.getElementById("delivery_cost").value = "";
	}
	else{
	document.getElementById("delivery_cost").value = "$" + Number(delivery_cost).toFixed(2);
	}
	
	if(fuel_levy !=0)
	{
	document.getElementById("fuel_levy").value = "$" + Number(fuel_levy).toFixed(2);
	}
	
	costTotal();
}
function costTotal() {

	cost_total = (cost_subtotal + delivery_cost + fuel_levy);
	
	if (cost_total==0 || isNaN(cost_total)|| cost_total==""){
	document.getElementById("cost_total").value = "";
	document.getElementById("fuel_levy").value = "";
	document.getElementById("cost_total").value = "";
	}
	else{
	
	document.getElementById("cost_total").value = "$" + Number(cost_total).toFixed(2);
	}
	
	
}


function calculate(){
updateForm("sir_walter",document.forms[0].sir_walter_area.value);
}

function resetCalculator(){


cost_subtotal = 0;
delivery_cost = 0;
cost_total =  0;
fuel_levy =  0;

sir_walter_area=0;
fescue_area=0;
kikuyu_area=0;
top_kikuyu_area=0;
couch_area=0;

sir_walter_total_cost=0;
fescue_total_cost=0;
kikuyu_total_cost=0;
top_kikuyu_total_cost=0;
couch_total_cost=0;


document.getElementById("sir_walter_area").value = "";
document.getElementById("fescue_area").value = "";
document.getElementById("kikuyu_area").value = "";
document.getElementById("top_kikuyu_area").value = "";
document.getElementById("couch_area").value = "";

document.getElementById("sir_walter_price").value = "";
document.getElementById("fescue_price").value = "";
document.getElementById("kikuyu_price").value = "";
document.getElementById("top_kikuyu_price").value = "";
document.getElementById("couch_price").value = "";

document.getElementById("sir_walter_total_cost").value = "";
document.getElementById("fescue_total_cost").value = "";
document.getElementById("kikuyu_total_cost").value = "";
document.getElementById("top_kikuyu_total_cost").value = "";
document.getElementById("couch_total_cost").value = "";


document.getElementById("cost_subtotal").value = ""
document.getElementById("delivery_cost").value = ""
document.getElementById("fuel_levy").value = ""
document.getElementById("cost_total").value = ""
}
*/
	-->
