
// ************************************** Forms
function checkForm(frm) {
   	// emails address - max length 80
	frm.emailAddress.required = true;
	frm.emailAddress.requiredError = 'Email address required.';
	frm.emailAddress.pattern = 'email';
	frm.emailAddress.patternError = 'The email address entered is not valid.';
	frm.emailAddress.maxlength = 80;
	frm.emailAddress.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	

	// first name - max length 100
	frm.firstName.required = true;
	frm.firstName.requiredError = 'First name required.';
	frm.firstName.maxlength = 100;
	frm.firstName.maxlengthError = 'Our systems do not allow first names longer than 100 characters.';
	
	// lastname - max length 100
   frm.lastName.required = true;
   frm.lastName.requiredError = 'Last name required.';
   frm.lastName.maxlength = 100;
   frm.lastName.maxlengthError = 'Our systems do not allow last names longer than 100 characters.';
   
   //landline number - max length 35
   frm.contactNo.required = true;
   frm.contactNo.requiredError = 'Contact number required.';
   frm.contactNo.maxlength = 35;
   frm.contactNo.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';
   

  // departing from - max length 100
   frm.departingFrom.required = true;
   frm.departingFrom.requiredError = 'Departing from required.';
   frm.departingFrom.maxlength = 100;
   frm.departingFrom.maxlengthError = 'Our systems do not allow departure points longer than 100 characters.';
   
   // travelling to - max length 100
   frm.lastName.required = true;
   frm.lastName.requiredError = 'Travelling to required.';
   frm.lastName.maxlength = 100;
   frm.lastName.maxlengthError = 'Our systems do not allow travel points longer than 100 characters.';
   
   // departure date - max length 100
   frm.departureDate.required = true;
   frm.departureDate.requiredError = 'Departure Date required.';
   frm.departureDate.maxlength = 20;
   frm.departureDate.maxlengthError = 'Our systems do not allow departure dates longer than 100 characters.';
   
   // return date - max length 100
   frm.returnDate.required = true;
   frm.returnDate.requiredError = 'Return from required.';
   frm.returnDate.maxlength = 20;
   frm.returnDate.maxlengthError = 'Our systems do not allow return dates longer than 100 characters.';
   
   var errors = getFormErrors(frm);
   
   if (errors.length > 0) {
      var errorMessage = 'The following information was missing or incomplete' + ((errors.length > 1) ? 's' : '') + ':\n\n';
      for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) {
         errorMessage += '* ' + errors[errorIndex] + '\n';
      }
      errorMessage += '\nPlease correct ' + ((errors.length > 1) ? 'these' : 'this') + ' problem' + ((errors.length > 1) ? 's' : '') + ' and try again.';
      alert(errorMessage);
      return false;
   }
   // no errors: return true
   return true;
}

// ************************************** Newsletter

function checkNewsletter(frm) {
	var debug = false;
	
	if (debug)
	{
		alert("in checkNewsletter function");
	}
	
   	// emails address - max length 80
	frm.email.required = true;
	frm.email.requiredError = 'Email address required.';
	frm.email.pattern = 'email';
	frm.email.patternError = 'The email address entered is not valid.';
	frm.email.maxlength = 80;
	frm.email.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	//confirmation email address - max lenght 80
	frm.confirm_email.required = true;
	frm.confirm_email.requiredError = 'Confirmation Email Address Required';
	frm.confirm_email.pattern = 'email';
	frm.confirm_email.patternError = 'Confirmation Email Address entered is not valid';
	frm.confirm_email.maxlength = 80;
	frm.confirm_email.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// first name - max length 100
	frm.firstname.required = true;
	frm.firstname.requiredError = 'First name required.';
	frm.firstname.maxlength = 100;
	frm.firstname.maxlengthError = 'Our systems do not allow first names longer than 100 characters.';
	
	// lastname - max length 100
   frm.lastname.required = true;
   frm.lastname.requiredError = 'Last name required.';
   frm.lastname.maxlength = 100;
   frm.lastname.maxlengthError = 'Our systems do not allow last names longer than 100 characters.';
   
   //Cell number - max length 35
   frm.cellnumber.required = true;
   frm.cellnumber.requiredError = 'CellPhone number required.';
   frm.cellnumber.maxlength = 35;
   frm.cellnumber.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';
   
   //Landline number - max length 35
   frm.landlinenumber.required = true;
   frm.landlinenumber.requiredError = 'Landline number required.';
   frm.landlinenumber.maxlength = 35;
   frm.landlinenumber.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';
   
   	//dateofbirth
   frm.dateofbirth.required = true;
   frm.dateofbirth.requiredError = 'Date of Birth required.';
   frm.dateofbirth.minlength = 10;
   frm.dateofbirth.minlengthError = 'Date of Birth to short.';
   frm.dateofbirth.maxlength = 10;
   frm.dateofbirth.maxlengthError = 'Date of Birth to long.';
   /**
   //postal address
   frm.postaladdress.required = true;
   frm.postaladdress.requiredError = 'Postal Address required.';
   frm.postaladdress.maxlength = 150;
   frm.postaladdress.maxlengthError = 'Our systems do not allow Addresses longer than 150 characters.';
 	**/
	
	var post = "";
   post = checkdpostal();
   
 var errors = getFormErrors(frm);	 
	 
	 // compare email addresses
	 if((frm.email.value != frm.confirm_email.value)&&(frm.confirm_email.value != '')){
	   	errors[errors.length] = 'The Email Addreses do not match';	
	   }
	   
   if (errors.length > 0|| post != "") {
      var errorMessage = 'The following information was missing or incomplete' + ((errors.length > 1) ? 's' : '') + ':\n\n';
	   
      for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) {
         errorMessage += '* ' + errors[errorIndex] + '\n';
      }
	  errorMessage += post;
      errorMessage += '\nPlease correct ' + ((errors.length > 1) ? 'these' : 'this') + ' problem' + ((errors.length > 1) ? 's' : '') + ' and try again.';
      alert(errorMessage);
      return false;
   }
   
   // no errors: return true
   return true;
}

// ************************************** Newsletter



