// Carriage calculations
	function calc_carriage_value (zone)
	{	if (zone=='0') return 0;
		if (zone=='1') return 1.30;
		return 2.60;
	}

	function calc_carriage (zone)
	{	fee = calc_carriage_value (zone);
		if (fee==0) document.Mainform.Carriage.value = "Carriage free"; else document.Mainform.Carriage.value="Carriage: £" + currency (fee) + " per month";
		return fee;
	}

	function currency (x)
	{	if (Math.floor(x)==x) return x+".00"
		if (Math.floor(x*10) == x*10) return x+"0"
		return Math.round(x*100)/100;
	}


// Voucher calculations
		function vtrim (x)
		{	var xx = x;
			while ((k=xx.indexOf (" ")) >=0) {
				xx = xx.substring (0,k) + xx.substring (k+1);
			}
			return xx;
		}
	
	function verify_voucher (voucher_code)
	{	codelist = "2LUZE8JTCRY4IAQVXMSD70K3WP9B5NF6G1HO-";
		xx = vtrim(voucher_code);

		t=0; 
		for (k=0; k<xx.length; ++k) {
			t = t + codelist.indexOf(xx.charAt(k)) * (k+1);
		}
		t=t%37;
		if (t != 0) {
			//alert (t);
			return false;
		}
		if (xx == "FRE800JHQ020NC") return true;
		return false;
	}

	function calc_prepay_discount (voucher_code)
	{	if (!verify_voucher (voucher_code)) return 0;
		return 35;
	}

	function calc_sub_discount (voucher_code)
	{	if (!verify_voucher (voucher_code)) return ""
		return "First installment free";
	}


// sanity checks

		function nm (t)
		{	if (t.alt) return t.alt
			return t.name
		}
		
	function verify (t)
	{	if (t.value.search (t.re) == -1)
		{	alert ("''"+t.value + "'' doesn't seem to be a sensible entry for "+nm(t)+"\nTry something like ''"+t.eg+"''");
			return false;
		}
		return true;
	}
	function final_check(t)
	{	if (!verify (t)) {
			t.focus();
			return false
		}
		return true;
	}
