var ContactUs = {	
	init: function() {
		ContactUs.setupFormValidation();
	},
	
	setupFormValidation : function() {
		
		if ($defined($('name'))) new RequiredFieldValidator($('name'), '', { 'errorMessage': "Please enter your name"});
		if ($defined($('emailaddress'))) new RequiredFieldEmailValidator($('emailaddress'), '');
		if ($defined($('telephone'))) new RequiredFieldTelephoneValidator($('telephone'), '', {'errorOnEmpty': false, 'showStatusFlagOnEmpty': false});
		if ($defined($('address'))) new RequiredFieldValidator($('address'), '');


		var howfound = $('howfound');
		var howfoundother = $('howfoundother');
		
		if (howfound && howfoundother) {
			if (howfound.get('value') != "Other") {
				howfoundother.getParent('li').addClass('hidden');
			}
				
			howfound.addEvent('change', function() {
				if (this.get('value') > "") {
					Helper.setCheckClass(this, 'stateOK', false);
				}
				else {
					Helper.setCheckClass(this, 'stateUnmarked', false);
				}
				if (howfound.get('value') == "Other") {
					howfoundother.getParent('li').removeClass('hidden');
					if (howfoundother.get('value') == "")
						Helper.setCheckClass(howfoundother, 'stateError', false);
				}
				else {
					howfoundother.getParent('li').addClass('hidden');
				}
			});
			
			howfoundother.addEvent('keyup', function() {
				if (this.get('value') == "")
					Helper.setCheckClass(this, 'stateError', false);
				else
					Helper.setCheckClass(this, 'stateOK', false);
			});
	
		}
	}

};

window.addEvent('domready', ContactUs.init);
