	
function updateShippingTotal() {
				shipQty = 0;
				
				shipQty = (document.getElementById("flag_35Nylon").value * 1);
				//shipQty += (document.getElementById("flag_35NylonFlown").value * 1);
				shipQty += (document.getElementById("flag_35Cotton").value * 1);
				//shipQty += (document.getElementById("flag_35CottonFlown").value * 1);
				//shipQty += (document.getElementById("flag_46Nylon").value * 1);
				//shipQty += (document.getElementById("flag_46NylonFlown").value * 1);
				shipQty += (document.getElementById("flag_58Cotton").value * 1);
				//shipQty += (document.getElementById("flag_58CottonFlown").value * 1);
				shipQty += (document.getElementById("flag_58Nylon").value * 1);
				//shipQty += (document.getElementById("flag_58NylonFlown").value * 1);
				//alert(shipTotal);
				//shipping_price = document.getElementById('shipping_total').value * 1;
				//alert(shipping_price);
				shippingToAdd = (shipQty * 4.00).toFixed(2);
				//alert("new shipping to add: " + shippingToAdd);
				//shipping_price = (shipping_price + shippingToAdd).toFixed(2);
				
				document.getElementById('shipping_total').value = shippingToAdd;
				document.getElementById('shipping_total_display').innerHTML = "$" + shippingToAdd;
				//alert(document.getElementById('shipping_total_display').innerHTML);
				
				
	
	
}
function updateFlagCertFee() {
				certQty = 0;
				
				certQty = (document.getElementById("flag_35Nylon").value * 1);
				//shipQty += (document.getElementById("flag_35NylonFlown").value * 1);
				certQty += (document.getElementById("flag_35Cotton").value * 1);
				//shipQty += (document.getElementById("flag_35CottonFlown").value * 1);
				//certQty += (document.getElementById("flag_46Nylon").value * 1);
				//shipQty += (document.getElementById("flag_46NylonFlown").value * 1);
				certQty += (document.getElementById("flag_58Cotton").value * 1);
				//shipQty += (document.getElementById("flag_58CottonFlown").value * 1);
				certQty += (document.getElementById("flag_58Nylon").value * 1);
				//shipQty += (document.getElementById("flag_58NylonFlown").value * 1);
				//alert(shipTotal);
				//shipping_price = document.getElementById('shipping_total').value * 1;
				//alert(shipping_price);
				certToAdd = (certQty * 4.05).toFixed(2);
				//alert("new shipping to add: " + shippingToAdd);
				//shipping_price = (shipping_price + shippingToAdd).toFixed(2);
				
				document.getElementById('cert_total').value = certToAdd;
				document.getElementById('cert_total_display').innerHTML = "$" + certToAdd;
				//alert("new price: " + shipping_price);
				
				
	
	
}

function updateFlagTotals() {
	
		fTotal = 0;
				
		if(document.getElementById("flag_35NylonFlown").checked) {
			fTotal = (document.getElementById("flag_35Nylon").value * 1) * document.getElementById("price_1").innerHTML.substr(1,document.getElementById("price_1").innerHTML.length) + ((document.getElementById("flag_35Nylon").value * 1) * 4.05);
		} else {
			fTotal = (document.getElementById("flag_35Nylon").value * 1) * document.getElementById("price_1").innerHTML.substr(1,document.getElementById("price_1").innerHTML.length);
		}
		
		
		
		if(document.getElementById("flag_35CottonFlown").checked) {
			fTotal += (document.getElementById("flag_35Cotton").value * 1) * document.getElementById("price_3").innerHTML.substr(1,document.getElementById("price_3").innerHTML.length) + ((document.getElementById("flag_35Cotton").value * 1) * 4.05);
		} else {
			fTotal += (document.getElementById("flag_35Cotton").value * 1) * document.getElementById("price_3").innerHTML.substr(1,document.getElementById("price_3").innerHTML.length);
			
		}
		
/*			if(document.getElementById("flag_46NylonFlown").checked) {
			fTotal += (document.getElementById("flag_46Nylon").value * 1) * document.getElementById("price_5").innerHTML.substr(1,document.getElementById("price_5").innerHTML.length) + ((document.getElementById("flag_46Nylon").value * 1) * 4.05);
		} else {
			fTotal += (document.getElementById("flag_46Nylon").value * 1) * document.getElementById("price_5").innerHTML.substr(1,document.getElementById("price_5").innerHTML.length);
			
		}*/
		
		if(document.getElementById("flag_58CottonFlown").checked) {
			
			fTotal += (document.getElementById("flag_58Cotton").value * 1) * document.getElementById("price_7").innerHTML.substr(1,document.getElementById("price_7").innerHTML.length) + ((document.getElementById("flag_58Cotton").value * 1) * 4.05);
			
		} else {
			fTotal += (document.getElementById("flag_58Cotton").value * 1) * document.getElementById("price_7").innerHTML.substr(1,document.getElementById("price_7").innerHTML.length);
		}
		
		if(document.getElementById("flag_58NylonFlown").checked) {
			fTotal += (document.getElementById("flag_58Nylon").value * 1) * document.getElementById("price_9").innerHTML.substr(1,document.getElementById("price_9").innerHTML.length) + ((document.getElementById("flag_58Nylon").value * 1) * 4.05);
		} else {
			fTotal += (document.getElementById("flag_58Nylon").value * 1) * document.getElementById("price_9").innerHTML.substr(1,document.getElementById("price_9").innerHTML.length);
		}
		document.getElementById("flags_total").value=fTotal.toFixed(2);
		
	
	
	
	
}

function doTotal(rowToTotal,flagType) {

				priceField = "price_" + rowToTotal;
				totalField =  "total_" + rowToTotal;
				flownField =  flagType +"Flown";
				
				qty = document.getElementById(flagType).value;
				toBeFlown = document.getElementById(flownField).checked;
				//alert("to be flown : " + toBeFlown);
				price = document.getElementById(priceField).innerHTML.substr(1,document.getElementById(priceField).innerHTML.length);
			
				rowTotal = (qty * price).toFixed(2); //the value for the row.
				
				//alert("row total before flown " + rowTotal);
				
				if(toBeFlown) {
				
					flownTotal = (qty * 4.05).toFixed(2);
					//alert("flownTotal: "+ flownTotal);
					rowTotal = ((rowTotal * 1) + (flownTotal * 1)).toFixed(2);
				}
				
				//alert("new total with flown included " + rowTotal);
				//alert(flagType);
				//update the total for this flag type
				document.getElementById(flagType + "_total").value = rowTotal;
				
				//update the flag total at the bottom of the form
				fTotal = (document.getElementById("flags_total").value * 1) + (rowTotal * 1);
				//alert("fTotal: " + fTotal);
				document.getElementById("flags_total").value=fTotal;
				
				updateShippingTotal(); 
				//updateFlagCertFee();
				updateFlagTotals()
				
				f = document.forms["flagForm"];
    		
    			total = 0;
				
				//update the row total
    			document.getElementById(totalField).innerHTML = "$" + addCommas(rowTotal);
				
    			//update the grand total field and display total fields
				grandTotal = (document.getElementById("flags_total").value * 1) + (document.getElementById("shipping_total").value * 1); //no shipping fee by browns office
				//grandTotal = (document.getElementById("flags_total").value * 1);
				//alert("grandTotal: " + grandTotal);
  				document.getElementById("grand_total_display").innerHTML = "$" + addCommas(grandTotal.toFixed(2));
				document.getElementById("grand_total").value = grandTotal.toFixed(2);
				
		
}

   	function addCommas(nStr) {
   			nStr += '';
   			x = nStr.split('.');
   			x1 = x[0];
   			x2 = x.length > 1 ? '.' + x[1] : '';
   			var rgx = /(\d+)(\d{3})/;
   			while (rgx.test(x1)) {
   				x1 = x1.replace(rgx, '$1' + ',' + '$2');
   			}
   			return x1 + x2;
		}
