
	function popup(url) {
		window.open(url,'refund_policy','status=yes,resizable=yes,scrollbars=yes,width=450,height=550');
	}

	function print_this() {
		if (window.print) window.print()
		void (null)
	}

	function pop_add_food() {
		window.open('add_food.php','add_food','status=yes,resizable=yes,scrollbars=yes,width=415,height=475');
	}

	function pop_meals_all() {
		window.open('meals_all.php','meals_all','status=yes,resizable=yes,scrollbars=yes,width=620,height=450');
	}

	function check_email(form) {

		if (is_email(form.email.value)) {

			return true;
		}
		else {
			alert ('You must provide a valid email address');
			return false;
		}

	} // -- ef

	function check_min_meals(f, min_meals) {

		/* function specialised to handle PHP's way of using element groups submitted as an array */

		var chkbox = f.elements['meal_id[]'];
		var noneChecked = true;
		var counter = 0;

		if (typeof chkbox.length == 'undefined') {
			/* there's only one checkbox on the form, normalize it to an array/collection */
			chkbox = new Array(chkbox);
		}

		for (var i = 0; i < chkbox.length; i++) {
			
			if (chkbox[i].checked) {
				counter = counter + 1;
			}
		}

		if (counter < min_meals) {
			alert('Please select at least ' + min_meals + ' meals');
			return false;
		} else {
			return true;
		}

	} // -- ef


	
	function toggle(element) {

			for (i = 0; i < element.length; i++) {

				if (element[i].style.display == 'none') {
					var status = '';
				} else {
					var status = 'none';
				}

			element[i].style.display = status;
			}

	}

	function favoriteDelete() {
		
		var answer = confirm('This action will remove this meal from "Favourite meal"!\n Are you sure to remove it?');
		if(answer) {
			document.frm_meal_page.action.value = "removeFavorite";
			return true;
		}
		else {
			return false;
		}
	}

	function addFavorite() {
		document.frm_meal_page.action.value = "addFavorite";
		return true;

	}
	
	


















	function check_login(form) {

		if (is_string(form.username.value, 1, 32) && is_string(form.password.value, 1, 32)) {

			return true;
		}
		else {
			alert('Please enter a username and password');
			return false;
		}

	}



	/* end validation library */






	function check_register(form) {


		if (!is_string(form.firstname.value, 1, 32)) {
			alert ('Please supply your firstname');
			return false;
		}

		if (!is_string(form.surname.value, 1, 32)) {
			alert ('Please supply your surname');
			return false;
		}


		if (!is_string(form.address.value, 1, 256)) {
			alert ('Please supply your full address');
			return false;
		}


		if (!is_string(form.telephone.value, 8, 32)) {
			alert ('Please supply your telephone number');
			return false;
		}


		if (!is_email(form.email.value)) {
			alert ('Please supply a valid email address');
			return false;
		}


		if (!is_string(form.dob.value, 10, 10)) {
			alert ('Please supply your full date of birth (DD/MM/YYYY)');
			return false;
		}



		if (!is_string(form.height.value, 1, 5)) {
			alert ('Please supply your height in centimetres');
			return false;
		}


		if (!is_string(form.weight.value, 1, 5)) {
			alert ('Please supply your weight in kilograms');
			return false;
		}


		if (!is_string(form.bodyfat_perc.value, 1, 5)) {
			alert ('Please supply your body fat percentage');
			return false;
		}


		if (!is_string(form.username.value, 5, 16)) {
			alert ('Username must be between 5 and 16 characters');
			return false;
		}

		if (!is_string(form.password.value, 5, 16)) {
			alert ('Password must be between 5 and 16 characters');
			return false;
		}


		if (form.password.value != form.password_confirm.value) {
			alert ('Passwords do not match - please re-enter them');
			return false;
		}


	} // -- ef












	function check_reg_one(form) {

		if (!is_string(form.firstname.value, 1, 32)) {
			alert ('Please supply your firstname');
			return false;
		}

		if (!is_string(form.surname.value, 1, 32)) {
			alert ('Please supply your surname');
			return false;
		}

		if (!is_string(form.address.value, 1, 256)) {
			alert ('Please supply your full address');
			return false;
		}

		if (!is_string(form.postcode.value, 2, 10)) {
			alert ('Please supply your postcode');
			return false;
		}

		if (!is_string(form.telephone.value, 4, 32)) {
			alert ('Please supply your telephone number');
			return false;
		}

		if (!is_email(form.email.value)) {
			alert ('Please supply a valid email address');
			return false;
		}

	} // -- ef





	function check_reg_two(form) {

		if (!is_string(form.dob.value, 10, 10)) {
			alert ('Please complete your date of birth in the correct format - DD/MM/YYYY');
			return false;
		}

		if (!is_string(form.height.value, 1, 5)) {
			alert ('Please supply your height');
			return false;
		}
		
		if (!is_integer(form.height.value, 1, 5)) {
			alert ('Please supply numeric height');
			return false;
		}

		if (!is_string(form.weight.value, 1, 5)) {
			alert ('Please supply your weight');
			return false;
		}
		
		if (!is_integer(form.weight.value, 1, 5)) {
			alert ('Please supply numeric weight');
			return false;
		}

		if (!is_string(form.bodyfat_perc.value, 1, 5)) {
			alert ('Please supply your body fat percentage');
			return false;
		}

		if (!is_integer(form.bodyfat_perc.value, 1, 5)) {
			alert ('Please supply numeric body fat');
			return false;
		}

	} // -- ef




	function check_reg_three(form) {

		if (!is_string(form.username.value, 5, 16)) {
			alert ('Username must be between 5 and 16 characters');
			return false;
		}

		if (!is_string(form.password.value, 5, 16)) {
			alert ('Password must be between 5 and 16 characters');
			return false;
		}


		if (form.password.value != form.password_confirm.value) {
			alert ('Passwords do not match - please re-enter them');
			return false;
		}

	} // -- ef



	function check_reg_four(form) {

		/*
		var msg;
		msg = "You will now be taken to our secure WorldPay account page where you can enter payment details and complete the registration process.";
		alert(msg);
		*/

	} // -- ef


	function check_renew_one(form) {

		/*
		var msg;
		msg = "You will now be taken to our secure WorldPay account page where you can enter payment details and complete the registration process.";
		alert(msg);
		*/

	} // -- ef


	function check_renew_two(form) {

		/*
		var msg;
		msg = "You will now be taken to our secure WorldPay account page where you can enter payment details and complete the registration process.";
		alert(msg);
		*/

	} // -- ef


/* begin validation library -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */


	function is_email(str) {

		if (str.indexOf("@") == -1) {
		return false;
		} else {
		return true;
		}
	}


	function is_string(str, min_length, max_length) {

		if (str.length >= min_length && str.length <= max_length) {
		return true;
		} else {
		return false;
		}
	}

	function is_integer(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		 return true;
	}

	function is_date(str) {

		var date_array;
		var d, m, y;


		if (!is_string(str, 6, 10)) {		// check if a string has been entered
		return false;
		} else {

			date_array = str.split("/");

			d	= parseInt(date_array[0]);
			m	= parseInt(date_array[1]);
			y	= parseInt(date_array[2]);

			if (d < 1 && d > 31) {	// simply check for day range
			return false;
			}

			if (m < 1 && m > 12) {	// simply check for month range
			return false;
			}


			if (y < 1900) {		// add 1900 if year is supplied in two digits
				y = y + 1900;
			}
			
			if (y < 1900) {		// is valid year
			return false;
			}

			return true;
		}




			/*

			if (d >= 1 && d <= 31) {
			return false;
			}

	
			if (m >= 1 && m =< 12) {
			return false;
			}

			if (y > 1900) {
			return false;
			}
			*/

	}

/* end validation library -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */





