// JavaScript Document
	function Mod(X, Y) { return X - Math.floor(X/Y)*Y }

	function Div(X, Y) { return Math.floor(X/Y) /* full range */ }

	function get_radio_value() {
		var f = document.forms[0];
		for (var i=0; i < f.destzone.length; i++)
			{
			 if (f.destzone[i].checked)
					{
					var rad_val = f.destzone[i].value;
					return rad_val;
					}
			}
	}
	
	function changeShipping () {
		var f = document.forms[0];
		
		// Init values
		f.shippingorder.value = 0;
		var destzone = get_radio_value();
		var totalq = 0;
		var totalorder = 0;
						
		if (f.qty1.value != "") {totalq = totalq + parseInt(f.qty1.value); f.gcfprice1.value = toDollarsAndCents((parseInt(f.qty1.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice1.value);}
		if (f.qty2.value != "") {totalq = totalq + parseInt(f.qty2.value); f.gcfprice2.value = toDollarsAndCents((parseInt(f.qty2.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice2.value);}
		if (f.qty3.value != "") {totalq = totalq + parseInt(f.qty3.value); f.gcfprice3.value = toDollarsAndCents((parseInt(f.qty3.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice3.value);}
		if (f.qty4.value != "") {totalq = totalq + parseInt(f.qty4.value); f.gcfprice4.value = toDollarsAndCents((parseInt(f.qty4.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice4.value);}
		if (f.qty5.value != "") {totalq = totalq + parseInt(f.qty5.value); f.gcfprice5.value = toDollarsAndCents((parseInt(f.qty5.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice5.value);}
		if (f.qty6.value != "") {totalq = totalq + parseInt(f.qty6.value); f.gcfprice6.value = toDollarsAndCents((parseInt(f.qty6.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice6.value);}
		if (f.qty7.value != "") {totalq = totalq + parseInt(f.qty7.value); f.gcfprice7.value = toDollarsAndCents((parseInt(f.qty7.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice7.value);}
		if (f.qty8.value != "") {totalq = totalq + parseInt(f.qty8.value); f.gcfprice8.value = toDollarsAndCents((parseInt(f.qty8.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice8.value);}
		if (f.qty9.value != "") {totalq = totalq + parseInt(f.qty9.value); f.gcfprice9.value = toDollarsAndCents((parseInt(f.qty9.value) * 0.80)); totalorder = totalorder + parseFloat(f.gcfprice9.value);}
		if (f.qty10.value != "") {totalq = totalq + parseInt(f.qty10.value); f.gcfprice10.value = toDollarsAndCents((parseInt(f.qty10.value) * 6.50)); totalorder = totalorder + parseFloat(f.gcfprice10.value);}
									
		// Card shipping				 * totalq
		if (totalq > 0) {
			if (destzone == "oz") {
				f.shippingorder.value = toDollarsAndCents(parseFloat(0.50) * totalq);
			} else {
				f.shippingorder.value = toDollarsAndCents(parseFloat(1.20) * totalq);
			}
		}
		
		// Card total order				
		f.totalorder.value = toDollarsAndCents(parseFloat(totalorder) + parseFloat(f.shippingorder.value));
	}
			
	function toDollarsAndCents(n) {
		var s = "" + Math.round(n * 100) / 100
		//alert(s);
		var i = s.indexOf('.')
		//alert(i);
		if (i < 0) return s + ".00"
		var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
		if (i + 2 == s.length) t += "0"
		return t
	}				
	
	function checkPrices() {
		var f = document.forms[0];
	
		if (f.qty1.value == "0" && f.qty2.value == "0" && f.qty3.value == "0" && f.qty4.value == "0" && f.qty5.value == "0" && f.qty6.value == "0" && f.qty7.value == "0" && f.qty8.value == "0" && f.qty9.value == "0" && f.qty10.value == "0") {
			alert('Please enter a card quantity before clicking on purchase');
			f.qty1.focus();
			return false;
		}
		else {
			if (readCookie('shipval')==undefined) {
				f.shipping.value = parseFloat(f.shippingorder.value);
			} else {
				f.shipping.value = parseFloat(readCookie('shipval')) + parseFloat(f.shippingorder.value);
			}
			createCookie('shipval',f.shipping.value);
						
			//alert(toDollarsAndCents(f.qty1.value * 2.9));
			//changeShipping();	
			f.submit();
		}
	}
