function checkform()
	{
	if (document.getElementById("email").value == null || document.getElementById("email").value == "")
		{
		window.alert("Please enter a valid email address and try again.");
		showlayer('account');
		document.getElementById("email").className="formerror";
		document.getElementById("email").focus();
		return false;
		}
	else
		{
		document.getElementById("email").className="null";
		}
	if (!checkemail())
		{
		return false;
		}
	if (document.getElementById("password").value == null || document.getElementById("password").value == "")
		{
		window.alert("Please enter a password and try again.");
		showlayer('account');
		document.getElementById("password").className="formerror";
		document.getElementById("password2").className="formerror";
		document.getElementById("password").focus();
		return false;
		}
	else
		{
		document.getElementById("password").className="null";
		document.getElementById("password2").className="null";
		}
	if (!checkpasswordlength())
		{
		return false;
		}
	if (!checkpassword())
		{
		return false;
		}
	if (document.getElementById("propflag").checked)
		{
		if (document.getElementById("firstnamep").value == null || document.getElementById("firstnamep").value == "")
			{
			window.alert("Please enter the proposers first name and try again.");
			showlayer('account');
			document.getElementById("firstnamep").className="formerror";
			document.getElementById("firstnamep").focus();
			return false;
			}
		else
			{
			document.getElementById("firstnamep").className="null";
			}
		if (document.getElementById("surnamep").value == null || document.getElementById("surnamep").value == "")
			{
			window.alert("Please enter the proposers surname and try again.");
			showlayer('account');
			document.getElementById("surnamep").className="formerror";
			document.getElementById("surnamep").focus();
			return false;
			}
		else
			{
			document.getElementById("surnamep").className="null";
			}
		}
	if (document.getElementById("answer").value == null || document.getElementById("answer").value == "")
		{
		window.alert("Please enter the answer to your security and try again.");
		showlayer('account');
		document.getElementById("answer").className="formerror";
		document.getElementById("answer").focus();
		return false;
		}
	else
		{
		document.getElementById("answer").className="null";
		}
	if (document.getElementById("firstname").value == null || document.getElementById("firstname").value == "")
		{
		window.alert("Please enter your first name and try again.");
		showlayer('testator');
		document.getElementById("firstname").className="formerror";
		document.getElementById("firstname").focus();
		return false;
		}
	else
		{
		document.getElementById("firstname").className="null";
		}
	if (document.getElementById("surname").value == null || document.getElementById("surname").value == "")
		{
		window.alert("Please enter your surname and try again.");
		showlayer('testator');
		document.getElementById("surname").className="formerror";
		document.getElementById("surname").focus();
		return false;
		}
	else
		{
		document.getElementById("surname").className="null";
		}
	if (document.getElementById("dobday").selectedIndex == 0)
		{
		window.alert("Please enter your date of birth and try again.");
		showlayer('testator');
		document.getElementById("dobday").className="formerror";
		document.getElementById("dobday").focus();
		return false;
		}
	else
		{
		document.getElementById("dobday").className="null";
		}
	if (document.getElementById("dobmonth").selectedIndex == 0)
		{
		window.alert("Please enter the your month of birth and try again.");
		showlayer('testator');
		document.getElementById("dobmonth").className="formerror";
		document.getElementById("dobmonth").focus();
		return false;
		}
	else
		{
		document.getElementById("dobmonth").className="null";
		}
	if (document.getElementById("dobyear").value == null || document.getElementById("dobyear").value == "" || document.getElementById("dobyear").value < 1890 || document.getElementById("dobyear").value > 2006)
		{
		window.alert("Please enter a valid year of birth (four digits) and try again.");
		showlayer('testator');
		document.getElementById("dobyear").className="formerror";
		document.getElementById("dobyear").focus();
		return false;
		}
	else
		{
		document.getElementById("dobyear").className="null";
		}
	return true;
	}

function showlayer(layer)
	{
	document.getElementById("account").style.display="none";
	document.getElementById("testator").style.display="none";
	document.getElementById("will").style.display="none";
	document.getElementById("living").style.display="none";
	document.getElementById("deeds").style.display="none";
	document.getElementById("att").style.display="none";
	document.getElementById(layer).style.display="block";
	}

function proposer(showalert)
	{
	// displays the 'proposer' section of the form and disclaimer if the proposer checkbox is ticked
	if (document.getElementById("propflag").checked)
		{
		if (showalert)
			{
			window.alert("Although Will Registry UK does allow you to register on behalf of another person, you MUST obtain their express permission first!\n\nPlease do not proceed any further until you have sought and obtained permission from the testator (author of the will).");
			}
		document.getElementById("proposer").style.display="block";
		}
	else
		{
		document.getElementById("proposer").style.display="none";
		}
	}

function showhide(id1, id2, setvalue)
	{
	// shows/hides element "id1" according to whether drop-down box "id2" has particular value "setvalue"
	var element1 = document.getElementById(id1);
	var element2 = document.getElementById(id2);
	if (element2[element2.selectedIndex].value == setvalue)
		{
		element1.className='show';
		}
	else
		{
		element1.className='hidden';
		}
	}

function checkemail()
	{
	// checks the email address entered on the form
	if (document.getElementById("email").value)
		{
		if (!echeck(document.getElementById("email").value))
			{
			window.alert("The email address you entered does not appear to be valid. A valid address is needed to activate your account.");
			document.getElementById("email").className="formerror";
			document.getElementById("email").focus();
			return false;
			}
		else
			{
			document.getElementById("email").className="null";
			}
		}
	return true;
	}

function checkpassword()
	{
	if (document.getElementById("password").value != document.getElementById("password2").value)
		{
		window.alert("Your passwords do not match. Please retype your password carefully in each box.");
		showlayer('account');
		document.getElementById("password").className="formerror";
		document.getElementById("password2").className="formerror";
		document.getElementById("password2").focus();
		return false;
		}
	else
		{
		document.getElementById("password").className="null";
		document.getElementById("password2").className="null";
		}
	return true;
	}

function checkpasswordlength()
	{
	if ((document.getElementById("password").value.length < 4) || (document.getElementById("password").value.length > 11))
		{
		window.alert("Please enter a password between 4 and 12 characters long.");
		showlayer('account');
		document.getElementById("password").className="formerror";
		document.getElementById("password2").className="formerror";
		document.getElementById("password").focus();
		return false;
		}
	else
		{
		document.getElementById("password").className="null";
		document.getElementById("password2").className="null";
		}
	return true;
	}

function echeck(str)
	{
	// determines whether a supplied string is a valid email address or not
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
		{
		return false;
		}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		return false;
		}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		return false;
		}
	 if (str.indexOf(at,(lat+1))!=-1)
	 	{
	 	return false;
	 	}
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 	{
	 	return false;
	 	}
	 if (str.indexOf(dot,(lat+2))==-1)
	 	{
	 	return false;
	 	}
	 if (str.indexOf(" ")!=-1)
	 	{
	 	return false;
	 	}
	return true					
	}
function popuphelp(id)
	{
	var url = "/popup.php?id=" + id;
	window.open(url, 'Help','width=200,height=300,scrollbars=auto,resizable=1,toolbars=0,statusbar=0');
	}
