// 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.bmprice1.value = toDollarsAndCents((parseInt(f.qty1.value) * 1.25)); totalorder = totalorder + parseFloat(f.bmprice1.value);}
		if (f.qty2.value != "") {totalq = totalq + parseInt(f.qty2.value); f.bmprice2.value = toDollarsAndCents((parseInt(f.qty2.value) * 1.25)); totalorder = totalorder + parseFloat(f.bmprice2.value);}
		if (f.qty3.value != "") {totalq = totalq + parseInt(f.qty3.value); f.bmprice3.value = toDollarsAndCents((parseInt(f.qty3.value) * 1.25)); totalorder = totalorder + parseFloat(f.bmprice3.value);}
		if (f.qty4.value != "") {totalq = totalq + parseInt(f.qty4.value); f.bmprice4.value = toDollarsAndCents((parseInt(f.qty4.value) * 1.25)); totalorder = totalorder + parseFloat(f.bmprice4.value);}
		if (f.qty5.value != "") {totalq = totalq + parseInt(f.qty5.value); f.bmprice5.value = toDollarsAndCents((parseInt(f.qty5.value) * 3.95)); totalorder = totalorder + parseFloat(f.bmprice5.value);}
									
		// Card shipping				 * totalq
		if (totalq > 0) {
			if (destzone == "oz") {
				f.shippingorder.value = toDollarsAndCents(parseFloat(0.50) * totalq);
			} else {
				if (totalq == 1) { 
					f.shippingorder.value = toDollarsAndCents(parseFloat(1.20) * totalq);
				} else if (totalq > 1) {
					f.shippingorder.value = toDollarsAndCents((Div(totalq,8)+1) * (parseFloat(1.85)));
				}
			}
		}
		
		// 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") {
			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();
		}
	}
