function updateTotal() {
	var total = 0.0;
	var elements = document.getElementById('order').elements;
	
	for (var i = 0; i < elements.length; i++) {
		if (elements[i].type == "text") {
			if (parseInt(elements[i].value) > 0) {
				var current = parseFloat(elements[i].id);
				if (!isNaN(current)) total += parseInt(elements[i].value) * current;
			}
		}
	}
	
	if (isNaN(total) || total <= 0) document.getElementById('totalField').value = "0.00";
	else document.getElementById('totalField').value = formatCurrency(total);
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function validateOrder()
{
	var formFullname = document.getElementById("fullname").value;
	var formPhone = document.getElementById("phone").value;
	var formAddress1 = document.getElementById("address1").value;
	var formCity = document.getElementById("city").value;
	var formState = document.getElementById("state").value;
	var formZip = document.getElementById("zip").value;
	var totalField = document.getElementById("totalField").value;
	
	if (formFullname == "" || formPhone == "" || formAddress1 == "" || formCity == "" || formState == "" || formZip == "") {
		alert("Please be sure to fill out all address information.");
	}
	else if (parseFloat(totalField) <= 0.0) {
		alert("Please order at least one item.");
	}
	else {
		alert("Thank you for submitting your order, you will be contacted shortly.");
		document.getElementById("order").submit();
	}
}