// JavaScript Document

var Cost;

function tally() {
	Cost = 0;
	if (document.orderform.Tithe.value != 0) {
		var Tithe = Number(document.orderform.Tithe.value);
		Cost = Cost + Tithe;
		if (Tithe >= 0) {
			var roundTithe = Math.round(Tithe*100)/100;
			document.orderform.Tithe.value = roundTithe;
		} else {
			document.orderform.Tithe.value = "Invalid Entry";
		}
	}
	if (document.orderform.Missions.value != 0) {
		var Missions = Number(document.orderform.Missions.value);
		Cost = Cost + Missions;
		if (Missions >= 0) {
			var roundMissions = Math.round(Missions*100)/100;
			document.orderform.Missions.value = roundMissions;
		} else {
			document.orderform.Missions.value = "Invalid Entry";
		}
	}
	if (document.orderform.Building.value != 0) {
		var Building = Number(document.orderform.Building.value);
		Cost = Cost + Building;
		if (Building >= 0) {
			var roundBuilding = Math.round(Building*100)/100;
			document.orderform.Building.value = roundBuilding;
		} else {
			document.orderform.Building.value = "Invalid Entry";
		}
	}
	if (document.orderform.Other.value != 0) {
		var Other = Number(document.orderform.Other.value);
		Cost = Cost + Other;
		if (Other >= 0) {
			var roundOther = Math.round(Other*100)/100;
			document.orderform.Other.value = roundOther;
		} else {
			document.orderform.Other.value = "Invalid Entry";
		}
	}

	if (Cost >= 0) {
		var roundCost = Math.round(Cost*100)/100;
		document.orderform.Total.value = roundCost;
	} else {
		document.orderform.Total.value = "Error";
	}
	//document.orderform.amount.value = Cost;
	if (Cost == 0) {
		document.orderform.formSubmit.disabled=true;
	} else {
		document.orderform.formSubmit.disabled=false;
	}
}
function submitForm() {
	if (document.orderform.Total.value == "Error") {
		alert("I am sorry, only numbers are accepted. Please make the appropriate changes and resubmit. Thank you.");
	} else { 
		var orderNum1 = Math.round(Math.random() * 10000);
		var orderNum2 = Math.round(Math.random() * 10000);
		var orderNum3 = Math.round(Math.random() * 10000);
		var orderNum4 = Math.round(Math.random() * 10000);
		var orderNum5 = Math.round(Math.random() * 10000);
		var orderNum = orderNum1 + "-" + orderNum2 + "-" + orderNum3 + "-" + orderNum4 + "-" + orderNum5;
        document.orderform.OrderNumber.value = orderNum;
		var firstForm = document.orderform;
		firstForm.submit();
	}
}

