function show( ul ) {
	if( $(ul).style.display == 'none' ) {
		$(ul).style.display = 'block';
	} else {
		$(ul).style.display = 'none';
	}
}

function clearForm() {
	$('qForm').name.value = '';
	$('qForm').email.value = '';
	$('qForm').phone.value = '';
	$('qForm').desc.value = '';
	$('qForm').captcha.value = '';
}

var formCheckConfig = {
	submit: false,
	submitByAjax: true,
	flashTips: 1,
	display: {
		errorLocation: 1, 
		indicateErrors: 1, 
		showErrors: 1,
		addClassErrorToField: 1,
		titlesInsteadNames: true,
		fadeDuration: 0,
		scrollToFirst: true
	},
	onAjaxRequest: function() {
		spinner = new Spinner('content');
		spinner.show();
	},
	onAjaxSuccess: function( res ) {
		spinner.hide();
		var response = JSON.decode( res );
		if (response.success) {
			(function(){
				$('question-form').set('html', '<div style="height: 88px;padding-top:90px;padding-left:26px;color:#BABABA;">Zapytanie zostało wysłane, dziękujemy!</div>');
			}).delay(300);
		}
		else {
			if (response.data != 'error_msg') {
				var ref = $(response.data[0]);
				ref.errors.push(response.msg);
				formCheck.addError(ref);
			} else {
				(function(){
					$('question-form').set('html', '<div style="height: 88px;padding-top:90px;padding-left:26px;color:#BABABA;">' + response.msg + '</div>');
				}).delay(300);
			}
		}
	}
};

var formCheck = null;

window.addEvent('domready',function() {
	$$('a').setProperty('onfocus', 'blur()');
	
	if( $('q-form') ) {
		var textarea = $('bg-txt').getElement('textarea');
		var input = $('q-form').getElement('input');
		
		textarea.addEvent('focus',function() {
			if (this.value == 'Treść...' || this.value == 'Message...') {
				this.value = '';
			}
		});
		
		textarea.addEvent('blur',function() {
			if( this.value == '' ) {
				this.value = lang == 'pl' ? 'Treść...' : 'Message...';
			}
		});
		
		input.addEvent('focus',function() {
			this.value = '';
		});
		
		input.addEvent('blur',function() {
			if( this.value == '' ) {
				this.value = lang == 'pl' ? 'Twój e - mail' : 'Your e - mail';
			}
		});
		
		formCheck = new FormCheck('q-form', formCheckConfig);
	}
	
	$$('.blank').setProperty('target', '_blank');
});
