/*
	Vamos Theatre Form Validation Routines
	Used for the Contact and Newsletter signup forms.
	Created January 14th 2012
*/

function validateVamosForm(sourceform) {
	var err = '';
	var numprobs = 0;
	
	if($.trim($('#firstname').val()) == '') {
		err += ' * Your first name is missing.\r\n';
		numprobs++;
	}
	
	if($.trim($('#lastname').val()) == '') {
		err += ' * Your last name is missing.\r\n';
		numprobs++;
	}
		
	var email = $.trim($('#email').val());
	if(email == '') {
		err += ' * Your email address is missing.\r\n';
		numprobs++;
	} else {
		if(!isEmailFormatCorrect(email)) {
			err += ' * Your email address is not correct.\r\n';
			numprobs++;
		}
	}
	
	if((sourceform == 'contact') && ($('#captcha').length > 0))
	{
		if($.trim($('#captcha').val()) == '') {
			err += '\r\nYou must enter the word you see in the image just above the "Send Message" button. This is the only way we can stop spammers abusing our site.\r\n';
			numprobs++;
		}
	}
	
	if(err != '') {
		if(numprobs > 1)
			window.alert('Sorry, I can\'t proceed because of the problems listed below.\r\n\r\n' + err + '\r\nPlease try again!');
		else
			window.alert('Sorry, there is a problem with the information you\'ve entered and I can\'t proceed.\r\n\r\n' + err + '\r\nPlease try again!');
	}
	else {
		$('#vamosform').submit();
	}
	return false;
}
	
$(document).ready(function () { $('#submitform').click( function() { return validateVamosForm('contact'); });});
