function verifySignup() {
var themessage = "You are required to complete the following fields: ";
if (document.calypsoSignup.fname.value=="") {
themessage = themessage + " - First Name";
}
if (document.calypsoSignup.lname.value=="") {
themessage = themessage + " -  Last Name";
}
if (document.calypsoSignup.username.value=="") {
themessage = themessage + " -  Login Name";
}
if (document.calypsoSignup.password.value=="") {
themessage = themessage + " -  Login Password";
}
if (document.calypsoSignup.email.value=="") {
themessage = themessage + " -  E-mail";
}
if (document.calypsoSignup.dob.value=="") {
themessage = themessage + " -  Date of Birth";
}
if (document.calypsoSignup.address.value=="") {
themessage = themessage + " -  Address";
}
if (document.calypsoSignup.suburb.value=="") {
themessage = themessage + " -  Suburb";
}
if (document.calypsoSignup.state.value=="") {
themessage = themessage + " -  State";
}
if (document.calypsoSignup.country.value=="") {
themessage = themessage + " -  Country";
}
if (document.calypsoSignup.postcode.value=="") {
themessage = themessage + " -  Post Code";
}
//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 (verifyEmail()==false){return false;}
	if (verifyPwd()==false){return false;}
	if (validateDate()==false) {return false;}
	document.calypsoSignup.submit();
}
else {
		alert(themessage);
		return false;
	}
}

function verifyUserName(){
	strng=document.calypsoSignup.username.value;
	if ((strng.length < 4) || (strng.length > 10)) {
		alert("The username is the wrong length.\n enter 4-10 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.calypsoSignup.password.value;
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if ((strng.length < 6) || (strng.length > 8)) {
       alert("The password is the wrong length.\n enter 6-8 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.calypsoSignup.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.calypsoSignup.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;
    } 
}


function verifyBook() {
var themessage = "You are required to complete the following fields: ";
if (document.calypsoBook.name.value=="") {
themessage = themessage + " - First Name";
}
if (document.calypsoBook.email.value=="") {
themessage = themessage + " -  E-mail";
}
if (document.calypsoBook.phone.value=="") {
themessage = themessage + " -  Phone";
}
if (document.calypsoBook.style.selectedIndex ==0) {
themessage = themessage + " -  Fishing Style";
}
if (document.calypsoBook.date.value=="") {
themessage = themessage + " -  Date";
}
if (document.calypsoBook.NoDays.value=="") {
themessage = themessage + " -  No. of Days";
}
if (document.calypsoBook.NoPeople.value=="") {
themessage = themessage + " -  No. of People";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.calypsoBook.submit();
}
else {
alert(themessage);
return false;
   }
}


function verifyContact() {
var themessage = "You are required to complete the following fields: ";
if (document.calypsoContact.name.value=="") {
themessage = themessage + " - First Name";
}
if (document.calypsoContact.email.value=="") {
themessage = themessage + " -  E-mail";
}
if (document.calypsoContact.phone.value=="") {
themessage = themessage + " -  Phone";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.calypsoContact.submit();
}
else {
alert(themessage);
return false;
   }
}
