function mtCheckBox(controlid,rowid,amount,isMealdeal) {
	// a checkbox has been selected on mealtime - update background and ongoing cost
	if (controlid.checked) {
		document.getElementById(rowid).style.backgroundColor="lightyellow";
		if (!isMealdeal) {
			iCost+=amount;	
			mtUpdateCost();	
		}	
	} else {
		document.getElementById(rowid).style.backgroundColor="white";
		if (!isMealdeal) {
			iCost-=amount;
			mtUpdateCost();	
		}
	}
	
}
function mtRadio(strRadioGroupName,amount,isMealdeal) {
	// firstly iterate through all radios - if under name strRadioGroupName then switch
	// the containing row (parentNode.parentNode) style to transparent, unless the radio
	// is selected - then make it lightyellow
	
	if (objRadioGroups[strRadioGroupName]) {
		iCost-=objRadioGroups[strRadioGroupName];		
	}
	objRadioGroups[strRadioGroupName]=amount;
	
	if (!isMealdeal) {
		iCost+=amount;
	}
	
	var inputs = document.getElementById ('mainholder').getElementsByTagName ('input');
	for (var i = 0; i < inputs.length; ++i) {
		if (inputs[i].type == 'radio' && inputs[i].name == strRadioGroupName) {
			if (!inputs[i].checked) { 
				inputs[i].parentNode.parentNode.style.backgroundColor='white';
			} else {
				inputs[i].parentNode.parentNode.style.backgroundColor='lightyellow';
			}
		}
	}
	
	if (!isMealdeal) {
		mtUpdateCost();	
	}

}
function mtUpdateCost() {
	document.getElementById('currentprice').innerHTML=mtFormatCurrency(iCost);
}
function mtSelectFillingCategory(iWhat) {
	// hide all filling categories bar IWhat
	for (i=1;i<=7;i++) {
		if (i==iWhat) {
			// change filling category table
			document.getElementById('fc' + i).style.visibility="visible";
			// change filling category link text
			document.getElementById('fc_selection' + i).style.color="black";
			document.getElementById('fc_selection' + i).style.fontWeight="bold";
			
		} else {
			document.getElementById('fc' + i).style.visibility="hidden";
			document.getElementById('fc_selection' + i).style.color="#007B5C";
			document.getElementById('fc_selection' + i).style.fontWeight="normal";			
		}
	}
	
}
function mtFormatCurrency(num) {
	// toFixed() wasnt working -converts 3.3 to £3.30 etc
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
}
function mtIsBread() {
	// returns true if some bread has been selected, false if not.
	var inputs = document.getElementById ('mainholder').getElementsByTagName ('input');
	for (var i = 0; i < inputs.length; ++i) {
		if (inputs[i].type == 'radio' && inputs[i].name == "radbread") {
			if (inputs[i].checked) { 
				return true;
			} 
		}
	}	
	return false;
}

// mealtime - shows and hides a meal
function showMeal(iWhich) {
	if (document.getElementById("mealdetails"+iWhich).style.display=="none") {
		document.getElementById("mealdetails"+iWhich).style.display="block";
		document.getElementById("link"+iWhich).innerHTML="Hide Details";
		document.getElementById("icon"+iWhich).src="images/collapse.gif";
	} else {
		document.getElementById("mealdetails"+iWhich).style.display="none";
		document.getElementById("link"+iWhich).innerHTML="Check Details";	
		document.getElementById("icon"+iWhich).src="images/expand.gif";
	}
}

// function to check if t+c are clicked, if so, submit refFrm
function checktandc(refFrm) {
	if (document.getElementById('agree').checked==false) {
		alert("You must agree to the terms and conditions first.");
		return false;
	} else {
		if (confirm('Are you sure you want to place this order?')) {
			//document.getElementById(refFrm).submit();
			return true;
		} else {
			return false;	
		}
	}

}

// used for navigation on filling selection
function fillingswitch(iID) {
	/* All filling selections are displayed in hidden divs. This function shows one of these divs whilst hiding the rest */
	var inputs = document.getElementsByTagName('div');
	for (var i = 0; i < inputs.length; i++) {
		var divname=inputs[i].id;
		if (divname.substr(0,7)=="filling") {
			if (divname.substr(8)==iID) {	
				inputs[i].style.visibility="visible";
			} else {
				inputs[i].style.visibility="hidden";
			}
		}
    }
}

function backpage() {
	document.forms[0].direction.value='-1';
	document.forms[0].submit();
} 
function nextpage() {
	document.forms[0].submit();
}

// time confirm function used for reserving time
function c(strTime) {
	if (confirm("Are you sure you wish to book your delivery for " +strTime + "?")) {
		return true;
	} else {
		return false
	}
}

