/**
 * (c) Jason Crosse www.Antanova.com 2008
 * for IMAB.net through J2
 * Basic form validation: make a couple of fields mandatory before form submission
 */
 
var antanova = {
	
	message: '',
	
	validate: function(form)
	{
		this.message = '';
		// tests whether the 'name' text field is empty.
		if(form.name.value.length==0)
		{
			this.message = 'Please enter your name in the box provided.\n\n';
		}
		
		// Check to see if the branch has been selected.
		if(form['office'].value=='nowhere')
		{
			this.message+= 'Please select your preferred office location.\n\n';
		}
		
		// if the email radio button is active, tests whether the email textfield is empty
		if(form['contact-e'].checked && form.email.value.length == 0)
		{
			this.message += 'You have indicated you would prefer to be contacted by email. Please enter your email address in the box provided.\n\n';
		}
		// checks the email address for very basic validity
		else if(form['contact-e'].checked && !(/^.+\@.+\..{2,5}/.test(form.email.value)) )
		{
			this.message += 'Please check the email address you have entered is correct.\n\n';
		}
		
		if(form['contact-p'].checked && form.phone.value.length == 0)
		{
			this.message += 'You have indicated you would prefer to be contacted by phone. Please enter your phone number in the box provided.\n\n';
		}
		
		if(this.message!='')
		{
			alert(this.message);
			return false;
		}
		else
		{
			return true;
		}
	}
	
};