function doDelivery()
	{
	if (document.checkout.deliv.checked==true)
		{
		var myform=document.getElementById("checkout");
		var newinput=document.createElement("<input type='hidden' name='withDelivery'>");
		myform.appendChild(newinput);
		newinput.setAttribute("id","ad_del");
		} else {
		var tform=document.getElementById("checkout");
		var theNewField=document.getElementById("ad_del");
		if (!theNewField)
			{return}
		tform.removeChild(theNewField);
		}
	}
function doPostage(destination)
	{
	var dest = destination.options[destination.selectedIndex].value;
	document.getElementById("CountrySelect").blur();
	document.getElementById("deliv").focus();
	if (dest == "00")
		{
		alert("Please select the area for delivery");
		location.reload();
		} else {
		// set a code (zone) based on the selected delivery area
		switch(dest) 
			{
			case "GB" :
			zone = "A"
			break
			case "EU" :
			zone = "B"
			break
			case "WD" :
			zone = "C"
			}
		// get the  current displayed postage ie ?.??
		var thepostage = document.getElementById("pst");
		// get  the current displayed price
		var endprice = document.getElementById("prce");
		// get the actual price of goods
		var goodstotal = document.getElementById("tot");
		var totalvalueoforder = document.getElementById("totaloforder");
		var theValueofOrder = totalvalueoforder.value;
		// get the total amount of order (hidden field)
		var orderprice = document.getElementById("amount");
		// get the weight
		var wgt = document.getElementById("theweight");
		var weight = wgt.value;
		var saverweight = weight;
		var post_amount = 0;
		if (zone == "A") // UK
			{
			if (weight <= 4000)
				{
				postCh = new Array(2);
				postCh[0] = [4000,8.22];
				postCh[1] = [2000,6.60];
				postCh[2] = [1750,5.90];
				postCh[3] = [1500,5.20];
				postCh[4] = [1250,4.50];
				postCh[5] = [1000,3.35];
				postCh[6] = [750,2.75];
				postCh[7] = [500,2.24];
				postCh[8] = [250,1.72];
				postCh[9] = [100,1.39];
				for (var i in postCh)
					{
					if (weight > postCh[i][0])
						{
						break;
						}
					post_amount = postCh[i][1];
					} 
				} else 	{
						var extraweight = weight - 4000;
						var band = parseInt((extraweight / 2000), 10) + 1;
						post_amount = 8.22 + ( band * 2.8);
						}
			} else if (zone == "B") // Europe
						{
						if (weight <= 500)
							{
							postCh = new Array(2);
							postCh[0] = [500,3.85];
							postCh[1] = [480,3.73];
							postCh[2] = [460,3.61];
							postCh[3] = [440,3.49];
							postCh[4] = [420,3.37];
							postCh[5] = [400,3.25];
							postCh[6] = [380,3.13];
							postCh[7] = [360,3.01];
							postCh[8] = [340,2.89];
							postCh[9] = [320,2.77];
							postCh[10] = [300,2.65];
							postCh[11] = [280,2.51];
							postCh[12] = [260,2.37];
							postCh[13] = [240,2.24];
							postCh[14] = [220,2.12];
							postCh[15] = [200,1.98];
							postCh[16] = [180,1.85];
							postCh[17] = [160,1.70];
							postCh[18] = [140,1.57];
							postCh[19] = [120,1.42];
							postCh[20] = [100,1.31];
							for (var i in postCh)
								{
								if (weight > postCh[i][0])
									{
									break;
									}
								post_amount = postCh[i][1];
								} 
							} else { 
							while (weight > 1099) // split up if multiple large items
								{
								weight = weight - 1080;
								post_amount = post_amount + 7.04;
								}
								if (post_amount == 0)
									{
									var extraweight = weight - 500;
									var band = parseInt((extraweight / 20), 10);
										if (   band != parseFloat((extraweight / 20))  )
											{ band = band + 1; }
									post_amount = post_amount + 3.85 + ( band * .11);
									} else {
									var extraweight = weight;
									var band = parseInt((extraweight / 20), 10);
										if (   band != parseFloat((extraweight / 20))  )
											{ band = band + 1; }
									post_amount = post_amount + ( band * .11);
									}
							}
							if (theValueofOrder > 55.97)
								{
								post_amount = post_amount + 4.25;
								}
						} else if (zone == "C") // World
							{
							if (weight <= 500)
								{
								postCh = new Array(2);
								postCh[0] = [500,6.87];
								postCh[1] = [480,6.63];
								postCh[2] = [460,6.39];
								postCh[3] = [440,6.15];
								postCh[4] = [420,5.91];
								postCh[5] = [400,5.67];
								postCh[6] = [380,5.43];
								postCh[7] = [360,5.19];
								postCh[8] = [340,4.95];
								postCh[9] = [320,4.71];
								postCh[10] = [300,4.47];
								postCh[11] = [280,4.22];
								postCh[12] = [260,3.96];
								postCh[13] = [240,3.71];
								postCh[14] = [220,3.46];
								postCh[15] = [200,3.20];
								postCh[16] = [180,2.93];
								postCh[17] = [160,2.65];
								postCh[18] = [140,2.38];
								postCh[19] = [120,2.10];
								postCh[20] = [100,1.82];
								for (var i in postCh)
									{
									if (weight > postCh[i][0])
										{
										break;
										}
									post_amount = postCh[i][1];
									} 
								} else { 
								while (weight > 1099) // split up if multiple large items
									{
									weight = weight - 1080;
									post_amount = post_amount + 13.25;
									}
									if (post_amount == 0)
										{
										var extraweight = weight - 500;
										var band = parseInt((extraweight / 20), 10);
											if (   band != parseFloat((extraweight / 20))  )
												{ band = band + 1; }
										post_amount = post_amount + 6.87 + ( band * .22);
										} else {
										var extraweight = weight;
										var band = parseInt((extraweight / 20), 10);
											if (   band != parseFloat((extraweight / 20))  )
												{ band = band + 1; }
										post_amount = post_amount + ( band * .22);
										}
								}
								if (theValueofOrder > 55.97)
									{
									post_amount = post_amount + 4.25;
								}
							}
		}
	post_amount = post_amount + .2;	
	// set the correct postage
	thepostage.firstChild.nodeValue=post_amount.toFixed(2);
	// set the correct end price in the table...
	endprice.firstChild.nodeValue=(parseFloat(goodstotal.firstChild.nodeValue) + parseFloat(thepostage.firstChild.nodeValue)).toFixed(2);
	// ...and in the hidden field
	orderprice.value=endprice.firstChild.nodeValue;
	
				// new bit for saver
				if(saverweight < 50)
					{
					savit();
					} else 
					{
					var theSaver = document.getElementById("saver");
					theSaver.style.visibility = "hidden";
					}
	} // end of doPostage function
function preCheckout()
	{
	var thepostage = document.getElementById("pst");
	if (thepostage.firstChild.nodeValue == "?.??")
		{
		alert("You must select destination for delivery... ");
		var nopost = document.getElementById("CountrySelect");
		nopost.style.color="yellow";
		nopost.style.backgroundColor="green";
		nopost.style.fontWeight="bold";
		return false;
//		location.reload();
		}
	}
function savit()
	{
	var theSaver = document.getElementById("saver");
	theSaver.firstChild.nodeValue = "SAVE MONEY - you can add another bottle of Cortaflex Capsules or Cortaflex HA Capsules to this order and pay no extra postage!";
	theSaver.style.visibility = "visible";
	}