var ERR_LOGON_FORMNOTFOUND = 1001;
var ERR_LOGON_ELEMENTNOTFOUND = 1002;

var ERR_LOGON_EMPTYFIRSTNAME = 1003;
var ERR_LOGON_EMPTYLASTNAME = 1004;
var ERR_LOGON_EMPTYDATEOFBIRTH = 1005;


function startform_submit()
{
	var f = document.forms["startform"];
	var errorMessage = "";

	/* now uses bpDateEdit element so no longer need validation */
	//if(check_Logon_DateOfBirth())
	//	errorMessage += "\nThe date of birth you entered is not valid. It must be in the format DD/MM/YYYY.\n";

	if(check_Logon_FirstName() || check_Logon_LastName())
		errorMessage += "\nEither first or last name is missing. You must enter both a first and last name to start.\n";

	if(check_Logon_DateOfBirth())
		errorMessage += "\nYou must enter a valid date of birth. Click on the calendar icon to choose your date of birth.\n";

	if(errorMessage != '')
		alert("The following problems were found in your logon details:\n\n" + errorMessage);
	else
		f.submit();
}



/*
** @brief Checks that the First Name field has been completed
** for logging on.
**
** @return 0 if the first name is present, or one of
** the error constants ERR_EMPTYFIRSTNAME.
*/
function check_Logon_FirstName()
{
	var f = document.forms["startform"];
	if(!f) return ERR_LOGON_FORMNOTFOUND;
	var e = f.elements["LogonFirstName"];
	if(!e) return ERR_LOGON_ELEMENTNOTFOUND
	
	//	alert("First Name = " + v);

	var v = e.value;
	//	alert("Last Name = " + v);
	if(v.replace(" ", "") == "") return ERR_LOGON_EMPTYLASTNAME;
	
	return 0;
}



/*
** @brief Checks that the Last Name field has been completed
** for logging on.
**
** @return 0 if the last name is present, or one of
** the error constants ERR_EMPTYLASTNAME.
*/
function check_Logon_LastName()
{
	var f = document.forms["startform"];
	if(!f) return ERR_LOGON_FORMNOTFOUND;
	var e = f.elements["LogonLastName"];
	if(!e) return ERR_LOGON_ELEMENTNOTFOUND

	var v = e.value;
	//	alert("Last Name = " + v);
	if(v.replace(" ", "") == "") return ERR_LOGON_EMPTYLASTNAME;

	return 0;
}



/**
 * @brief Checks whether the logon DOB is valid.
 *
 * @return 0 if the content is valid, or one of the
 * error constants ERR_EMPTYDATE, ERR_INVALIDDATE
 * otherwise.
 */
function check_Logon_DateOfBirth()
{
	var f = document.forms["startform"];
	if(!f) return ERR_LOGON_FORMNOTFOUND;
	var e = f.elements["LogonDateOfBirth"];
	if(!e) return 0; 	/* if element not present we're not using DoB to logon */
	if(e.value == "") return ERR_LOGON_EMPTYDATEOFBIRTH ;
	return 0;
}

