function validate() {
	function $(sel) {
		return (window.Element && window.Element.extend ? window.Element.extend(document.getElementById(sel)) : document.getElementById(sel));
	}

	function hideErrors(sel) {
		var container;
		if (container = $(sel)) {
			for (var x = 0, elm = container.childNodes[x]; x < container.childNodes.length; ++x, elm = container.childNodes[x]) {
				if (elm.tagName && elm.className && elm.className.indexOf('error') != -1) {
					elm.style.display = 'none';
				}
			}
		}
	}

	function showError(sel) {
		if ($(sel)) {
			$(sel).style.display = '';
		}
	}

	function strTrim(str) {
		return str.replace(/\s+/, ' ').replace(/^\s+/, '').replace(/\s$/, '');
	}

	hideErrors('holder_errors');

	if (!$('vote_option_0').checked && !$('vote_option_1').checked && !$('vote_option_2').checked) {
		showError('error_vote_options');
		return false;
	}

	$('name').value = strTrim($('name').value);
	if (!$('name').value.length) {
		showError('error_name');
		return false;
	}

	$('location').value = strTrim($('location').value);
	if (!$('location').value.length) {
		showError('error_location');
		return false;
	}

	if (!parseInt($('age').value)) {
		showError('error_age');
		return false;
	}

	$('email').value = strTrim($('email').value);
	if (!$('email').value.length || !$('email').value.match(/^[0-9A-Za-z._-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})$/)) {
		showError('error_email');
		return false;
	}

	$('phone').value = strTrim($('phone').value);
	if ($('phone').value.length && !$('phone').value.match(/^[0-9\s-]+$/)) {
		showError('error_phone');
		return false;
	}

	$('main_form').submit();
}
