	var expires_date = new Date();  // current date & time
	expires_date.setDate(expires_date.getDate() +31); // add a month
	expires_date = expires_date.toUTCString();
	var expires=" expires="+expires_date+";";

	function get_cookie ( cookie_name ) {
	  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	  if ( results )
		return ( unescape ( results[2] ) );
	  else
		return null;
	}

	function read_cookies () {
	
		var name = get_cookie ( "name" );
		var phone = get_cookie ( "phone" );
		var email = get_cookie ( "email" );
		var remember = get_cookie ( "remember" );

		if (name) { document.getElementById('name').value = name; }
		if (phone) { document.getElementById('phone').value = phone; }
		if (email) { document.getElementById('email').value = email; }
		if (remember && (name || email)) { document.getElementById('remember').checked = true; }

	}
	
	function delete_cookie ( cookie_name ) {
		var cookie_date = new Date();
		cookie_date.setTime ( cookie_date.getTime() - 1 );
		document.cookie = cookie_name += "=; expires=" + cookie_date.toUTCString();
	}

	function writeprice(id) {
		string = prices[id].toFixed(2);
		if (string.length == 3) {
			string = '0'+string; // if it's less than a pound
		}
		return string;
	}

	function totaltext(number) {
		total = parseFloat(total);
		total = total.toFixed(2);
		totalstring = total+'';
		if (totalstring.length == 3) {
			totalstring = '0'+totalstring; // if it's less than a pound
		}
		document.getElementById('total').innerHTML = '&pound;'+totalstring;
		document.getElementById('toptotal').innerHTML = '&pound;'+totalstring;
	}
	
	function add(id) {
		quantities[id] ++;
		total = parseFloat(total);
		total += prices[id];
		document.getElementById('quantity'+id).innerHTML = 'x'+quantities[id]+' <a onClick="javascript:remove('+id+');return false;">&nbsp;remove&nbsp;<\/a>';
		document.getElementById('item'+id).className = 'selected';
		totaltext(total);
	}

	function remove(id) {
		if (quantities[id] > 0) {
			quantities[id] --;
			total = parseFloat(total);
			total -= prices[id];
			if (quantities[id] == 0) {
				document.getElementById('quantity'+id).innerHTML = '';
				document.getElementById('item'+id).className = '';
			} else {
				document.getElementById('quantity'+id).innerHTML = 'x'+quantities[id]+' <a onClick="javascript:remove('+id+');return false;">&nbsp;remove&nbsp;<\/a>';
			}
			totaltext(total);
		}
	}
	
	function checkout() { // done in order of irritation (e.g. no point getting people to input a valid email address if it's already past 11am)
	
		// did you order anything?
		if (total == 0) {
			alert('You haven\'t ordered anything!');
			return false;
		}
		
		// time check
		var currenttime=new Date();
		Hours = currenttime.getHours();
		if (Hours > 11 && !(debug)) {
			alert('Unfortunately, your order must be in before 11am.\n\nSorry!');
			return false;
		} else if (Hours == 11 && !(debug)) {
			alert('Unfortunately, your order must be in before 11am.\n\nIf you\'ve only just missed the deadline, you can try phoning it in (0141 334 7626).');
			return false;
		}
		
		// is the email address valid?
		email = document.getElementById('email').value;
		if ((email.indexOf('@') == -1) || (email.indexOf('@') == -1)) {
			alert('You must enter a valid email address so we can send you confirmation of your order');
			return false;
		}
		
		// other details
		name = document.getElementById('name').value;
		phone = document.getElementById('phone').value;
		if ((name == "") || (name == null) || (phone = "") || (phone == null)) {
			alert('You must enter both your name and telephone number or we won\'t be able to stalk you after hours');
			return false;
		}
		
		// if everything's correct, write the hidden form variable
		ordertext = '';
		count = 0;
		for (count=0;count<categories.length;count++) {
			if (quantities[count] > 0) {
				ordertext += categories[count]+': '+quantities[count]+'x '+titles[count]+'\n';
			}
		}
		
		// write some cookies (mmmm, cookies)
		if (document.getElementById('remember').checked) {
			document.cookie = "remember=1;"+expires;
			document.cookie = "name="+escape(document.getElementById('name').value)+";"+expires;
			document.cookie = "phone="+escape(document.getElementById('phone').value)+";"+expires;
			document.cookie = "email="+escape(document.getElementById('email').value)+";"+expires;
		} else {
			delete_cookie ( "name" );
			delete_cookie ( "phone" );
			delete_cookie ( "email" );
			delete_cookie ( "remember" );
		}

		ordertext += '\nTotal to pay = £'+totalstring;
		
		document.getElementById('ordertext').value = ordertext;
		document.getElementById('formtotal').value = totalstring;
		return true;
	}
