function verifySignup() {
var themessage = "You are required to complete the following fields: ";
if (document.eckSignup.fname.value=="") {
themessage = themessage + " - First Name";
}
if (document.eckSignup.lname.value=="") {
themessage = themessage + " -  Last Name";
}
if (document.eckSignup.username.value=="") {
themessage = themessage + " -  Login Name";
}
if (document.eckSignup.password.value=="") {
themessage = themessage + " -  Login Password";
}
if (document.eckSignup.email.value=="") {
themessage = themessage + " -  E-mail";
}
if (document.eckSignup.dob.value=="") {
themessage = themessage + " -  Dat of Birth";
}
if (document.eckSignup.suburb.value=="") {
themessage = themessage + " -  Suburb";
}
if (document.eckSignup.state.value=="") {
themessage = themessage + " -  State";
}
if (document.eckSignup.country.value=="") {
themessage = themessage + " -  Country";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
	if (verifyUserName()==false){return false;}
	if (verifyPwd()==false){return false;}
	if (verifyEmail()==false){return false;}
	if (validateDate()==false) {return false;}
	document.eckSignup.submit();
}
else {
		alert(themessage);
		return false;
	}
}

function verifyUserName(){
	strng=document.eckSignup.username.value;
	if ((strng.length < 6) || (strng.length > 15)) {
		alert("The username is the wrong length.\n enter 6-15 characters");
		return false;
	}
	var illegalChars = /\W/;
	// allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       alert("The username contains illegal characters.\n enter only letters, numbers, and underscores");
	   return false;
    } 
return true;
}

function verifyPwd(){
	strng=document.eckSignup.password.value;
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if ((strng.length < 6) || (strng.length > 15)) {
       alert("The password is the wrong length.\n enter 6-15 characters");
	   return false;
    }
    else if (illegalChars.test(strng)) {
      alert("The password contains illegal characters.\n enter only letters and numbers");
	  return false;
    }
return true;
}

function verifyEmail() {
	strng=document.eckSignup.email.value;
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
    alert("Please enter a valid email address.\n");
	return false;
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   alert("The email address contains illegal characters.\n");
	   return false;
	}
return true;
}

function validateDate() {
	var fld=document.eckSignup.dob.value;
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    var errorMessage = "Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. 30/2/2000 would not be accepted.\nFormat dd/mm/yyyy.";
    if ((fld.match(RegExPattern)) && (fld != '')) {
        return true; 
    } else {
        alert(errorMessage);
        return false;
    } 
}
