function findmonth(field) {
	var months;
	
	for (var m=1; m<=12; m++) {
		if (field.value == monthtext[m]) {
			months = m;
			break;
		}
	}
	return (months);
}

function checkdate() {
	var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
	var dateErrors = "";
	
	var departday=document.getElementById('departday')
	var departmonth=document.getElementById('departmonth')
	var departyear=document.getElementById('departyear')

	var returnday=document.getElementById('returnday')
	var returnmonth=document.getElementById('returnmonth')
	var returnyear=document.getElementById('returnyear')
	
	var today=new Date();
	var day = today.getDate();
	var month = today.getMonth();
	var year = today.getFullYear();
	
	try {
		if(parseInt(departyear.value) >= parseInt(year)) {
			if (findmonth(departmonth) >= month) {
					if (departday.value >= day) {
						
				} else 	dateErrors += "* Your departure day is incorrect \n";
			} else dateErrors += "* Your departure month is incorrect \n";			
		} else dateErrors += "* Your departure year is incorrect \n";	
	} catch (e) {}
	
	try {
	if (returnyear.value != "N/A" && returnmonth.value != "N/A" && returnday.value != "N/A")
		if(parseInt(returnyear.value) >= parseInt(departyear.value)) {
			if (parseInt(findmonth(returnmonth)) >= parseInt(findmonth(departmonth))) {	
				if (parseInt(returnday.value) >= parseInt(departday.value)) {

				} else dateErrors += "* Your return day is incorrect \n";
			} else dateErrors += "* Your return month is incorrect \n";
		} else dateErrors += "* Your return year is incorrect \n";
	} catch (e) {}
	
	return (dateErrors);
}

function checkdpostal() {
	
	var PostalErrors = "";
	
	var postaladdress=document.getElementById('postaladdress')
	
	try {
		if (postaladdress.value == "select") {
			PostalErrors += "* Please select where you live \n";
		}
		}catch (e) {}
		
	
	return (PostalErrors);
}
	
// ************************************** EmailUs
function checkEmailUs(frm) {
   	// emails address - max length 80
	frm.from.required = true;
	frm.from.requiredError = 'Email address required.';
	frm.from.pattern = 'email';
	frm.from.patternError = 'The email address entered is not valid.';
	frm.from.maxlength = 80;
	frm.from.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// title
	frm.title.disallowEmptyValue = true;
	frm.title.disallowEmptyValueError = 'Title required.';
	
	// 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.';
   
   //phone number - max length 35
   frm.landline.required = true;
   frm.landline.requiredError = 'Phone number required.';
   frm.landline.pattern = 'numeric';
   frm.landline.patternError = 'Invalid phone number.';
   frm.landline.maxlength = 35;
   frm.landline.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';

   //postcode - min length 5, max 9
   frm.postcode.required = true;
   frm.postcode.requiredError = 'Post Code is required.';
   frm.postcode.minlength = 4;
   frm.postcode.minlengthError = 'Post Code is too short.';
   frm.postcode.maxlength = 8;
   frm.postcode.maxlengthError = 'Post Code is too long.';
   
   // subject line removed 20/01/05 kf
   //frm.subject.required = true;
   //frm.subject.requiredError = 'Choose what your query relates to.';
   
   // free text - max length 5000
   frm.message.required = true;
   frm.message.requiredError = 'Please enter your query.';
   frm.message.maxlength = 5000;
   frm.message.maxlengthError = 'Our systems do not allow messages longer than 5000 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;
}

// ************************************** Groups
function checkGroups(frm) {
   	// emails address - max length 80
	frm.from.required = true;
	frm.from.requiredError = 'Email address required.';
	frm.from.pattern = 'email';
	frm.from.patternError = 'The email address entered is not valid.';
	frm.from.maxlength = 80;
	frm.from.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// title
	frm.title.disallowEmptyValue = true;
	frm.title.disallowEmptyValueError = 'Title required.';
	
	// 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.';
   
   //phone number - max length 35
   frm.phonenumber.required = true;
   frm.phonenumber.requiredError = 'Phone number required.';
   frm.phonenumber.pattern = 'numeric';
   frm.phonenumber.patternError = 'Invalid phone number.';
   frm.phonenumber.maxlength = 35;
   frm.phonenumber.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';

   //postcode - min length 5, max 9
   frm.postcode.required = true;
   frm.postcode.requiredError = 'Post Code is required.';
   frm.postcode.minlength = 4;
   frm.postcode.minlengthError = 'Post Code is too short.';
   frm.postcode.maxlength = 8;
   frm.postcode.maxlengthError = 'Post Code is too long.';
   
   	// nature of trip
	frm.triptype.disallowEmptyValue = true;
	frm.triptype.disallowEmptyValueError = 'Please specify the nature of the trip.';
   
   // group type
   // frm.elements['grouptype'][0].required = true;
   // frm.elements['grouptype'][0].requiredError = 'Please specify the group type.';
      
   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;
}

// ************************************** DealEnquiry

function checkDealEnquiry(frm) {
   	// emails address - max length 80
	frm.from.required = true;
	frm.from.requiredError = 'Email address required.';
	frm.from.pattern = 'email';
	frm.from.patternError = 'The email address entered is not valid.';
	frm.from.maxlength = 80;
	frm.from.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// title
	frm.title.disallowEmptyValue = true;
	frm.title.disallowEmptyValueError = 'Title required.';
	
	// 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.';
   
   //phone number - max length 35
   frm.phonenumber.required = true;
   frm.phonenumber.requiredError = 'Phone number required.';
   frm.phonenumber.pattern = 'numeric';
   frm.phonenumber.patternError = 'Invalid phone number.';
   frm.phonenumber.maxlength = 35;
   frm.phonenumber.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';

    //postcode - min length 5, max 9
   frm.postcode.required = true;
   frm.postcode.requiredError = 'Post Code is required.';
   frm.postcode.minlength = 4;
   frm.postcode.minlengthError = 'Post Code is too short.';
   frm.postcode.maxlength = 8;
   frm.postcode.maxlengthError = 'Post Code is too long.';
   
   // free text - max length 5000
   frm.requirements.maxlength = 5000;
   frm.requirements.maxlengthError = 'Our systems do not allow messages longer than 5000 characters.';
   
   //date
   
//   frm.departdate.required = true;
//   frm.departdate.requiredError = 'Departure date required.';
//   frm.departdate.minlength = 10;
//   frm.departdate.minlengthError = 'Incorrect date format.';
   
   
   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;
}


// ************************************** Travel Advisor
function checkTravelAdvisor(frm) {
	var debug = false;
	
	if (debug)
	{
		alert("in checkTravelAdvisor function");
	}
	
   	// emails address - max length 80
	frm.from.required = true;
	frm.from.requiredError = 'Email address required.';
	frm.from.pattern = 'email';
	frm.from.patternError = 'The email address entered is not valid.';
	frm.from.maxlength = 80;
	frm.from.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// title
	frm.title.disallowEmptyValue = true;
	frm.title.disallowEmptyValueError = 'Title required.';
	
	// 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.';
   
   //phone number - max length 35
   frm.phonenumber.required = true;
   frm.phonenumber.requiredError = 'Phone number required.';
   frm.phonenumber.pattern = 'numeric';
   frm.phonenumber.patternError = 'Invalid phone number.';
   frm.phonenumber.maxlength = 35;
   frm.phonenumber.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';

    //postcode - min length 5, max 9
   frm.postcode.required = true;
   frm.postcode.requiredError = 'Post Code is required.';
   frm.postcode.minlength = 4;
   frm.postcode.minlengthError = 'Post Code is too short.';
   frm.postcode.maxlength = 8;
   frm.postcode.maxlengthError = 'Post Code is too long.';
   /**
    //dateofbirth - min length 10
   frm.dateofbirth.required = true;
   frm.dateofbirth.requiredError = 'Date of Birth is required.';
   frm.dateofbirth.minlength = 10;
   frm.dateofbirth.minlengthError = 'Date of Birth is too short.';
**/
    //destination
   frm.destination.required = true;
   frm.destination.requiredError = 'Travel destination required.';
   
 //  frm.departmonth.required = true;
   //frm.departmonth.requiredError = 'Departure month required.';
   
   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
/**	
function checkEmail(frm) {
	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.';
}

	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;
   }
	
	return true;
}
**/
// ************************************** CustomerFeedback

function checkCustFeedback(frm) {
   	// emails address - max length 80
	frm.from.required = true;
	frm.from.requiredError = 'Email address required.';
	frm.from.pattern = 'email';
	frm.from.patternError = 'The email address entered is not valid.';
	frm.from.maxlength = 80;
	frm.from.maxlengthError = 'Sorry, we cannot accept email addresses above 80 characters.';
	
	// title
	frm.title.disallowEmptyValue = true;
	frm.title.disallowEmptyValueError = 'Title required.';
	
	// 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.landline.required = true;
   frm.landline.requiredError = 'Landline number required.';
   frm.landline.maxlength = 35;
   frm.landline.maxlengthError = 'Our systems do not allow phone numbers longer than 35 numbers.';
   

   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;
}
