/*
* Name: validation.js
* purpose: form validation routines for portal forms
* History: 05-02-07: Gavin Harrison created
*/

// validate strings with alphabetical character values and whitespaces, returns true if valid 
function isAlphabetical(s){
	return (/^[A-Za-z \s]*$/).test(s);
}
// check for valid numeric values , can contain a decimal point or leading minus sign returns true if valid
function isNumeric(s){
	return (/(^-*\d+$)|(^-*\d+\.\d+$)/).test(s);
}
// check for valid e-mail addresses, returns true if valid
function isEmail(s){
	return (/^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/).test(s);
}
// check for valid uk telephone numbers and valid mobile numbers, returns true if valid
function validatePhoneNumber(s){
	return (/^\d{5}\s*\d{6}$/).test(s);
}
// validate UK post codes according to following rules
// LN NLL, LLN NLL, LNN NLL, LLNN NLL, LLNL NLL, LNL NLL
function validatePostCode(s){
	return (/^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$/).test(s);
}
//returns true if a (s)tring contains only alphanumeric (0-9,a-z,A-Z) characters
function isAlphaNumeric(s) {
	return (/[\w]/).test(s);
}
// check that password field is a minimum of 6 alphanumeric characters 
function isValidPassword(s){
	return(/\w{6,12}$/).test(s);
}

// validate checkbox org_category, used to choose which section entry is listed under
function validateCheckbox  (strCheckBoxID, intMinimumChecked) //args: check box id, minimum number of boxes required 
{
	// count how many boxes have been checked by the reader
  	var count = 0;
  	for (var i=0; i < strCheckBoxID.length; i++){
    	if (strCheckBoxID[i].checked) 
		{
			count++;
		}
  	}
	// if count >= minimum checked then form is valid
	if (count >= intMinimumChecked)
	{ 
		return true;
	}
	else{ // no boxes checked
  		return false;
	}
}

/************** organisation registration form ***********/

// xor_organisation_registration_form.asp stage one: Business Details
function validate_OrganisationRegistration_stageone(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	
	// business name is mandetory
	if (document.formOne.BusinessName.value == '') {
    	alert("Business Name is a required field ");	
		document.formOne.BusinessName.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}		

	// address line one is mandetory
	if (document.formOne.AddressOne.value == '') {
    	alert("Address line one is a required field ");	
		document.formOne.AddressOne.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}	
	//  address one must contain alphanumeric data
	if (document.formOne.AddressOne.value != ''){
    	isValid = isAlphaNumeric(formOne.AddressOne.value);
		if(!isValid){
			alert("Address line one field contains invalid data");
			document.formOne.AddressOne.focus();
			document.formOne.trackProgress.value = ''
			return false;
		}
	}
	// post town (AddressFour) is mandetory
	if (document.formOne.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formOne.AddressFour.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formOne.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formOne.AddressFour.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formOne.AddressFour.focus();
			document.formOne.trackProgress.value = ''			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formOne.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formOne.PostCode.value != ''){
    	isValid = validatePostCode(formOne.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
			return false;
		}
	}

	// telephone number must be a valid uk or mobile format 
	if (document.formOne.TelephoneNationalNumber.value != ''){
    	isValid = validatePhoneNumber(formOne.TelephoneNationalNumber.value);
		if(!isValid){
			alert("Telephone Number is not in a recognised format");
			document.formOne.TelephoneNationalNumber.focus();
			document.formOne.trackProgress.value = ''			
			return false;
		}
	}	

	// fax number must be a valid uk format 
	if (document.formOne.FaxNationalNumber.value != ''){
    	isValid = validatePhoneNumber(formOne.FaxNationalNumber.value);
		if(!isValid){
			alert("Fax Number is not in a recognised format");
			document.formOne.FaxNationalNumber.focus();
			document.formOne.trackProgress.value = ''		
			return false;
		}
	}	

}

/* edit stage one: Business Details */
function validate_OrganisationRegistration_editstageone(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	
	// business name is mandetory
	if (document.formTwo.BusinessName.value == '') {
    	alert("Business Name is a required field ");	
		document.formTwo.BusinessName.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}		

	// address line one is mandetory
	if (document.formTwo.AddressOne.value == '') {
    	alert("Address line one is a required field ");	
		document.formTwo.AddressOne.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	//  address one must contain alphanumeric data
	if (document.formTwo.AddressOne.value != ''){
    	isValid = isAlphaNumeric(formTwo.AddressOne.value);
		if(!isValid){
			alert("Address line one field contains invalid data");
			document.formTwo.AddressOne.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
			return false;
		}
	}
	// post town (AddressFour) is mandetory
	if (document.formTwo.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formTwo.AddressFour.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formTwo.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formTwo.AddressFour.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formTwo.AddressFour.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formTwo.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formTwo.PostCode.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formTwo.PostCode.value != ''){
    	isValid = validatePostCode(formTwo.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formTwo.PostCode.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
			return false;
		}
	}

	// telephone number must be a valid uk or mobile format 
	if (document.formTwo.TelephoneNationalNumber.value != ''){
    	isValid = validatePhoneNumber(formTwo.TelephoneNationalNumber.value);
		if(!isValid){
			alert("Telephone Number is not in a recognised format");
			document.formTwo.TelephoneNationalNumber.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'			
			return false;
		}
	}	

	// fax number must be a valid uk format 
	if (document.formTwo.FaxNationalNumber.value != ''){
    	isValid = validatePhoneNumber(formTwo.FaxNationalNumber.value);
		if(!isValid){
			alert("Fax Number is not in a recognised format");
			document.formTwo.FaxNationalNumber.focus();
			document.formTwo.trackProgress.value = 'EditStageOne';		
			return false;
		}
	}	

}
/* end edit stage one */
// xor_organisation_registration_form.asp: stage two: Contact Details
function validate_OrganisationRegistration_stagetwo(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	
	// business name is mandetory
	if(document.formThree.ContactName.value == '') {
    	alert("Contact Name is a required field ");	
		document.formThree.ContactName.focus();
		document.formThree.trackProgress.value = "StageOne"
		return false;
	}		
	// contact telephone number is mandetory
	if(document.formThree.ContactTelephone.value == '') {
    	alert("Contact Telephone Number is a required field ");	
		document.formThree.ContactTelephone.focus();
		document.formThree.trackProgress.value = "StageOne"
		return false;
	}	
	// telephone number must be a valid uk or mobile format 
	if(document.formThree.ContactTelephone.value != ''){
    	isValid = validatePhoneNumber(formThree.ContactTelephone.value);
		if(!isValid){
			alert("Contact Telephone Number is not in a recognised format");
			document.formThree.ContactTelephone.focus();
			document.formThree.trackProgress.value = 'StageOne'			
			return false;
		}
	}	
	// contact email must be a valid format
	if(document.formThree.ContactEMail.value != ''){
		isValid = isEmail(formThree.ContactEMail.value);
		if(!isValid){
			alert("Contact E-Mail is not in a recognised format");
			document.formThree.ContactEMail.focus();
			document.formThree.trackProgress.value = 'StageOne'
			return false;
		}
	}

}

// edit stage two
function validate_OrganisationRegistration_editstagetwo(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	 
	// business name is mandetory
	if(document.formFour.ContactName.value == '') {
    	alert("Contact Name is a required field ");	
		document.formFour.ContactName.focus();
		document.formFour.trackProgress.value = "EditStageTwo"
		return false;
	}		
	// contact telephone number is mandetory
	if(document.formFour.ContactTelephone.value == '') {
    	alert("Contact Telephone Number is a required field ");	
		document.formFour.ContactTelephone.focus();
		document.formFour.trackProgress.value = "EditStageTwo"
		return false;
	}	
	// telephone number must be a valid uk or mobile format 
	if(document.formFour.ContactTelephone.value != ''){
    	isValid = validatePhoneNumber(formFour.ContactTelephone.value);
		if(!isValid){
			alert("Contact Telephone Number is not in a recognised format");
			document.formFour.ContactTelephone.focus();
			document.formFour.trackProgress.value = 'EditStageTwo'			
			return false;
		}
	}	
	// contact email must be a valid format
	if(document.formFour.ContactEMail.value != ''){
		isValid = isEmail(document.formFour.ContactEMail.value);
		if(!isValid){
			alert("Contact E-Mail is not in a recognised format");
			document.formFour.ContactEMail.focus();
			document.formFour.trackProgress.value = 'EditStageTwo';
			return false;
		}
	}
}

/* 
* stage 3 of organisation registration does not require validation
* skip to stage 4
*/

//  xor_organisation_registration_form.asp: stage four: categories
function validate_OrganisationRegistration_stagethree(){
	// ensures that at least one checkbox is checked
	var isValid;	
	isValid = validateCheckbox(document.formSeven.org_category, 1);
	if(!isValid){
		alert("Select at least one category from the options below");
		document.formSeven.trackProgress.value = 'StageThree';		
		return false;
	}
}

//  xor_organisation_registration_form.asp: stage four: categories
function validate_OrganisationRegistration_editstagefour(){
	// ensures that at least one checkbox is checked
	var isValid;	
	isValid = validateCheckbox(document.formEight.org_category, 1);
	if(!isValid){
		alert("Select at least one category from the options below");
		document.formEight.trackProgress.value = 'EditStageFour';	
		return false;
	}
}
/************** end organisation registration form ***********/

/************** sport registration form *******************/
/* stage one */
function validate_SportsRegister_stageone(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	// sport name is mandetory
	if (document.formOne.SportName.value == '') {
    	alert("Sport Name is a required field ");	
		document.formOne.trackProgress.value = ''
		document.formOne.SportName.focus();
		return false;
	}
	// sport name must be alphabetical
	isValid = isAlphabetical(document.formOne.SportName.value);
	if(!isValid){
		alert("Sport Name contains invalid character")
		document.formOne.trackProgress.value = ''
		document.formOne.SportName.focus();
		return false;
	}
	
	// organisation name is mandetory
	if (document.formOne.OrganisationName.value == '') {
    	alert("Organisation Name is a required field ");	
		document.formOne.trackProgress.value = ''
		document.formOne.OrganisationName.focus();
		return false;
	}
	// post town (AddressFour) is mandetory
	if (document.formOne.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formOne.AddressFour.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formOne.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formOne.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formOne.AddressFour.focus();
			document.formOne.trackProgress.value = ''			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formOne.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formOne.PostCode.value != ''){
    	isValid = validatePostCode(formOne.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
			return false;
		}
	}
}
/* edit stage one */
function validate_SportsRegister_editstageone(){
	var isValid;
	// sport name is mandetory
	if (document.formTwo.SportName.value == '') {
    	alert("Sport Name is a required field ");	
		document.formTwo.trackProgress.value = 'EditStageOne'
		document.formTwo.SportName.focus();
		return false;
	}
	// sport name must be alphabetical
	isValid = isAlphabetical(document.formTwo.SportName.value);
	if(!isValid){
		alert("Sport Name contains invalid character")
		document.formTwo.trackProgress.value = 'EditStageOne'
		document.formTwo.SportName.focus();
		return false;
	}
	
	// organisation name is mandetory
	if (document.formTwo.OrganisationName.value == '') {
    	alert("Organisation Name is a required field ");	
		document.formTwo.trackProgress.value = 'EditStageOne'
		document.formTwo.OrganisationName.focus();
		return false;
	}	
	// post town (AddressFour) is mandetory
	if (document.formTwo.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formTwo.AddressFour.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formTwo.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formTwo.AddressFour.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formTwo.AddressFour.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formTwo.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formTwo.PostCode.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formTwo.PostCode.value != ''){
    	isValid = validatePostCode(formTwo.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formTwo.PostCode.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
			return false;
		}
	}
	
}
/* stage two */
function validate_SportsRegister_stagetwo(){
	// contact name is mandetory
	if (document.formThree.ContactName.value == ''){
		alert("Contact Name is a required field");
		document.formThree.trackProgress.value = 'StageOne'
		document.formThree.ContactName.focus();
		return false;
	}
	// contact name is alphabetical
	var isValid;
	isValid = isAlphabetical(document.formThree.ContactName.value);
	if(!isValid){
		alert("Contact Name contains invalid characters");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactName.focus();
		return false;
	}
	// contact telephone is mandetory
	if (document.formThree.ContactTelephone.value == ''){
		alert("Contact Telephone is a required field");
		document.formThree.trackProgress.value = 'StageOne'
		document.formThree.ContactTelephone.focus();
		return false;
	}	
	// Contact telephone must be in a recognised format
	isValid = validatePhoneNumber(document.formThree.ContactTelephone.value)
	if(!isValid){
		alert("Contact Telephone is not in a recognised format");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactTelephone.focus();
		return false;		
	}
	// Contact email is mandetory
	if(document.formThree.ContactEMail.value == ''){
		alert("Contact E-Mail is a required field");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactEMail.focus();
		return false;		
	}
	isValid = isEmail(document.formThree.ContactEMail.value);
	if(!isValid){
		alert("Contact E-Mail is not in a recognised format");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactEMail.focus();
		return false;		
	}
}
/* edit stage two */
function validate_SportsRegister_editstagetwo(){
	// contact name is mandetory
	if (document.formFour.ContactName.value == ''){
		alert("Contact Name is a required field");
		document.formFour.trackProgress.value = 'StageOne'
		document.formFour.ContactName.focus();
		return false;
	}
	// contact name is alphabetical
	var isValid;
	isValid = isAlphabetical(document.formFour.ContactName.value);
	if(!isValid){
		alert("Contact Name contains invalid characters");
		document.formFour.trackProgress.value = 'StageOne';
		document.formFour.ContactName.focus();
		return false;
	}
	
	// contact telephone is mandetory
	if (document.formFour.ContactTelephone.value == ''){
		alert("Contact Telephone is a required field");
		document.formFour.trackProgress.value = 'StageOne'
		document.formFour.ContactTelephone.focus();
		return false;
	}	
	// Contact telephone must be in a recognised format
	isValid = validatePhoneNumber(document.formFour.ContactTelephone.value)
	if(!isValid){
		alert("Contact Telephone is not in a recognised format");
		document.formFour.trackProgress.value = 'StageOne';
		document.formFour.ContactTelephone.focus();
		return false;		
	}	
	// Contact email is mandetory
	if(document.formFour.ContactEMail.value == ''){
		alert("Contact E-Mail is a required field");
		document.formFour.trackProgress.value = 'StageOne';
		document.formFour.ContactEMail.focus();
		return false;		
	}
	isValid = isEmail(document.formFour.ContactEMail.value);
	if(!isValid){
		alert("Contact E-Mail is not in a recognised format");
		document.formFour.trackProgress.value = 'StageOne';
		document.formFour.ContactEMail.focus();
		return false;		
	}	
}

/************** end sport registration form ***************/

/*********** branding toolkit registration form ***********/
/**************** stage one:  ****************************/
function validate_Branding_stageone(){
	var isValid;
	// organisation name is mandetory
	if(document.formOne.OrganisationName.value == ''){
		alert("Organisation Name is a required field");
		document.formOne.trackProgress.value = '';
		document.formOne.OrganisationName.focus();
		return false;
	}
	// address line one is mandetory
	if (document.formOne.AddressOne.value == '') {
    	alert("Address line one is a required field ");	
		document.formOne.AddressOne.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}	
	//  address one must contain alphanumeric data
	if (document.formOne.AddressOne.value != ''){
    	isValid = isAlphaNumeric(formOne.AddressOne.value);
		if(!isValid){
			alert("Address line one field contains invalid data");
			document.formOne.AddressOne.focus();
			document.formOne.trackProgress.value = ''
			return false;
		}
	}
	// post town (AddressFour) is mandetory
	if (document.formOne.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formOne.AddressFour.focus();
		document.formOne.trackProgress.value = ''
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formOne.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formOne.AddressFour.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formOne.AddressFour.focus();
			document.formOne.trackProgress.value = ''			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formOne.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formOne.PostCode.value != ''){
    	isValid = validatePostCode(formOne.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formOne.PostCode.focus();
			document.formOne.trackProgress.value = ''
			return false;
		}
	}
}
/****************** end stage one **********************/

/***************** edit stage one **********************/
function validate_Branding_editstageone(){
	// check that mandetory fields contain a value
	// check for valid input if value exists
	 var isValid;
	
	// business name is mandetory
	if (document.formTwo.OrganisationName.value == '') {
    	alert("Business Name is a required field ");	
		document.formTwo.OrganisationName.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}		

	// address line one is mandetory
	if (document.formTwo.AddressOne.value == '') {
    	alert("Address line one is a required field ");	
		document.formTwo.AddressOne.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	//  address one must contain alphanumeric data
	if (document.formTwo.AddressOne.value != ''){
    	isValid = isAlphaNumeric(formTwo.AddressOne.value);
		if(!isValid){
			alert("Address line one field contains invalid data");
			document.formTwo.AddressOne.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
			return false;
		}
	}
	// post town (AddressFour) is mandetory
	if (document.formTwo.AddressFour.value == '') {
    	alert("Please enter a Post Town for this contact ");	
		document.formTwo.AddressFour.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// post town must contain alphanumeric data
	if (document.formTwo.AddressFour.value != ''){
    	isValid = isAlphaNumeric(formTwo.AddressFour.value);
		if(!isValid){
			alert("Post Town contains invalid data");
			document.formTwo.AddressFour.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'			
			return false;
		}
	}
	// postcode is mandetory
	if (document.formTwo.PostCode.value == '') {
    	alert("Please enter a valid post code ");	
		document.formTwo.PostCode.focus();
		document.formTwo.trackProgress.value = 'EditStageOne'
		return false;
	}	
	// postcode must be a valid uk postcode 
	if (document.formTwo.PostCode.value != ''){
    	isValid = validatePostCode(formTwo.PostCode.value);
		if(!isValid){
			alert("Post Code is not in a recognised format");
			document.formTwo.PostCode.focus();
			document.formTwo.trackProgress.value = 'EditStageOne'
			return false;
		}
	}	
}
/******************* end edit stage one *********************/

/********************** stage two ***************************/
function validate_Branding_stagetwo(){
	// contact name is mandetory
	if (document.formThree.ContactName.value == ''){
		alert("Contact Name is a required field");
		document.formThree.trackProgress.value = 'StageOne'
		document.formThree.ContactName.focus();
		return false;
	}
	// contact name is alphabetical
	var isValid;
	isValid = isAlphabetical(document.formThree.ContactName.value);
	if(!isValid){
		alert("Contact Name contains invalid characters");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactName.focus();
		return false;
	}
	// contact telephone is mandetory
	if (document.formThree.ContactTelephone.value == ''){
		alert("Contact Telephone is a required field");
		document.formThree.trackProgress.value = 'StageOne'
		document.formThree.ContactTelephone.focus();
		return false;
	}	
	// Contact telephone must be in a recognised format
	isValid = validatePhoneNumber(document.formThree.ContactTelephone.value)
	if(!isValid){
		alert("Contact Telephone is not in a recognised format");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactTelephone.focus();
		return false;		
	}
	// contact e-mail is mandetory as it becomes user name for log in
	if (document.formThree.ContactEMail.value == ''){
		alert("Contact E Mail Address is a required field");
		document.formThree.trackProgress.value = 'StageOne'
		document.formThree.ContactEMail.focus();
		return false;
	}
	// Contact E Mail must be in a recognised format
	isValid = isEmail(document.formThree.ContactEMail.value)
	if(!isValid){
		alert("Contact E Mail Address is not in a recognised format");
		document.formThree.trackProgress.value = 'StageOne';
		document.formThree.ContactEMail.focus();
		return false;		
	}	
}
/************************ end stage two ******************************/

/************************ edit stage two *****************************/
function validate_Branding_editstagetwo(){
	// contact name is mandetory
	if (document.formFour.ContactName.value == ''){
		alert("Contact Name is a required field");
		document.formFour.trackProgress.value = 'EditStageTwo'
		document.formFour.ContactName.focus();
		return false;
	}
	// contact name is alphabetical
	var isValid;
	isValid = isAlphabetical(document.formFour.ContactName.value);
	if(!isValid){
		alert("Contact Name contains invalid characters");
		document.formFour.trackProgress.value = 'EditStageTwo';
		document.formFour.ContactName.focus();
		return false;
	}
	// contact telephone is mandetory
	if (document.formFour.ContactTelephone.value == ''){
		alert("Contact Telephone is a required field");
		document.formFour.trackProgress.value = 'EditStageTwo'
		document.formFour.ContactTelephone.focus();
		return false;
	}	
	// Contact telephone must be in a recognised format
	isValid = validatePhoneNumber(document.formFour.ContactTelephone.value)
	if(!isValid){
		alert("Contact Telephone is not in a recognised format");
		document.formFour.trackProgress.value = 'EditStageTwo';
		document.formFour.ContactTelephone.focus();
		return false;		
	}
	// contact e-mail is mandetory as it becomes user name for log in
	if (document.formFour.ContactEMail.value == ''){
		alert("Contact E Mail Address is a required field");
		document.formFour.trackProgress.value = 'EditStageTwo'
		document.formFour.ContactEMail.focus();
		return false;
	}
	// Contact E Mail must be in a recognised format
	isValid = isEmail(document.formFour.ContactEMail.value)
	if(!isValid){
		alert("Contact E Mail Address is not in a recognised format");
		document.formFour.trackProgress.value = 'EditStageTwo';
		document.formFour.ContactEMail.focus();
		return false;		
	}	
}
/*********************** end edit stage two **************************/

/*********************** stage three *********************************/

function validate_Branding_stagethree(){
	// password and password confirmation fields are mandetory
	if(document.formFive.PasswordOne.value == ''){
		alert("Password is a required field");
		document.formFive.trackProgress.value = 'StageTwo'
		document.formFive.PasswordOne.focus();
		return false;
	}
	// password confirmation field 
	if(document.formFive.PasswordTwo.value == ''){
		alert("Please confirm your Password");
		document.formFive.trackProgress.value = 'StageTwo'
		document.formFive.PasswordTwo.focus();
		return false;
	}	
	// check for password match
	if(document.formFive.PasswordOne.value != document.formFive.PasswordTwo.value){
		alert("Error: Passwords do not match!");
		document.formFive.trackProgress.value = 'StageTwo';
		document.formFive.PasswordTwo.value = '';
		document.formFive.PasswordTwo.focus();
		return false;
	}
	// password must be alphanumeric
	var isValid;
	isValid = isAlphaNumeric(document.formFive.PasswordOne.value);
	if(!isValid){
		alert("Password contains invalid characters");
		document.formFive.trackProgress.value = 'StageTwo'
		document.formFive.PasswordOne.focus();
		return false;
	}
	isValid = isValidPassword(document.formFive.PasswordOne.value);
	if(!isValid){
		alert("Passwords must be between 6 and 12 characters long");
		document.formFive.trackProgress.value = 'StageTwo'
		document.formFive.PasswordOne.focus();
		return false;
	}
	if(isValid){
		// double check length
		var strPassword = document.formFive.PasswordOne.value;
		if(strPassword.length > 12){
			alert("Passwords must be between 6 and 12 characters long");
			document.formFive.trackProgress.value = 'StageTwo'
			document.formFive.PasswordOne.focus();
			return false;
		}
		return true;
	}
	// password confirmation field 
	if(document.formFive.PasswordTwo.value == ''){
		alert("Please confirm your Password");
		document.formFive.trackProgress.value = 'StageTwo'
		document.formFive.PasswordTwo.focus();
		return false;
	}	
	// check for password match
	if(document.formFive.PasswordOne.value != document.formFive.PasswordTwo.value){
		alert("Error: Passwords do not match!");
		document.formFive.trackProgress.value = 'StageTwo';
		document.formFive.PasswordTwo.value = '';
		document.formFive.PasswordTwo.focus();
		return false;
	}
}

/*********************** end stage three *****************************/

/*********************** edit stage three *********************************/

function validate_Branding_editstagethree(){
	// password and password confirmation fields are mandetory
	if(document.formSix.PasswordOne.value == ''){
		alert("Password is a required field");
		document.formSix.trackProgress.value = 'EditStageThree'
		document.formSix.PasswordOne.focus();
		return false;
	}
	// password confirmation field 
	if(document.formSix.PasswordTwo.value == ''){
		alert("Please confirm your Password");
		document.formSix.trackProgress.value = 'EditStageThree'
		document.formSix.PasswordTwo.focus();
		return false;
	}	
	// check for password match
	if(document.formSix.PasswordOne.value != document.formSix.PasswordTwo.value){
		alert("Error: Passwords do not match!");
		document.formSix.trackProgress.value = 'EditStageThree';
		document.formSix.PasswordTwo.value = '';
		document.formSix.PasswordTwo.focus();
		return false;
	}
	// password must be alphanumeric
	var isValid;
	isValid = isAlphaNumeric(document.formSix.PasswordOne.value);
	if(!isValid){
		alert("Password contains invalid characters");
		document.formSix.trackProgress.value = 'EditStageThree'
		document.formSix.PasswordOne.focus();
		return false;
	}
	isValid = isValidPassword(document.formSix.PasswordOne.value);
	if(!isValid){
		alert("Passwords must be between 6 and 12 characters long");
		document.formSix.trackProgress.value = 'EditStageThree'
		document.formSix.PasswordOne.focus();
		return false;
	}
	if(isValid){
		// double check length
		var strPassword = document.formSix.PasswordOne.value;
		if(strPassword.length > 12){
			alert("Passwords must be between 6 and 12 characters long");
			document.formSix.trackProgress.value = 'EditStageThree'
			document.formSix.PasswordOne.focus();
			return false;
		}
		return true;
	}
	// password confirmation field 
	if(document.formSix.PasswordTwo.value == ''){
		alert("Please confirm your Password");
		document.formSix.trackProgress.value = 'EditStageThree'
		document.formSix.PasswordTwo.focus();
		return false;
	}	
	// check for password match
	if(document.formSix.PasswordOne.value != document.formSix.PasswordTwo.value){
		alert("Error: Passwords do not match!");
		document.formSix.trackProgress.value = 'EditStageThree';
		document.formSix.PasswordTwo.value = '';
		document.formSix.PasswordTwo.focus();
		return false;
	}
}
/*********************** end edit stage three *****************************/
/**************** end branding toolkit registration form *************/

/**************************** branding toolkit log in ****************************/
/***************************stage one: Log In Screen *****************************/
function validate_branding_toolkit_login(){
	if(document.formOne.username.value == ''){
		alert("User Name is a required field");
		document.formOne.trackProgress.value = '';		
		document.formOne.username.focus();
		return false;
	}
	if(document.formOne.password.value == ''){
		alert("Password is a required field");
		document.formOne.trackProgress.value = '';
		document.formOne.password.focus();
		return false;
	}
	// username must be a valid e-mail address
	isValid = isEmail(document.formOne.username.value)
	if(!isValid){
		alert("User name is not in a recognised format");
		document.formOne.trackProgress.value = '';
		document.formOne.username.focus();
		return false;		
	}	
	// password must be alphanumeric
	var isValid;
	isValid = isAlphaNumeric(document.formOne.password.value);
	if(!isValid){
		alert("Password contains invalid characters");
		document.formOne.trackProgress.value = ''
		document.formOne.password.focus();
		return false;
	}
	isValid = isValidPassword(document.formOne.password.value);
	if(!isValid){
		alert("Passwords must be between 6 and 12 characters long");
		document.formOne.trackProgress.value = ''
		document.formOne.password.focus();
		return false;
	}
	if(isValid){
		// double check length
		var strPassword = document.formOne.password.value;
		if(strPassword.length > 12){
			alert("Passwords must be between 6 and 12 characters long");
			document.formOne.trackProgress.value = ''
			document.formOne.password.focus();
			return false;
		}
		return true;
	}
}
/************************** stage two: Get User Details **************************/
function validate_Get_User_Details(){
	if(document.formThree.username.value == ''){
		alert("User Name is a required field");
		document.formThree.trackProgress.value = 'GetDetails';		
		document.formThree.username.focus();
		return false;
	}	
	// user name must be a valid e-mail address
	isValid = isEmail(document.formThree.username.value)
	if(!isValid){
		alert("User name is not in a recognised format");
		document.formThree.trackProgress.value = 'GetDetails';
		document.formThree.username.focus();
		return false;		
	}	
	
}
/************************** end branding toolkit log in **************************/
/***************************	E-mail us application  ***************************/
// validate form fields
function validateMessage(mailForm){
	if (mailForm.senderName.value =="") {
	 alert('You must supply your name');
	 mailForm.senderName.focus();
	 return (false);
	}
	
	if (!isEmail(mailForm.senderEMail.value)) {
		alert("Please enter a valid email address");
		mailForm.senderEMail.focus();
		return(false)
	}
	
	if (mailForm.message.value =="") {
	 alert('Please supply a message');
	 mailForm.message.focus();
	 return (false);
	}	
}
/************************** end E-mail us application  **************************/
/************************ email page to friend application **********************/
// validate form fields
function validateEMailPageMessage(mailForm){
	if (mailForm.senderName.value =="") {
	 alert('You must supply your name');
	 mailForm.senderName.focus();
	 return (false);
	}
	
	if (!isEmail(mailForm.senderEMail.value)) {
		alert("Please enter a valid email address");
		mailForm.senderEMail.focus();
		return(false)
			
	}
	
	if (mailForm.recipientName.value =="") {
	 alert('You must supply the name of the recipient');
	 mailForm.recipientName.focus();
	 return (false);
	}
	
	if (!isEmail(mailForm.recipientEMail.value)) {
		alert("Please enter a valid email address for the recipient");
		mailForm.recipientEMail.focus();
		return(false)	
	}
	
	if (mailForm.message.value =="") {
	 alert('Please supply a message');
	 mailForm.message.focus();
	 return (false);
	}	
}
/********************** end email page to friend application ********************/

/**********************  event submission application   *************************/
// stage one: event details
function validate_event_stageone(){
	// event title is mandetory
	if(document.formOne.EventTitle.value == ''){
		alert('Event Title is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.EventTitle.focus();
		return(false);
	}
	// event summary is mandetory
	if(document.formOne.EventSummary.value == ''){
		alert('Event Summary is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.EventSummary.focus();
		return(false);
	}
	// event description is mandetory
	if(document.formOne.EventDescription.value == ''){
		alert('Event Description is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.EventDescription.focus();
		return(false);
	}
	// event opening times is mandetory
	if(document.formOne.OpeningTimes.value == ''){
		alert('Opening Times is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.OpeningTimes.focus();
		return(false);
	}
	// event ticket details is mandetory
	if(document.formOne.TicketDetails.value == ''){
		alert('Ticket Details is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.TicketDetails.focus();
		return(false);
	}
	// event venue is mandetory
	if(document.formOne.EventVenue.value == ''){
		alert('Event Venue is a required field');
		document.formOne.trackProgress.value = '';
		document.formOne.EventVenue.focus();
		return(false);
	}
}
// edit stage one
function validate_event_editstageone(){
	// event title is mandetory
	if(document.editformOne.EventTitle.value == ''){
		alert('Event Title is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.EventTitle.focus();
		return(false);
	}
	// event summary is mandetory
	if(document.editformOne.EventSummary.value == ''){
		alert('Event Summary is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.EventSummary.focus();
		return(false);
	}
	// event description is mandetory
	if(document.editformOne.EventDescription.value == ''){
		alert('Event Description is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.EventDescription.focus();
		return(false);
	}
	// event opening times is mandetory
	if(document.editformOne.OpeningTimes.value == ''){
		alert('Opening Times is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.OpeningTimes.focus();
		return(false);
	}
	// event ticket details is mandetory
	if(document.editformOne.TicketDetails.value == ''){
		alert('Ticket Details is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.TicketDetails.focus();
		return(false);
	}
	// event venue is mandetory
	if(document.editformOne.EventVenue.value == ''){
		alert('Event Venue is a required field');
		document.editformOne.enctype = 'text/plain'
		document.editformOne.trackProgress.value = 'EditStageOne';
		document.editformOne.action = "xev_Submit_Your_Event.asp"
		document.editformOne.EventVenue.focus();
		return(false);
	}
}
// stage two: event type
function validate_event_stagetwo(){
	// one keyword is required
	if(document.formTwo.EventKeywordOne.value == ''){
		alert('Please provide at least one keyword');
		document.formTwo.trackProgress.value = 'StageOne';
		document.formTwo.EventKeywordOne.focus();
		return(false);
	}
}
// stage three: organiser details
function validate_event_stagethree(){
	var isValid;
	// organiser name is mandetory
	if(document.formThree.OrganiserName.value == ''){
		alert('Organiser Name is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.OrganiserName.focus();
		return(false);
	}
	// address line one is mandetory
	if(document.formThree.AddressOne.value == ''){
		alert('Address Line One is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.AddressOne.focus();
		return(false);
	}	
	// address line four (post town) is mandetory
	if(document.formThree.AddressFour.value == ''){
		alert('Post Town is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.AddressFour.focus();
		return(false);
	}	
	// post town must be alphanumeric
	isValid = isAlphaNumeric(document.formThree.AddressFour.value);
	if(!isValid){
		alert("Post town contains invalid characters");
		document.formThree.trackProgress.value = 'StageTwo'
		document.formThree.AddressFour.focus();
		return false;
	}	
	// post code is mandetory
	if(document.formThree.PostCode.value == ''){
		alert('Post Code is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.PostCode.focus();
		return(false);
	}
	// post code must be valid
	isValid = validatePostCode(document.formThree.PostCode.value);
	if(!isValid){
		alert("Post code is invalid");
		document.formThree.trackProgress.value = 'StageTwo'
		document.formThree.PostCode.focus();
		return false;
	}	
	// contact telephone number is mandetory	
	if(document.formThree.ContactTelephone.value == ''){
		alert('Telephone Number is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.ContactTelephone.focus();
		return(false);
	}
	// telephone number must be in a recognised format
	isValid = validatePhoneNumber(document.formThree.ContactTelephone.value)
	if(!isValid){
		alert("Telephone Number is not in a recognised format");
		document.formThree.trackProgress.value = 'StageTwo'
		document.formThree.ContactTelephone.focus();
		return false;
	}
	// E-Mail address is mandetory	
	if(document.formThree.OrganiserEMail.value == ''){
		alert('E-Mail is a required field');
		document.formThree.trackProgress.value = 'StageTwo';
		document.formThree.OrganiserEMail.focus();
		return(false);
	}
	// E-Mail address must be in a recognised format
	isValid = isEmail(document.formThree.OrganiserEMail.value)
	if(!isValid){
		alert("E-Mail Address is not in a recognised format");
		document.formThree.trackProgress.value = 'StageTwo'
		document.formThree.OrganiserEMail.focus();
		return false;
	}
}
	
function validate_event_stagefour(){
	// image attachments must be in jpeg format only
	if (document.formFour.SelectImage.value != ''){
		var strInput = document.formFour.SelectImage.value;
		var strMimeType = strInput.substring(strInput.lastIndexOf(".")+1,strInput.length);
		if(strMimeType != "jpg" && strMimeType != "JPG"  && strMimeType != "jpeg" && strMimeType != "JPEG"  ){
			alert("Images must be in JPEG format only");
			document.formFour.action = "xev_Submit_Your_Event.asp"
			//document.formFour.enctype = 'text/plain' 
			document.formFour.trackProgress.value = 'StageThree';
			return(false);	
		}
	}
}
/********************  end event submission application   ***********************/