var regulamento_elem;
var comoparticipar_elem;
var content_elem;
var caracteresNum;
var perguntaFinal;

window.addEvent('domready', function() {

	regulamento_elem = $('regulamento');
	comoparticipar_elem = $('comoparticipar');
	oque_elem = $('oque');
	
	content_elem = $('body').getChildren();
	content_elem = content_elem[0];

	perguntaFinal = $('perguntaFinal');
	caracteresNum = $('caracteresNum');
	
	errors_elem = $('errors');
	
	if( errors_elem ) {
		errors_elem.addEvent('click', function() {
			errors_elem.setStyle('display', 'none');
		});
		
		$('body').addEvent('click', function() {
			errors_elem.setStyle('display', 'none');
		});
	}
	
	function updateCharsNum() {
		var str = perguntaFinal.get('value');
		if( !str ) { return; }
			
		var len = str.length;
		if( len > 255 ) {
			perguntaFinal.set('value', str.substr(0, 255));
			len = 255;
		}
			
		caracteresNum.set('html', 'Caracteres: ' + (255 - len));
	}
	
	function updateCharsNumLoop() {
		updateCharsNum();
		updateCharsNumLoop.delay(500);
	}
	
	if( perguntaFinal && caracteresNum ) {
		
		perguntaFinal.addEvent('change', function() {
			updateCharsNumLoop();
		});
		
		updateCharsNumLoop.delay(500);
	}
});

function hide_body() {
	$('body').getChildren().each(function(item) {
		item.setStyle('display', 'none');
	})
}
	
function reset_body() {
	$('body').getChildren().each(function(item) {
		item.setStyle('display', 'block');
	})
	regulamento_elem.setStyle('display', 'none');
	comoparticipar_elem.setStyle('display', 'none');
	if( oque_elem ) {
		oque_elem.setStyle('display', 'none');
	}
}
	
function show_regulamento() {
	hide_body();
	regulamento_elem.setStyle('display', 'block');
}
	
function show_comoparticipar() {
	hide_body();
	comoparticipar_elem.setStyle('display', 'block');
}
