
	function load_image(from, to) {

		document[from].src = to;	//swaps an image src with a remote url (used to show product images)

	}

	function frmsubmit(func) {
		frm = document.entryform;
		frm.func.value = func;
		frm.submit();
	}


	function update_shipping_location(element) {
		frm = element.form;			/* find this select box's form */
		frm.action = "checkout.php";		/* change the action, so it submits back to itself */
		frm.submit();			/* submit the form */
	}

	function search_by_standards(element) {

		var standard_id = element.standard_id.options[element.standard_id.selectedIndex].value;

		if (standard_id) {
			window.location = "search.php?stype=standards&standard_id=" + standard_id;
		}

	}



	function search_by_keywords(element) {

		var keyword_id = element.keyword_id.options[element.keyword_id.selectedIndex].value;

		if (keyword_id) {
			window.location = "search.php?stype=keywords&keyword_id=" + keyword_id;
		}

	}



	function check_form(element) {

			var email;
			var telephone;

			email = document.myform.Email.value;
			telephone = document.myform.Telephone.value;

				if (email.indexOf("@") == -1) {

					alert ('You must provide a valid email address');
					return false;
				}
				else {
					return true;
				}

	}


	function print_this() {
		if (window.print) window.print()
		void (null)
	}




	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_register(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');
			return false;
		}


		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.company.value, 1, 64)) {
			alert ('Please supply your company name');
			return false;
		}


		if (!is_string(form.address1.value, 1, 64) || !is_string(form.address2.value, 1, 64) || !is_string(form.postcode.value, 1, 64)) {
			alert ('Please supply your address');
			return false;
		}


	} // -- ef









	/* begin customisation checks */

	function _is_bread_change(form) {

		if (form.bread_id) {	// see if dropdown box exists first

			if (form.bread_id.options[form.bread_id.selectedIndex].value != form.default_bread_id.value) {		// see if selected option DOES NOT match that in the default_bread_id hidden field
			return true;	// bread type has been changed!
			}
			else {
			return false;	// bread type not changed
			}
		}
		else {
		return false;	// dropdown not found, therefore cannot change bread type, return false
		}

		// logic check = passed

	}



	function _is_special(form) {

		if (form.is_special.value == 1) {
		return true;
		}
		else {
		return false;
		}
	}



	function _is_special_instructions(form) {

		if (form.special_instructions) {	// see if special_instructions exists, if so continue

			if (form.special_instructions.value.length > 0) {		// check if smth. typed into the textarea
			return true;		// instructions exist!
			}
			else {
			return false;		// no intructions exists
			}
		}
		else {
		return false;	// because special_instructions wasn't even found so no special_instructions can exist!
		}

		// logic check = passed

	}



	function _is_friendly_name(form) {

		if (form.friendly_name) {	// check if friendly_name exists

			if (form.friendly_name.value.length > 0) {	// // check if smth. typed into the field
			return true;		// yes, smth typed!
			}
			else {
			return false;		// no, field is empty
			}
		}
		else {
		return false;	// because friendly_name wasn't even found, so therefore no friendly_name can exist
		}

	}





	function check_customise(form) {

		var message = "You have changed the standard options or supplied special instructions for this item, please provide an order description so we can process this item individually";

		var is_special = _is_special(form);
		var is_bread_change = _is_bread_change(form);
		var is_special_instructions = _is_special_instructions(form);
		var is_friendly_name = _is_friendly_name(form);


			/* detect config changes */

			if (is_bread_change && !is_friendly_name) {	// bread has changed
	
				alert(message);		
				form.is_configured.value = 1;
				form.friendly_name.focus();
				return false;
			}


			if (is_special_instructions && !is_friendly_name) {	// if special_instructions, but no friendly_name, then alert and stop
	
				alert(message);
				form.is_configured.value = 1;
				form.friendly_name.focus();
				return false;
			}

	} // -- ef

	/* end customisation checks */






































	/* 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 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 */




















	/* begin common library */

	function ltrim(str) {
		for (i = 0;str.charAt(i) <= " ";i++);
		return str.substring(i, str.length);
	}


	function rtrim(str) {
		for (var i = str.length-1;str.charAt(i) <= " "; i--);
		return str.substring(0, i+1);
	}


	function trim(str) {
		return ltrim(rtrim(str));
	}



	/* end common library */



















