var isValid = 1;

function validateForm(event) {
	//event.preventDefault();
	isValid = 1;
	$('name','company','title','telephone','email','confirmemail','comments').each(validateTextBox);
	matchTextBox($('email','confirmemail'));
	if (isValid != 1) {
		$('form_error').addClassName('formError').update('The highlighted fields are required.');
		Event.stop(event);
	} else {
		$('form_error').removeClassName('formError').update('');
	}
}

function validateTextBox(textBox) {
	if (textBox != null) {
		if (textBox.value.length === 0) {
			textBox.addClassName('error');
			$('label_'+textBox.id).removeClassName('fieldLabel').addClassName('formError');
			isValid = 0;
			return false;
		} else {
			textBox.removeClassName('error');
			$('label_'+textBox.id).addClassName('fieldLabel').removeClassName('formError');
			return true;
		}
	}
}

function matchTextBox(textBoxes) {
	if (textBoxes[1].value.length > 0) {
		if (textBoxes[0].value != textBoxes[1].value) {
			textBoxes[1].addClassName('error');
			$('label_'+textBoxes[1].id).removeClassName('fieldLabel').addClassName('formError');
			isValid = 0;
			return false;		
		} else {
			textBoxes[1].removeClassName('error');
			$('label_'+textBoxes[1].id).addClassName('fieldLabel').removeClassName('formError');
			return true;
		}
	}
}

function addObservers() {
	$('form').observe('submit',validateForm);
}

Event.observe(window,'load',addObservers);