document.observe('dom:loaded', function () {
	if ($('css_switch')) {
		$('css_switch').style.display = 'block';
		$('css_switch').onclick = function() {
			Element.toggleClassName('content','dark');
		}
	}

	if ($('order_form')) {
		$('order_form').onsubmit = function() {
			if ($F('customer_name').trim().length < 4) {
				alert('Vyplňte prosím kontaktné informácie.');
				$('customer_name').style.borderColor = '#c00';
				$('customer_name').style.borderBottomWidth = '3px';
				$('customer_name').focus();
				return false;
			} else {
				$('customer_name').style.borderColor = '#666';
				$('customer_name').style.borderBottomWidth = '1px';
			}

			if ($F('customer_phone').trim().length < 4) {
				alert('Vyplňte prosím kontaktné informácie - telefón.');
				$('customer_phone').style.borderColor = '#c00';
				$('customer_phone').style.borderBottomWidth = '3px';
				$('customer_phone').focus();
				return false;
			} else {
				$('customer_phone').style.borderColor = '#666';
				$('customer_phone').style.borderBottomWidth = '1px';
			}

			if ($F('customer_email').trim().length < 4) {
				alert('Vyplňte prosím kontaktné informácie.');
				$('customer_email').style.borderColor = '#c00';
				$('customer_email').style.borderBottomWidth = '3px';
				$('customer_email').focus();
				return false;
			} else {
				$('customer_email').style.borderColor = '#666';
				$('customer_email').style.borderBottomWidth = '1px';
			}

			if ($F('customer_address').trim().length < 4) {
				alert('Vyplňte prosím kontaktné informácie.');
				$('customer_address').style.borderColor = '#c00';
				$('customer_address').style.borderBottomWidth = '3px';
				$('customer_address').focus();
				return false;
			} else {
				$('customer_address').style.borderColor = '#666';
				$('customer_address').style.borderBottomWidth = '1px';
			}

			return true;
		};
	}
});


// otazka na predajcu
var defaultText = '';
var defaultName = '';
var defaultMail = '';
document.observe('dom:loaded', function () {
	if ($('feedback')) {
		defaultText = $F('feedback_text');
		Event.observe($('feedback_text'), 'focus', function() {
			if ($F('feedback_text') == defaultText) {
				$('feedback_text').update();
			}
		});
		Event.observe($('feedback_text'), 'blur', function() {
			if ($F('feedback_text') == '') {
				$('feedback_text').update(defaultText);
			}
		});
	
		defaultName = $F('feedback_name');
		Event.observe($('feedback_name'), 'focus', function() {
			if ($F('feedback_name') == defaultName) {
				$('feedback_name').setValue('');
			}
		});
		Event.observe($('feedback_name'), 'blur', function() {
			if ($F('feedback_name') == '') {
				$('feedback_name').setValue(defaultName);
			}
		});
	
		defaultMail = $F('feedback_mail');
		Event.observe($('feedback_mail'), 'focus', function() {
			if ($F('feedback_mail') == defaultMail) {
				$('feedback_mail').setValue('');
			}
		});
		Event.observe($('feedback_mail'), 'blur', function() {
			if ($F('feedback_mail') == '') {
				$('feedback_mail').setValue(defaultMail);
			}
		});


		$('feedback').onsubmit = function() {
			if (validateEmail($F('feedback_mail').trim())) {
				alert('Vyplňte prosím kontaktný email.');
				$('feedback_mail').style.borderColor = '#c00';
				$('feedback_mail').style.borderBottomWidth = '3px';
				$('feedback_mail').focus();
				return false;
			} else {
				$('feedback_mail').style.borderColor = '#666';
				$('feedback_mail').style.borderBottomWidth = '1px';
			}
			return true;
		};
	}
});


function validateEmail(elementValue){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/;
	return !emailPattern.test(elementValue);
}

