// JavaScript Document

var SuburbsAtoF =  new Array("('Select a Suburb','',true,true)","('Aberfoyle Park','15.00')","('Adel Airport','11.00')","('Adelaide','8.80')","('Albert Park','11.00')","('Alberton','14.00')","('Aldgate','20.00')","('Allenby Gardens','10.00')","('Andrews Farm','25.00')","('Angle Park','14.50')","('Angle Vale','30.00')","('Ascot Park','12.00')","('Ashford','10.00')","('Ashton','19.00')","('Athelstone','15.00')","('Athol Park','14.00')","('Auldana','11.00')","('Bakers Gully','30.00')","('Balhannah','23.00')","('Banksia Park','16.50')","('Basket Range','28.00')","('Beaumont','11.00')","('Bedford Park','14.00')","('Belair','14.00')","('Bellview  Heights','15.00')","('Beulah Pk','10.00')","('Beverley','10.00')","('Birkenhead','15.00')","('Black Forest','10.00')","('Blackwood','15.00')","('Blackwood Garden','15.00')","('Blair Athol','11.00')","('Blakeview','28.00')","('Blakiston','30.00')","('Blewitt Springs','30.00')","('Bolivar','18.00')","('Bowden','9.90')","('Bradbury','22.00')","('Brahma Lodge','16.50')","('Bridgewater','21.00')","('Brighton','15.00')","('Broadview','11.00')","('Brompton','11.00')","('Brooklyn Pk','10.00')","('Brownhill Creek','13.20')","('Burnside','11.00')","('Burton','19.00')","('Camden Pk','11.00')","('Campbelltown','12.00')","('Carey Gully','25.00')","('Castambul','23.00')","('Cavan','16.50')","('Centennial Park','16.50')","('Chain Of Ponds','25.00')","('Chandlers Hill','19.00')","('Charleston','30.00')","('Cheltenham','13.20')","('Cherry Gardens','23.00')","('Cherryville','24.00')","('Christies Beach','24.00')","('Christie Downs','24.00')","('Clapham','12.00')","('Clarence Park','12.00')","('Clarences  Garden','12.00')","('Clarendon','25.00')","('Clearview','11.00')","('Clovelly Park','15.00')","('Col Light Gardens','12.00')","('College Park','10.00')","('Collinswood','11.00')","('Coramandel East','16.00')","('Coromandel Valley','16.00')","('Cowandilla','10.00')","('Crafers','18.00')","('Crafers West','18.00')","('Craigburn','20.00')","('Craigmore','22.00')","('Croydon','11.00')","('Croydon Park','11.00')","('Croydon Park South','11.00')","('Cudlee Creek','29.00')","('Cumberland Park','10.00')","('Darlington','15.00')","('Davoren Park','24.00')","('Daw Park','12.00')","('Dernancourt','14.00')","('Devon Park','11.00')","('Direk','21.00')","('Dover Gardens','15.00')","('Dry Creek','15.00')","('Dudley Park','11.00')","('Dulwich','9.90')","('Eagle On The Hill','16.50')","('Eastwood','9.90')","('Echunga','36.00')","('Eden Hills','15.00')","('Edinburgh','23.00')","('Edwardstown','12.00')","('Elizabeth Downs','23.00')","('Elizabeth East','23.00')","('Elizabeth','23.00')","('Elizabeth Grove','23.00')","('Elizabeth Heights','23.00')","('Elizabeth North','23.00')","('Elizabeth Park','23.00')","('Elizabeth South','23.00')","('Elizabeth Vale','23.00')","('Elizabeth West','23.00')","('Enfield','11.00')","('Erindale','9.90')","('Ethelton','14.00')","('Evandale','11.00')","('Evanston','34.00')","('Evanston Gardens','34.00')","('Evanston Park','36.00')","('Evanston Sth','36.00')","('Everard Park','11.00')","('Exeter','15.00')","('Export Park','11.00')","('Fairveiw Park','17.00')","('Felixstow','11.00')","('Ferryden Park','11.00')","('Findon','11.00')","('Firle','10.00')","('Fitzroy','10.00')","('Flagstaff Hill','15.00')","('Flinders Park','11.00')","('Forest Range','25.00')","('Forestville','11.00')","('Frewville','10.00')","('Fulham','12.00')","('Fulham Gardens','12.00')","('Fullarton','11.00')");


var SuburbsGtoN =  new Array("('Select a Suburb','',true,true)","('Garden Island','17.00')","('Gawler','29.00')","('Gepps Cross','13.20')","('Gilberton','10.00')","('Gilles Plains','13.20')","('Gillman','15.00')","('Glandore','13.20')","('Glanville','15.00')","('Glen Osmond','11.00')","('Glenalta','15.00')","('Glenelg','16.50')","('Glenelg East','14.00')","('Glenelg Nth','14.00')","('Glenelg Sth','14.00')","('Glengowrie','14.00')","('Glenside','10.00')","('Glenunga','10.00')","('Globe Derby Park','19.00')","('Glynde','11.00')","('Golden Grove','19.00')","('Goodwood','11.00')","('Gould Creek','20.00')","('Grange','10.00')","('Greenacres','10.00')","('Greenfields ','14.00')","('Greenhill','14.00')","('Greenwith','16.50')","('Gulfview Heights','16.50')","('Hackham','22.00')","('Hackham West','22.00')","('Hackney','9.90')","('Hahndorf','23.00')","('Hallet Cove','19.00')","('Hampstead Gdns','13.20')","('Happy Valley','16.50')","('Hawthorndene','15.00')","('Hawthorn','11.00')","('Hazelwood Park','11.00')","('Heathfield','19.00')","('Heathpool','10.00')","('Hectorville','11.00')","('Hendon','11.00')","('Henley Beach','11.00')","('Henley Beach Sth','11.00')","('Highbury','15.00')","('Highgate','11.00')","('Hillbank','21.00')","('Hillcrest','12.00')","('Hilton','11.00')","('Hindmarsh','11.00')","('Holden Hill','14.00')","('Hope Valley','14.00')","('Houghton','21.00')","('Hove','14.00')","('Humbug Scrub','34.00')","('Huntfield Heights','25.00')","('Hyde Park','10.00')","('Ingle Farm','14.00')","('Inglewood','24.00')","('Inverbrackie','31.00')","('Ironbank','20.00')","('Joslin','10.00')","('Kensington','10.00')","('Kensington Gardens','10.00')","('Kensinton Park','10.00')","('Kent Town','10.00')","('Keswick','10.00')","('Kidman Park','11.00')","('Kilburn','11.00')","('Kilkenny','11.00')","('Kings Park','11.00')","('Kingston Park','16.50')","('Kingswood','11.00')","('Klemzig','11.00')","('Kudla','36.00')","('Kurralta Park','11.00')","('Largs Bay','15.00')","('Largs North','15.00')","('Leabrook','10.00')","('Leawood Gdns','16.50')","('Lenswood','28.00')","('Linden Park','10.00')","('Littlehampton','30.00')","('Lobethal','26.00')","('Lockleys','11.00')","('Longwood','21.00')","('Lonsdale','20.00')","('Lower Hermitage','23.00')","('Lower Mitcham','13.20')","('Lynton','14.00')","('Magill','10.00')","('Malvern','11.00')","('Manningham','11.00')","('Mansfield Park','12.00')","('Marble Hill','24.00')","('Marden','11.00')","('Marino','16.50')","('Marion','13.20')","('Marleston','11.00')","('Marryatville','11.00')","('Mawson  Lakes','15.00')","('Maylands','11.00')","('Macdonald Park','25.00')","('Mclaren Flat','33.00')","('Mclaren Vale','30.00')","('Medindie','11.00')","('Medindie Gardens','11.00')","('Melrose Park','13.20')","('Mile End','10.00')","('Mile End South','10.00')","('Millswood','11.00')","('Mitcham','12.00')","('Mitchell Park','15.00')","('Moana','33.00')","('Modbury','16.50')","('Modbury Heights','16.50')","('Modbury North','16.50')","('Montacute','20.00')","('Morphett Vale','25.00')","('Morphettville','14.00')","('Mount Lofty','21.00')","('Mount Osmond','16.50')","('Mt Barker','33.00')","('Munno Para','29.00')","('Munno Para Downs','30.00')","('Mylor','24.00')","('Myrtle Bank','11.00')","('Nailsworth','11.00')","('Nairne','34.00')","('Netherby','11.00')","('Netley','11.00')","('Newton','13.20')","('Noarlunga Centre ','25.00')","('Noarlunga Downs','29.00')","('North Adelaide','10.00')","('North Brighton','15.00')","('North Haven','18.00')","('North Plympton','12.00')","('Northfield','11.00')","('Northgate','11.00')","('Norton Summit','18.00')","('Norwood','10.00')","('Novar Gdns','12.00')");


var SuburbsOtoZ =  new Array("('Select a Suburb','',true,true)","('Oakbank','25.00')","('Oakden','12.00')","('Oaklands Park','15.00')","('O Halloran Hill','17.00')","('Old Noarlunga','29.00')","('Old Reynella','20.00')","('One Tree Hill','29.00')","('Onkaparinga Hills','25.00')","('Osborne','18.00')","('O sullivans Beach','18.00')","('Ottaway','14.00')","('Outer Harbour','18.00')","('Ovingham','11.00')","('Panorama','14.00')","('Para Hills','16.50')","('Para Hills West ','16.50')","('Para Vista','15.00')","('Paracombe','23.00')","('Paradise','13.20')","('Parafield','15.00')","('Parafield Gardens','17.00')","('Paralowie','17.00')","('Parkholme','12.00')","('Parkside','9.90')","('Pasadena','14.00')","('Payneham','11.00')","('Payneham Sth','11.00')","('Penfield','24.00')","('Penfield Gdns','29.00')","('Pennington','12.00')","('Peterhead','15.00')","('Picadilly','23.00')","('Plympton','11.00')","('Plympton Park','11.00')","('Pooraka','15.00')","('Port Adelaide','15.00')","('Port Noarlunga Sth','29.00')","('Port Norlunga','25.00')","('Prospect','10.00')","('Queenstown','14.00')","('Redwood Park','14.00')","('Regency Park','12.00')","('Renown Park','11.00')","('Reynella','19.00')","('Reynella East','19.00')","('Richmond','11.00')","('Ridgehaven','13.20')","('Ridleyton','11.00')","('Rose Park','10.00')","('Rosewater','14.00')","('Rosslyn Park','12.00')","('Rostrevor','12.00')","('Royal Park','14.00')","('Royston Park','10.00')","('Salisbury','17.00')","('Salisbury Downs','17.00')","('Salisbury East','16.50')","('Salisbury Hgts','20.00')","('Salisbury Nth','20.00')","('Salisbury Park','20.00')","('Salisbury Plains','18.00')","('Salisbury South','18.00')","('Sampson Flat','32.00')","('Scott Creek','23.00')","('Seacliff','15.00')","('Seacliff Park','15.00')","('Seacombe Hgts','15.00')","('Seacome Gdns','15.00')","('Seaford','30.00')","('Seaford Heights','30.00')","('Seaford Meadows','30.00')","('Seaford Rise','32.00')","('Seaton','14.00')","('Seaview Downs','15.00')","('Sefton Park','11.00')","('Semaphore','15.00')","('Semaphore Park','15.00')","('Semaphore South','15.00')","('Sheidow Pk','17.00')","('Skye','11.00')","('Smithfield','25.00')","('Smithfield Plains','25.00')","('Somerton Pk','14.00')","('South Brighton','15.00')","('South Plympton','11.00')","('Spring Hill','20.00')","('Springfeild','12.00')","('St Agnes','15.00')","('St Georges','11.00')","('St Kilda','21.00')","('St Marys','14.00')","('St Morris','11.00')","('St Peters','11.00')","('Stepney','11.00')","('Stirling','20.00')","('Stonyfell','11.00')","('Sturt','14.00')","('Summertown','21.00')","('Surry Downs','17.00')","('Taperoo','17.00')","('Tea Tree Gully','17.00')","('Tennyson','14.00')","('Teringie','14.00')","('The Levels','14.00')","('Thebarton','10.00')","('Thorngate','11.00')","('Toorak Gdns','11.00')","('Torrens Island','16.50')","('Torrens Park','12.00')","('Torrensville','11.00')","('Tranmere','11.00')","('Trinity Gdns','11.00')","('Trott Pk','16.50')","('Tusmore','10.00')","('Two Wells','36.00')","('Uleybury','35.00')","('Underdale','11.00')","('Unley','11.00')","('Unley Pk','11.00')","('Upper Hermatige','23.00')","('Upper Sturt','15.00')","('Uraidla','23.00')","('Urrbrae','11.00')","('Vale Park','11.00')","('Valley View','14.00')","('Verdun','23.00')","('Virgina','29.00')","('Vista ','15.00')","('Walkerville','10.00')","('Walkley Heights','12.00')","('Warradale','14.00')","('Waterfall Gully','14.00')","('Waterloo Cnr','19.00')","('Wattle Park','11.00')","('Wayville','10.00')","('Welland','11.00')","('West Beach','12.00')","('West Bourne Park','11.00')","('West Croydon','10.00')","('West Hindmarsh','11.00')","('West Lakes','14.00')","('West Lakes Shore','15.00')","('West Richmond','11.00')","('Windsor Gdns','11.00')","('Wingfield','14.00')","('Woodcroft','20.00')","('Woodforde','14.00')","('Woodside','30.00')","('Woodville','11.00')","('Woodville Gdns','12.00')","('Woodville Nth','12.00')","('Woodville Pk','11.00')","('Woodville Sth','11.00')","('Woodville West','12.00')","('Wynn Vale','16.50')","('Yatala Vale','17.00')","('Yattalunga ','30.00')");

var Hospitals =  new Array("('Select a Hospital','',true,true)","('Adelaide Clinic','8.80')","('Adelaide Day Surgery','6.60')","('Ashford Hospital','9.90')","('Blackwood Community','11.00')","('Burnside Memorial','10.00')","('Calvary','10.00')","('Central Districts','22.00')","('Flinders Medial','14.00')","('Flinders Private','14.00')","('Fullarton Private','8.80')","('Gawler Public','28.00')","('Glenelg Community Hospital','14.00')","('Glenside','8.80')","('Griffith Rehabilitation Hospital','11.00')","('Hampstead Rehabilitation Centre','9.90')","('Hillcrest Hospital','9.90')","('Hindmarsh Hospital','8.80')","('Julia Farr','8.80')","('Lyell Mc Ewin','23.00')","('Masonic Memorial','9.90')","('Memorial Hospital','10.00')","('Mitcham Rehab Clinic','8.80')","('Modbury Hospital','16.50')","('Mount Barker District Hospital','33.00')","('North Eastern Community','11.00')","('Parkwynd Private','8.80')","('Queen Elizabeth','14.00')","('Repatriation Gen','12.00')","('Reynella Sports Injury Clinic','13.50')","('Royal Adelaide','8.80')","('South Western Community','8.80')","('Southern District','20.00')","('Sports Med Hospital','9.90')","('St Andrews','7.70')","('St Margarets Hospital','11.00')","('Stirling District Hospital','14.00')","('Wakefield Hospital','8.80')","('Western Community','11.00')","('Womens and Childrens Hospital','9.90')");

var AgedCare =  new Array("('Select a Aged Care Facility','',true,true)","('Abbington Private','8.80')","('Abergeldie','11.00')","('Acacia Court','10.50')","('Adaire Private','8.80')","('Allora Nursing','9.90')","('Alwyndor Private','11.00')","('Anster Nursing','8.80')","('Ashlea Private','8.80')","('Austral Nursing','9.90')","('Bellara Nursing','8.80')","('Bellevue Nursing','12.50')","('Cabra Nursing','8.80')","('Carinya Nursing','8.80')","('Christies Beach Nursing','15.80')","('College Grove Private','8.80')","('Flora Mc Donald','8.80')","('Glendale Private','8.80')","('Gloucester Residential Care','13.20')","('Harrow Nursing Home','8.80')","('Hawthorn Nursing Home','8.80')","('Hyde Park Aged Care Facility','8.80')","('Kapara Aged Care Facility','10.70')","('Kensington Residential Care Facility','8.80')","('Kiandra  Residential Care Facility','8.80')","('Kings Park Nursing Home','8.80')","('Klemzig Aged Care Facility','9.90')","('Lewis Nursing Home','8.80')","('LHI Retirement Services','9.90')","('Marron Nursing Home','12.90')","('Martindale Nursing Home','28.00')","('Mary Potter Hospice','8.80')","('Milpara Aged Care Facility','9.90')","('Miroma Residential Care','8.80')","('Monreith Private','8.80')","('Morpeth Nursing Home','11.00')","('Noarlunga Private','18.00')","('Norwood Nursing Home','8.80')","('Onkaparinga Valley Residential Care','22.00')","('Orana Nursing Home','10.50')","('Para Hills Nursing Home','11.00')","('Perry Park Nursing','18.00')","('Playford Nursing Home','8.80')","('Queen Adelaide Private','8.80')","('Roseneath Nursing Home','8.80')","('Salisbury Private Nursing Home','12.90')","('Seaton Nursing Home','9.90')","('Semaphore Nursing Home','9.90')","('Serene Nursing Home','9.90')","('St Basils Aged Care','8.80')","('St Catherines Nursing Home','9.90')","('St Davids Cottage Respite','8.80')","('St Georges Park Nursing Home','8.80')","('St Louis Nursingn Home','8.80')","('St Martins Nursing Home','8.80')","('Strathmont Centre','9.90')","('Valley View Nursing Home','10.00')","('Walkerville Nursing Home','8.80')","('Waterworth Aged Care','10.50')","('Western Nursing Home','8.80')","('Winchester Residential Care','8.80')","('Wynwood Nursing Home','8.80')");


function RRNumberToTwoDecimalPlaces(num) {
	if(num.toFixed) {
		// browser supports toFixed()
		return num.toFixed(2);
	} else {
		var t = "";
		var n=Math.round(num*Math.pow(10, 2));
		var d;
		for (i = 0 ; i < 2 ; i++) {
			d = n%10;
			n = (n-d)/10;
			t = (d+"")+t ;
		}
		t = "." + t;
		n = n+t;
		return n;
	}
}



function RRSetDeliveryRegionMenu(regionsArray) {
	var popUpMenu = document.OrderForm.deliveryRegion;

	if(popUpMenu != null) {
	
		// set menu
		// first clear menu of excess items
		while (regionsArray.length < popUpMenu.options.length) {
			popUpMenu.options[(popUpMenu.options.length - 1)] = null;
		}
		// populate with menu items
		for (var i=0; i < regionsArray.length; i++) {
			popUpMenu.options[i]= eval("new Option"+regionsArray[i]);
		}
		
	}
	
	RRUpdateDeliveryFee("");
	
}


function RRSetDeliveryRegionsForType(regionType) {
	switch(regionType) {
	case 1:
	RRSetDeliveryRegionMenu(SuburbsAtoF);
	break;
	case 2:
	RRSetDeliveryRegionMenu(SuburbsGtoN);
	break;
	case 3:
	RRSetDeliveryRegionMenu(SuburbsOtoZ);
	break;
	case 4:
	RRSetDeliveryRegionMenu(Hospitals);
	break;
	case 5:
	RRSetDeliveryRegionMenu(AgedCare);
	break;
	default:
		// set deliveryRegion to nothings selected
		var noRegions = new Array("(' ','',true,true)");
		RRSetDeliveryRegionMenu(noRegions);
	break;
	}
}

function RRUpdateDeliveryFee(newFee) {
	document.getElementById('delivery_fee').innerHTML = '';
	if(newFee != null && newFee != "") {
	document.getElementById('delivery_fee').innerHTML = "<strong>$"+newFee+"<\strong>";
	} else {
	document.getElementById('delivery_fee').innerHTML = "-";
	}
}

function RRSubmitOrderForm(aForm) {
	
	// Validate Form
	if(MM_validateForm('Delivery_Date','','R','Delivery_Address','','R','Recipient_Name','','R','Recipient_Email','','NisEmail','Recipient_Phone','','R','Customer_Name','','R','Customer_Email_Address','','RisEmail','Customer_Address','','R','Customer_Telephone','','R')) {
		
		var orderText = RRGatherFormInformation(aForm);
		aForm.OrderInformation.value = orderText;
		
		return true;
	}
	
	return false;
}

function RRConvertToHRFieldName(inputName) {
	switch(inputName) {
		case "Delivery_Date":
		return "A delivery date";
		break;
		case "Delivery_Address":
		return "A delivery address";
		break;
		case "Recipient_Name":
		return "The recipient's name";
		break;
		case "Recipient_Email":
		return "The recipient's email address";
		break;
		case "Recipient_Phone":
		return "The recipient's telephone number";
		break;
		case "Customer_Name":
		return "The customer's name";
		break;
		case "Customer_Email_Address":
		return "The customer's email address";
		break;
		case "Customer_Address":
		return "The customer's address";
		break;
		case "Customer_Telephone":
		return "The customer's telephone number";
		break;
		default:
		return "Unknown";
		break;
	}
}


function RRGatherFormInformation(form) {
	var productPrice = parseFloat(form.ProductPrice.value);
	var productQuantity = parseInt(form.Main_Product.value);
	var productName = form.ProductName.value;
	// check that product quantitiy is greater than 0
	if(productQuantity <= 0) {
		form.Main_Product.value = 1;
		productQuantity = 1;
	}
	var orderInfo = "\n";
	
	orderInfo += "\n________ Customer Details ________\n";
	orderInfo += form.Customer_Name.value+"\n";
	if(form.Organisation.value != '') {
		orderInfo += form.Organisation.value+"\n";
	}
	orderInfo += form.Customer_Address.value+"\n\n";
	orderInfo += "Phone: "+form.Customer_Telephone.value+"\n";
	orderInfo += "Email: "+form.Customer_Email_Address.value+"\n\n";
	
	
	orderInfo += "\n________ Order Information ________\n";
	
	// Main Product
	var totalValue = productPrice*productQuantity;
	orderInfo += "$"+RRNumberToTwoDecimalPlaces(totalValue)+"\t- "+productQuantity+" x "+productName+"\n";
	
	// Extra Products
	// Wine
	var wineListValue = form.Wine.value;
	if(wineListValue != 0 && wineListValue != '0') {
		// Wine is selected
		var winePrice = RRGetPriceFromString(wineListValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(winePrice)+"\t- "+RRGetDescriptionFromString(wineListValue)+"\n";
		totalValue += winePrice;
	}
	
	// Chocolates
	var chocolatesListValue = form.Chocolates.value;
	if(chocolatesListValue != 0 && chocolatesListValue != '0') {
		var chocolatesPrice = RRGetPriceFromString(chocolatesListValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(chocolatesPrice)+"\t- "+RRGetDescriptionFromString(chocolatesListValue)+"\n";
		totalValue += chocolatesPrice;
	}
	
	// Gift Ideas
	var giftIdeasListValue = form.GiftIdeas.value;
	if(giftIdeasListValue != 0 && giftIdeasListValue != '0') {
		var giftPrice = RRGetPriceFromString(giftIdeasListValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(giftPrice)+"\t- "+RRGetDescriptionFromString(giftIdeasListValue)+"\n";
		totalValue += giftPrice;
	}
	
	// Balloons
	var balloonsListValue = form.Balloons.value;
	if(balloonsListValue != 0 && balloonsListValue != '0') {
		var balloonsPrice = RRGetPriceFromString(balloonsListValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(balloonsPrice)+"\t- "+RRGetDescriptionFromString(balloonsListValue)+"\n";
		totalValue += balloonsPrice;
	}
	
	// Soft Toys
	var softToysListValue = form.SoftToys.value;
	if(softToysListValue != 0 && softToysListValue != '0') {
		var softToysPrice = RRGetPriceFromString(softToysListValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(softToysPrice)+"\t- "+RRGetDescriptionFromString(softToysListValue)+"\n";
		totalValue += softToysPrice;
	}
	
	
	// Card
	var cardStringValue = form.Card.value;
	if(cardStringValue != 0 && cardStringValue != '0') {
		// Designer Card
		var cardPrice = RRGetPriceFromString(cardStringValue);
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(cardPrice)+"\t- "+RRGetDescriptionFromString(cardStringValue)+"\n";
		totalValue += cardPrice;
	}
	// Delivery Fee
	deliveryFee = parseFloat(form.deliveryRegion.value);
	if(deliveryFee != null && deliveryFee > 0) {
		orderInfo += "$"+RRNumberToTwoDecimalPlaces(deliveryFee)+"\t- Delivery Fee\n";
		totalValue += deliveryFee;
	}
	
	// end InnerHTML string
	orderInfo += "________\n$"+RRNumberToTwoDecimalPlaces(totalValue)+"\n\n";
	
	
	orderInfo += "Payment Type:\t"+getCheckedValue(form.Card_type)+"\n\n";
	
	orderInfo += "\n________ Recipient Details ________\n";
	orderInfo += form.Recipient_Name.value+"\n";
	orderInfo += "Phone: "+form.Recipient_Phone.value+"\n";
	if(form.Recipient_Email.value != '') {
		orderInfo += "Email: "+form.Recipient_Email.value+"\n";
	}
	orderInfo += "\n";
	
	orderInfo += "Delivery Date:\t"+form.Delivery_Date.value+"\n";
	orderInfo += "Preferred Time:\t"+form.Preferred_Delivery_Time.options[form.Preferred_Delivery_Time.selectedIndex].text+"\n\n";
	orderInfo += "Delivery Zone:\t"+form.deliveryRegion.options[form.deliveryRegion.selectedIndex].text+"\n";
	orderInfo += "Delivery Fee:\t$"+form.deliveryRegion.value+"\n\n";
	orderInfo += "Delivery Address:\n"+form.Delivery_Address.value+"\n\n";
	if(form.Special_Delivery_Instructions.value != '') {
		orderInfo += "Delivery Instructions:\n"+form.Special_Delivery_Instructions.value+"\n\n";
	}
	
	orderInfo += "\n________ Card Message ________\n";
	orderInfo += "Card Type:\t"+form.Card.options[form.Card.selectedIndex].text+"\n";
	if(form.Card_Message.value != '') {
	orderInfo += "\nCard Message:\n"+form.Card_Message.value+"\n\n";
	} else {
	orderInfo += "Card Message:\tNo card message.\n\n";
	}
	
	if(form.Comments.value != '') {
	orderInfo += "\n________ Feedback ________\n";
	orderInfo += form.Comments.value+"\n";
	}
	orderInfo += " \n \n ---------------------------------------------------";
	
	
	return orderInfo;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function RRCalculateSubTotal(form) {
	var productPrice = parseFloat(form.ProductPrice.value);
	var productQuantity = parseInt(form.Main_Product.value);
	var productName = form.ProductName.value;
	// check that product quantitiy is greater than 0
	if(productQuantity <= 0) {
		form.Main_Product.value = 1;
		productQuantity = 1;
	}
	var innerHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='2'><tr><td><strong><u>Items</u></strong></td><td width='120'><strong><u>Price</u></strong></td></tr>";
	
	// Main Product
	var totalValue = productPrice*productQuantity;
	innerHTML += "<tr><td> - "+productQuantity+" x "+productName+"</td><td>$"+RRNumberToTwoDecimalPlaces(totalValue)+"</td></tr>";
	
	// Extra Products
	// Wine
	var wineListValue = form.Wine.value;
	if(wineListValue != 0 && wineListValue != '0') {
		// Wine is selected
		var winePrice = RRGetPriceFromString(wineListValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(wineListValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(winePrice)+"</td></tr>";
		totalValue += winePrice;
	}
	
	// Chocolates
	var chocolatesListValue = form.Chocolates.value;
	if(chocolatesListValue != 0 && chocolatesListValue != '0') {
		var chocolatesPrice = RRGetPriceFromString(chocolatesListValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(chocolatesListValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(chocolatesPrice)+"</td></tr>";
		totalValue += chocolatesPrice;
	}
	
	// Gift Ideas
	var giftIdeasListValue = form.GiftIdeas.value;
	if(giftIdeasListValue != 0 && giftIdeasListValue != '0') {
		var giftPrice = RRGetPriceFromString(giftIdeasListValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(giftIdeasListValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(giftPrice)+"</td></tr>";
		totalValue += giftPrice;
	}
	
	// Balloons
	var balloonsListValue = form.Balloons.value;
	if(balloonsListValue != 0 && balloonsListValue != '0') {
		var balloonsPrice = RRGetPriceFromString(balloonsListValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(balloonsListValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(balloonsPrice)+"</td></tr>";
		totalValue += balloonsPrice;
	}
	
	// Soft Toys
	var softToysListValue = form.SoftToys.value;
	if(softToysListValue != 0 && softToysListValue != '0') {
		var softToysPrice = RRGetPriceFromString(softToysListValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(softToysListValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(softToysPrice)+"</td></tr>";
		totalValue += softToysPrice;
	}
	
	
	// Card
	var cardStringValue = form.Card.value;
	if(cardStringValue != 0 && cardStringValue != '0') {
		// Designer Card
		var cardPrice = RRGetPriceFromString(cardStringValue);
		innerHTML += "<tr><td> - "+RRGetDescriptionFromString(cardStringValue)+"</td><td>$"+RRNumberToTwoDecimalPlaces(cardPrice)+"</td></tr>";
		totalValue += cardPrice;
	}
	// Delivery Fee
	deliveryFee = parseFloat(form.deliveryRegion.value);
	if(deliveryFee != null && deliveryFee > 0) {
		innerHTML += "<tr><td> - Delivery Fee</td><td>$"+RRNumberToTwoDecimalPlaces(deliveryFee)+"</td></tr>";
		totalValue += deliveryFee;
	}
	
	// end InnerHTML string
	innerHTML += "</tr><tr><td align='right' height='28'><strong>Total (inc. GST):&nbsp;</strong></td><td><strong>$"+RRNumberToTwoDecimalPlaces(totalValue)+"</strong></td></tr></table>";
	
	RRSetSubtotalDivTag(innerHTML);
}

function RRGetDescriptionFromString(productString) {
	var cnt = productString.length;
	var desc = "";
	var foundComma = false;
	for(var i = 0; i < cnt; i++) {
		if(foundComma) {
			desc += productString.charAt(i);
		} else {
			if(productString.charAt(i) == ',') {
				foundComma = true;
			}
		}
	}
	
	return desc;

}

function RRGetPriceFromString(priceString) {
	var stringLen = priceString.length;
	var price = "";
	for(var i = 0; i < stringLen; i++) {
		if(priceString.charAt(i) == ',') {
			return parseFloat(price);
		}
		price += priceString.charAt(i);
	}
	return parseFloat(price);
}

function RRSetSubtotalDivTag(htmlString) {
	document.getElementById('subtotal').innerHTML = '';
	document.getElementById('subtotal').innerHTML = htmlString;
}





function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+RRConvertToHRFieldName(nm)+' must contain an email address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+RRConvertToHRFieldName(nm)+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+RRConvertToHRFieldName(nm)+' is required.\n'; }
  } 
  
  // Custom ones
  	if(getCheckedValue(document.OrderForm.Card_type) == "") {
		errors += '- A method of payment (credit card type) is required.\n';
	}
  	// Delivery Fee
	deliveryFee = parseFloat(document.OrderForm.deliveryRegion.value);
	if(!(deliveryFee != null && deliveryFee > 0)) {
		errors = '- A delivery fee must be calculated.\n'+errors;
	}
  
  	if (errors) {
  	 	alert('To complete your order, the following information must be specified:\n\n'+errors);
	}
	
	
  return (errors == '');
}