function inValidCharSet(str,charset)
{
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	return result;
}

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function calculate () {
	if (document.form1.a.value == "") { alert('Please complete the form.'); document.form1.a.focus(); return; }
	if (document.form1.b.value == "") { alert('Please complete the form.'); document.form1.b.focus(); return; }
	if (document.form1.c.value == "") { alert('Please complete the form.'); document.form1.c.focus(); return; }
	if (document.form1.d.value == "") { alert('Please complete the form.'); document.form1.d.focus(); return; }
	if (document.form1.e.value == "") { alert('Please complete the form.'); document.form1.e.focus(); return; }
	if (!inValidCharSet(document.form1.a.value,"0123456789.")) { alert('Please use only numbers in the form fields.'); document.form1.a.focus(); return; }
	if (!inValidCharSet(document.form1.b.value,"0123456789.")) { alert('Please use only numbers in the form fields.'); document.form1.b.focus(); return; }
	if (!inValidCharSet(document.form1.c.value,"0123456789.")) { alert('Please use only numbers in the form fields.'); document.form1.c.focus(); return; }
	if (!inValidCharSet(document.form1.d.value,"0123456789.")) { alert('Please use only numbers in the form fields.'); document.form1.d.focus(); return; }
	if (!inValidCharSet(document.form1.e.value,"0123456789.")) { alert('Please use only numbers in the form fields.'); document.form1.e.focus(); return; }
	document.form1.revenue.value = Dollar((document.form1.b.value * document.form1.e.value));
	document.form1.profit.value = Dollar(((document.form1.c.value * document.form1.e.value) - document.form1.a.value));
	document.form1.prospect.value = Dollar((document.form1.a.value / document.form1.d.value));
	document.form1.sale.value = Dollar((document.form1.a.value / document.form1.e.value));
	document.form1.conversion.value = Dollar(((document.form1.e.value / document.form1.d.value) * 100));
	document.form1.roi.value = Dollar(((document.form1.profit.value / document.form1.a.value) * 100));
	document.form1.revenue.focus();
}