function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

  function validateEmail(sEmail) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(sEmail)) {
      return true;
    } else {
      alert("Invalid email address.  Please re-enter.");
      return false;
    }
  }
		
		function checkSessionValid() {
			  if (getCookie("ApplicationRef") == null) {
		  alert("We're sorry but you do not have a valid session.\nThis can be caused by a number of things:\n - The application form has been left unattended for a long period of time\n - You have completed the application and have since pressed the back button to modify your details\n - You have cookies disabled in your browser\n - You have attempted to skip parts of the application form\n\nIf you have any further queries please call us on our 24 hour helpline: 0800 38 77 17\n\nYou will now be redirected to the start of the application form.");
				location = "/funeralplans/apply/";
		}

		}