var intCorporateMaxResponseLength = 2500;
var strConfirmationMessage = 'Please confirm that you wish to submit the information provided to The Children\'s Society...';

window.onload = function()
{
	// Get URL details
	var sPath = window.location.pathname;
	var sPageName = sPath.substring(sPath.lastIndexOf('/') + 1);
	
	// Call page-specific DOM functions
	//AddFormValidationEvents(sPageName);
}

function SetMaxLengthOfTextArea(textarea, maxLength)
{
	// Restrict the length of the value if it's too long
	if (textarea.value.length > maxLength)
	{
		textarea.value = textarea.value.substring(0, maxLength);
	}
}

function SetCorporateMaxLengthOfTextArea(textarea, maxLength)
{
	// Restrict the length of the value if it's too long
	if (textarea.value.length > maxLength)
	{
		textarea.value = textarea.value.substring(0, maxLength);
	}
}


function AddFormValidationEvents(pageFileName)
{
	var btnSubmitForm = document.getElementById('btnSubmitForm');
	
	if (pageFileName.toLowerCase() == "corporatecontactus.asp")
	{
		var Q1 = document.getElementById('Q1');
		var Q2 = document.getElementById('Q2');
		var Q3 = document.getElementById('Q3');
		var Q4 = document.getElementById('Q4');
		var Q5 = document.getElementById('Q5');
		var Q6 = document.getElementById('Q6');
		var Q7 = document.getElementById('Q7');
	}

	btnSubmitForm.onclick = function()
	{
		var strFormErrors;
		switch (pageFileName.toLowerCase())
		{
			case 'gcupdaterequest.asp':
				strFormErrors = FormErrors_UpdateRequest();
				break;
			case 'eventscontactus.asp':
				strFormErrors = FormErrors_EventsContactUs();
				break;
			case 'contactus.asp':
				strFormErrors = FormErrors_Contactus();
				break;
			case 'volunteerenquiryform.asp':
				strFormErrors = FormErrors_VolunteerEnquiry();
				break;
			case 'footstepsforchildhoodcontactus.asp':
				strFormErrors = FormErrors_Footsteps();
				break;
			case 'campaignscontactus.asp':
				strFormErrors = FormErrors_Campaigns();
				break;
			case 'youngrunaways.asp':
				strFormErrors = FormErrors_Runaways();
				break;
			case 'corporatecontactus.asp':
				strFormErrors = FormErrors_Corporate();
				break;
			case 'christinglepreregbrief.asp':
				strFormErrors = FormErrors_Christingle();
				break;	
			case 'leavesoflifecontactus.asp':
				strFormErrors = FormErrors_LeavesOfLife();
				break;
			case 'leavesoflifeservice.asp':
				strFormErrors = FormErrors_LeavesOfLifeService();
				break;	
			case 'basilbrush.asp':
				strFormErrors = FormErrors_BasilBrush();
				break;	
		}
	//	strFormErrors = 'errors';
	//	alert(pageFileName.toLowerCase());
		if (strFormErrors.length > 0)
		{
			alert('Sorry, the form is not yet complete.\n\n' + strFormErrors);
			return false;
		}
		else
		{	
			if (ConfirmEmailAddress() > 0)
			{
				return confirm(strConfirmationMessage);
			}
			else
			{
				alert('The Email Address was not verified correctly\n');
				return false;
			}
		}
	}
	
	btnSubmitForm.onkeypress = btnSubmitForm.onclick;

    if (pageFileName == "CorporateContactUs.asp")
    { 
		// Ensure textarea cannot contain more than the maximum response length
		Q1.onkeyup = function()
		{
			SetCorporateMaxLengthOfTextArea(this, intCorporateMaxResponseLength);
		}
		Q2.onkeyup = Q1.onkeyup;
		Q3.onkeyup = Q1.onkeyup;
		Q4.onkeyup = Q1.onkeyup;
		Q5.onkeyup = Q1.onkeyup;
		Q6.onkeyup = Q1.onkeyup;
		Q7.onkeyup = Q1.onkeyup;
	}
}


function ConfirmEmailAddress()
{

	var txtEmail = document.getElementById('txtEmail');
	var txtEmailConfirm = document.getElementById('txtEmailConfirm');
	
	return (txtEmail.value == txtEmailConfirm.value) ? 1 : 0;

}

// A generic function to check many of the common mandatory fields on the forms
function FormErrors_Generic()
{
	var ddTitle = document.getElementById('ddTitle');
	var txtForename = document.getElementById('txtForename');
	var txtSurname = document.getElementById('txtSurname');
	var txtEmail = document.getElementById('txtEmail');
	var txtEmailConfirm = document.getElementById('txtEmailConfirm');
	var ddCountry = document.getElementById('ddCountry');
	var txtAddress1 = document.getElementById('txtAddress1');
	var txtTown	= document.getElementById('txtTown');
	var txtPostCode = document.getElementById('txtPostCode');
	var txtCountry = document.getElementById('txtCountry');

	var titleInvalid = (ddTitle.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddTitle', titleInvalid);

	var forenameInvalid = (txtForename.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtForename', forenameInvalid);

	var surnameInvalid = (txtSurname.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtSurname', surnameInvalid);

	var emailAddressInvalid = (txtEmail.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtEmail', emailAddressInvalid);

	var emailConfirmInvalid = (txtEmailConfirm.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtEmailConfirm', emailConfirmInvalid);

	var emailsDoNotMatch = (!emailConfirmInvalid && !emailAddressInvalid && txtEmail.value != txtEmailConfirm.value);
	if (emailsDoNotMatch)
	{
		ChangeLabelColourForSpecifiedControl('txtEmail', emailsDoNotMatch);
		ChangeLabelColourForSpecifiedControl('txtEmailConfirm', emailsDoNotMatch);
	}

	var addressInvalid = (txtAddress1.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtAddress1', addressInvalid);
	
	var townInvalid = (txtTown.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtTown', townInvalid);
	
	var pcInvalid = (txtPostCode.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtPostCode', pcInvalid);

	var countryInvalid = (ddCountry.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddCountry', countryInvalid);
	
	var strErrors = '';

	if (titleInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your title';
	}
	if (forenameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your forename';
	}
	if (surnameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your surname';
	}
	if (emailAddressInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your email address';
	}	
	if (emailConfirmInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please confirm your email address';
	}
	if (!emailConfirmInvalid && !emailAddressInvalid && txtEmail.value != txtEmailConfirm.value)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please ensure you have entered the same email address twice';
	}
	if (addressInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the first line of your address';
	}
	if (townInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your town';
	}
	if (pcInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your post code';
	}
	if (countryInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please select your country';
	}

	return strErrors;
}


function FormErrors_UpdateRequest()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;

}

function FormErrors_EventsContactUs()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;
}

function FormErrors_Contactus()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;
}

function FormErrors_VolunteerEnquiry()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;

}

function FormErrors_Footsteps()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;

}

function FormErrors_Campaigns()
{
	strErrors = FormErrors_Generic();
	
	return strErrors;

}

function FormErrors_Runaways()
{
	// Check for the generic errors
	strErrors = FormErrors_Generic();

	// Now check for errors specific to this form
	var txtOrgName = document.getElementById('txtOrgName');
	var txtOrgAddress1 = document.getElementById('txtOrgAddress1');	
	var txtOrgTown = document.getElementById('txtOrgTown');
	var txtOrgPostCode = document.getElementById('txtOrgPostCode');
	var ddOrgCountry = document.getElementById('ddOrgCountry');
		
	var countryInvalid = (ddOrgCountry.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddOrgCountry', countryInvalid);

	var orgnameInvalid = (txtOrgName.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtOrgName', orgnameInvalid);

	var orgaddressInvalid = (txtOrgAddress1.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtOrgAddress1', orgaddressInvalid);

	var orgpcInvalid = (txtOrgPostCode.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtOrgPostCode', orgpcInvalid);

	var townInvalid = (txtOrgTown.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtOrgTown', townInvalid);
	
	if (orgnameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your organisation\'s name';	
	}
	if (orgaddressInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the first line of your organisation\'s address';
	}
	if (townInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your organisation\'s town';
	
	}
	if (orgpcInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your organisation\'s post code';
	}	
	if (countryInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your organisation\'s country';
	}	
	
	return strErrors;

}

function FormErrors_Corporate()
{
	// Need totally seperate validation here as have to specify company details.
	var ddTitle = document.getElementById('ddTitle');
	var txtForename = document.getElementById('txtForename');
	var txtSurname = document.getElementById('txtSurname');
	var txtCompName = document.getElementById('txtCompName');
	var txtEmail = document.getElementById('txtEmail');
	var txtEmailConfirm = document.getElementById('txtEmailConfirm');
	var ddCountry = document.getElementById('ddCountry');
	var txtAddress1 = document.getElementById('txtAddress1');
	var txtTown	= document.getElementById('txtTown');
	var txtPostCode = document.getElementById('txtPostCode');
	var ddCountry = document.getElementById('ddCountry');
	var txtWebsite = document.getElementById('txtWebsite');

	var titleInvalid = (ddTitle.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddTitle', titleInvalid);

	var forenameInvalid = (txtForename.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtForename', forenameInvalid);

	var surnameInvalid = (txtSurname.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtSurname', surnameInvalid);
	
	var compNameInvalid = (txtCompName.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtCompName', compNameInvalid);

	var emailAddressInvalid = (txtEmail.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtEmail', emailAddressInvalid);

	var emailConfirmInvalid = (txtEmailConfirm.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtEmailConfirm', emailConfirmInvalid);

	var emailsDoNotMatch = (!emailConfirmInvalid && !emailAddressInvalid && txtEmail.value != txtEmailConfirm.value);
	if (emailsDoNotMatch)
	{
		ChangeLabelColourForSpecifiedControl('txtEmail', emailsDoNotMatch);
		ChangeLabelColourForSpecifiedControl('txtEmailConfirm', emailsDoNotMatch);
	}

	var addressInvalid = (txtAddress1.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtAddress1', addressInvalid);
	
	var townInvalid = (txtTown.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtTown', townInvalid);
	
	var pcInvalid = (txtPostCode.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtPostCode', pcInvalid);

	var countryInvalid = (ddCountry.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddCountry', countryInvalid);
	
	var websiteInvalid = (txtWebsite.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtWebsite', websiteInvalid);
	
	var strErrors = '';

	if (titleInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your title';
	}
	if (forenameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your forename';
	}
	if (surnameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your surname';
	}
	if (compNameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your company\' name';
	}	
	if (addressInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the first line of your company\'s address';
	}
	if (townInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your company\'s town';
	}
	if (pcInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your company\'s post code';
	}
	if (countryInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your company\'s country';
	}
	if (emailAddressInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your email address';
	}
	if (emailConfirmInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please confirm your email address';
	}
	if (!emailConfirmInvalid && !emailAddressInvalid && txtEmail.value != txtEmailConfirm.value)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please ensure you have entered the same email address twice';
	}
	if (websiteInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your company\'s website';
	}		
	
	return strErrors;

}

function FormErrors_Christingle()
{
	var strErrors = FormErrors_Generic();
	
	var txtChurchSchoolGroup = document.getElementById('txtChurchSchoolGroup');
	var ddSite = document.getElementById('ddSite');
	
	var csgInvalid = (txtChurchSchoolGroup.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtChurchSchoolGroup', csgInvalid);
	var ddSiteInvalid = (ddSite.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddSite', ddSiteInvalid);
	
	if (csgInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the name of church, school or group';
	}
	if (ddSiteInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please tell us how you found out about the site';
	}
	
	return strErrors;
}
					
function FormErrors_LeavesOfLife()
{
	strErrors = FormErrors_Generic();
	
	var txtChurchSchoolGroup = document.getElementById('txtChurchSchoolGroup');
	var ddSite = document.getElementById('ddSite');
	
	var csgInvalid = (txtChurchSchoolGroup.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtChurchSchoolGroup', csgInvalid);
	var ddSiteInvalid = (ddSite.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddSite', ddSiteInvalid);
	
	if (csgInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the name of church, school or group';
	}
	if (ddSiteInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please tell us how you found out about the site';
	}
	
	return strErrors;
}

function FormErrors_LeavesOfLifeService()
{
	strErrors = FormErrors_Generic();
	
	var txtVenue = document.getElementById('txtVenue');
	var ddDay = document.getElementById('ddDay');
	var ddMonth = document.getElementById('ddMonth');
	var ddYear = document.getElementById('ddYear');
	
	var txtVenueInvalid = (txtVenue.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtVenue', txtVenueInvalid);

	var ddDayInvalid = (ddDay.value.length == 0);
	var ddMonthInvalid = (ddMonth.value.length == 0);
	var ddYearInvalid = (ddYear.value.length == 0);
	ChangeLabelColourForSpecifiedControl('ddServiceDate', (ddDayInvalid || ddMonthInvalid || ddYearInvalid));
	
	if (txtVenueInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a venue';
	}	
	if (ddDayInvalid || ddMonthInvalid || ddYearInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide the day, month and year of the service';
	}
		
	return strErrors;
}

function ChangeLabelColourForSpecifiedControl(controlName, isInvalid)
{
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++)
	{
		if (labels[i].attributes["for"].value == controlName)
		{
			labels[i].style.color = (isInvalid ? 'red' : 'black');
			break;
		}
	}
}

function ValidateEmail(strValue)
{
	var objRegExp  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

	//check for valid email
	return objRegExp.test(strValue);
}

function ValidateDate(strDate)
{
    var objRegExp = /^((0[1-9]|[1-2][0-9]|3[01]))(\/){1}(0[1-9]|1[012])(\/)([0-9]){4}$/;
 // var objRegExp = /^([0-9]){2}(\/){1}([0-9]){2}(\/)([0-9]){4}$/;
 //check for valid date (dd/mm/yyyy)
	return objRegExp.test(strDate);
}

function ValidatePhoneNumber(strPhone)
{
	var objRegExp = /^[0](\d{3})\s(\d{7})$/;
	return objRegExp.test(strPhone);
}

function ValidateMobileNumber(strMobile)
{
	var objRegExp = /^[0]\d{10}$/;
	return objRegExp.test(strMobile);
}

function calcJulian(isDate)
{
	var gregDate = new Date(isDate);
	var year = gregDate.getFullYear(); 
	var month = gregDate.getMonth()+1; 
	var day = gregDate.getDate();
	var A = Math.floor((7*(year+Math.floor((month+9)/12)))/4);
	var B = day+Math.floor((275*month)/9)
	var isJulian = (367*year)-A+B+1721014;
	return isJulian; 
}

function GetDays(DateofBirth)
{
	var tmp = DateofBirth.split("/")
	var xDate = tmp[1]+"/"+tmp[0]+"/"+tmp[2];
	var refDate = calcJulian(xDate);
	return refDate
}

function CompareDates(DOB) 
{ 
   var DOB_date   = parseInt(DOB.substring(0,2),10); 
   var DOB_month  = parseInt(DOB.substring(3,5),10);
   var DOB_year   = parseInt(DOB.substring(6,10),10); 
   DOB_year = DOB_year + 18; // Adding 18 to years to check for under 18 or over 18
   var DOB_18 = new Date(DOB_year, DOB_month, DOB_date); 
   
   var today = new Date();
   var today_date = today.getDate();
   var today_month = today.getMonth()+ 1;
   var today_year = today.getFullYear();
   
   var today_formatted = new Date(today_year,today_month, today_date);
   
   if(DOB_18 > today_formatted)
   {
      return false;
   } 
   else 
   { 
      return true;
   } 
} 

function FormErrors_BasilBrush()
{
	// Check for the generic errors
	var strErrors = '';

	// Now check for errors specific to this form
	var txtTitle = document.getElementById('ddTitle');
	var txtFirstName = document.getElementById('txtFirstName');
	var txtLastName = document.getElementById('txtLastName');	
	var txtEmail = document.getElementById('txtEmail');
	var txtEmailConfirm = document.getElementById('txtEmailConfirm');
	var txtPhone = document.getElementById('txtPhone');
	var txtMobile = document.getElementById('txtMobile');
	var txtAddress1 = document.getElementById('txtAddress1');
	var txtTown = document.getElementById('txtTown');
	var txtPostCode = document.getElementById('txtPostCode');
	var txtDateofBirth = document.getElementById('txtDateofBirth');
	var chkTermsandConditions = document.getElementById('chkTermsandConditions');
		
    var titleInvalid = (txtTitle.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtTitle', titleInvalid);
			
	var firstnameInvalid = (txtFirstName.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtFirstName', firstnameInvalid);

	var lastnameInvalid = (txtLastName.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtLastName', lastnameInvalid);
	
	var emailInvalid = (txtEmail.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtEmail', emailInvalid);
	
	var emailconfirmInvalid = (txtEmailConfirm.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtConfirmEmail', emailconfirmInvalid);
	
	var address1Invalid = (txtAddress1.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtAddress1', address1Invalid);
	
	var townInvalid = (txtTown.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtTown', townInvalid);
	
	var postcodeInvalid = (txtPostCode.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtPostCode', postcodeInvalid);
	
	var dateofbirthInvalid = (txtDateofBirth.value.length == 0);
	ChangeLabelColourForSpecifiedControl('txtDateofBirth', dateofbirthInvalid);

	var termsandconditionsInvalid = (chkTermsandConditions.checked == false);
	
    var emailsDoNotMatch = (!emailconfirmInvalid && !emailInvalid && txtEmail.value != txtEmailConfirm.value);
	if (emailsDoNotMatch)
	{
		ChangeLabelColourForSpecifiedControl('txtEmail', emailsDoNotMatch);
		ChangeLabelColourForSpecifiedControl('txtEmailConfirm', emailsDoNotMatch);
	}
	
	if (titleInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please select your title';	
	}
	if (firstnameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your firstname';	
	}
	if (lastnameInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your lastname';
	}
	if (emailInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your email address';
	}	
	if (emailconfirmInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please confirm your email address';
	}
	if (!ValidateEmail(txtEmail.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a valid email address';
	}
	if (!emailconfirmInvalid && !emailInvalid && txtEmail.value != txtEmailConfirm.value)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please ensure you have entered the same email address twice';
	}
	if (!ValidatePhoneNumber(txtPhone.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a valid UK phone number';
	}
	if (!ValidateMobileNumber(txtMobile.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a valid UK mobile number';
	}
	if (!ValidateEmail(txtEmail.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a valid email address';
	}
	if (address1Invalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide first line of your address';
	}
	if (townInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your town name';
	}
	if (postcodeInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your postcode';
	}
	if (dateofbirthInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide your date of birth';
	}
	if (!ValidateDate(txtDateofBirth.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please provide a valid date format';
	}
	if (!CompareDates(txtDateofBirth.value))
	{
	 	strErrors += (strErrors.length > 0 ? '\n' : '') + ' - You must be 18 years or older to enter the competition';
	}
	if (termsandconditionsInvalid)
	{
		strErrors += (strErrors.length > 0 ? '\n' : '') + ' - Please confirm that you have read competition terms and conditions';
	}
	
	return strErrors;
}
