var total
var totBags
var profitmargin
var need

function wipe() {
document.calc.bags.value = "";
document.calc.profit.value = "";
document.calc.total.value = "";
}

function calculate() {

totBags = parseFloat(document.calc.people.value) * parseFloat(document.calc.sell.value)
need = 500-totBags

	if (totBags<1000) { profitmargin=2 }
	else if (totBags<2000) { profitmargin=2.25 }
	else if (totBags<4000) { profitmargin=2.50 }
	else { profitmargin=2.75 }

total = totBags * profitmargin;
	
document.calc.bags.value = totBags;
document.calc.profit.value = profitmargin;
document.calc.total.value = total;

	if (document.calc.people.value=="") { 
		wipe();
		alert("You must have at least one seller. Please reenter your numbers."); return false;
		}

	if (document.calc.sell.value=="") { 
		wipe();
		alert("You must sell at least one bag per person. Please reenter your numbers."); return false;
		}
	
	if (totBags<500) { 
		wipe();
		alert("Your total number of bags is " + totBags + ", " + need + " short of the minimum goal. Please reenter your numbers."); return false; 
		}

}