/*
	Site : Vodafone Events booking site
	Developer : Graham Holden
	Company : Torpedo Group Ltd
	Date : 21/10/08
*/
var vodafone_employee = false;
function checkEmailAddress(field) {
   vodafone_employee = false;
	// Note: The next expression must be all on one line...
	//       allow no spaces, linefeeds, or carriage returns!
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var email = field.value;
	var split_array = email.split("@");
	//alert(split_array[1]);
	var good;
	if (filter.test(field.value)){
   		good = true;
	}else {
   		alert('Please enter a valid e-mail address.')
   		field.focus();
   		field.select();
   		good = false;
   }
  
   if(split_array[1] == 'vodafone.com'){
		good = false;
		alert('These events are for vodafone customers only');
		vodafone_employee = true;
	}
}

function compareEmailAddress(field){
	/*
		this is used to check to see that the email address has been entered in correctly
	*/
	
	if(field.value != $('email').value){
		alert('Emails do not match, please re enter confirmation email');
		field.focus();
		field.select();
	}
}



function checkFormFilled(form){
	/*
		this checks to see that the whole form is filled in correctly.
		onsubmit="return checkFormFilled(this);"
	*/

	
	
	var formToCheck = $(form).getElements();
	var errorMessage = 'The following fields in the form are required \n';
	var errorFields = '';
	var error = true;
	var radio_value = "";
	//error = true;
	var guidance_note = false;
	for(i in formToCheck){ 
		/* 
		if(formToCheck[i]['value'] == ''){
			errorFields += formToCheck[i]['title'] + '\n';
			error = true;
		}
		*/
		if(formToCheck[i]['title'] == 'validate'){ // if the form field is to be validated.
			if(formToCheck[i]['value'] == '' && formToCheck[i]['name'] == 'marketing'){
				errorFields += 'how did you hear about us \n';
				error = true;
			}else if(formToCheck[i]['value'] == ''){
				error = true;
				errorFields += formToCheck[i]['name'] + '\n';
			}
			if(formToCheck[i]['name'] == 'comment'){
				var comment = document.contactForm.comment.value;
				var word_array = comment.split(' ');
				var count = word_array.length;
				if(count > 200){
					var words_over = count - 200;
					errorFields += 'comment - ' + words_over + ' too many words (max 200)\n';
				}
			}
		}
		/*
		if(formToCheck[i]['name'] == 'comment'){
			var comment = document.contactForm.comment.value;
			var word_array = comment.split(' ');
			var count = word_array.length;
			if(count > 5){
				var words_over = count - 5;
				errorFields += 'comment - ' + words_over +' too many words (max 200)\n';
				error = true;
			}
		}
		*/
	}

 	if(errorFields ==''){
		error = false;
	}
 
	if(error == true){ // if there is an error then return false, as this prevents the form from being submitted
		alert(errorMessage + errorFields);
		form.focus();
		return false;
	}else{
		return true;
	}
}

function submitForm(form){
	/*
		as the form uses an image for the submit button then this is required to make sure that the form is submitted correctly.
	*/
	
	if(checkFormFilled(form)){
		document.forms[form].submit();
	}
}
