// JavaScript Document
$(document).ready(function() {
	$('#contato_mensagem').limit('1024','#restantes');
	$("abbr.timeago").timeago();
	
});

$(".submit_contato").corner();

//valida um endereço de email
//o nome da função não pode ser alterado
function validaEmail(email) {
	if ((email.length == 0) || (email.indexOf("@") < 3)) {
		return false;
	}
}

function valida_form() {
	var nome = document.getElementById('contato_nome');
	var email = document.getElementById('contato_email');
	var empresa = document.getElementById('contato_empresa');
	var telefone = document.getElementById('contato_telefone');
	var assunto = document.getElementById('contato_assunto');
	var mensagem = document.getElementById('contato_mensagem');

	//se existir o campo de CURSO, valida-o | esse campo só existe no form de inscrições | os actions de todos os forms são iguais
	if (document.getElementById('contato_curso')) {
		var curso = document.getElementById('contato_curso');
		if (curso.value == '') {
			$.prompt('Em qual o curso você deseja se inscrever?');
			return false;
		}
	}

	if (nome.value == '') {$.prompt('O campo NOME é obrigatório');return false;}
	if (validaEmail(email.value) == false) { $.prompt('O campo EMAIL está incorreto'); return false; }
	if (empresa.value == '') {$.prompt('O campo EMPRESA é obrigatório');return false;}
	if (telefone.value == '') {$.prompt('O campo TELEFONE é obrigatório');return false;}
	if (assunto.value == '0') {$.prompt('O ASSUNTO da mensagem é obrigatório');return false;}
	if (mensagem.value == '') {$.prompt('A MENSAGEM é obrigatória');return false;}
	
	$.blockUI({ message: null }); //dark screen
}

//function´s signup on newsletter
function valida_rss() {
	var nome = document.getElementById('rss_nome');
	var email = document.getElementById('rss_email');

	if (nome.value == '') {$.prompt('O campo NOME é obrigatório');return false;}
	if (validaEmail(email.value) == false) { $.prompt('O campo EMAIL está incorreto'); return false; }

	//verifica se update está selecionada
	//as validações abaixo só são feitas se a pessoa escolher receber a update
	var check = document.getElementById('opcao_update');
	var check_guia = document.getElementById('opcao_guia');
	if (check.checked == true || check_guia.checked == true) {
		//valida campos update
		var campo_endereco = document.getElementById('endereco');
		var campo_bairro = document.getElementById('bairro');
		var campo_cidade = document.getElementById('cidade');
		var campo_uf = document.getElementById('uf');
		var campo_cep = document.getElementById('cep');

		if ((campo_endereco.value == '') || (campo_endereco.value.length < 5)) {alert('O campo ENDEREÇO é obrigatório');campo_endereco.focus();return false;}
		if ((campo_bairro.value == '') || (campo_bairro.value.length < 3)) {alert('O campo BAIRRO é obrigatório');campo_bairro.focus();return false;}
		if ((campo_cidade.value == '') || (campo_cidade.value.length < 3)) {alert('O campo CIDADE é obrigatório');campo_cidade.focus();return false;}
		if (campo_uf.value == 'ni') {alert('O campo ESTADO é obrigatório');campo_uf.focus();return false;}
		if ((campo_cep.value == '') || (campo_cep.value.length < 8)) {alert('O campo CEP é obrigatório');campo_cep.focus();return false;}
	}
}

//exibe os campos para preencher o endereço de recebimento da update
function exibe_update() {
	var check = document.getElementById('opcao_update');
	if (check.checked == true) $("#campos_rss_update").slideDown();else $("#campos_rss_update").slideUp();
}
//fim newsletter

//exibe os campos para preencher o endereço de recebimento do guia
function exibe_guia() {
	var check = document.getElementById('opcao_guia');
	if (check.checked == true) $("#campos_rss_update").slideDown();else $("#campos_rss_update").slideUp();
}
//fim guia

//validação do campo busca
function valida_busca() {
	var termo = document.getElementById('termo_busca');
	if (termo.value == '' || termo.value == 'Busca...') {
		$.prompt('É necessário uma palavra-chave para buscar');	
		return false;
	}
}
//fim busca

//campos NOME e EMAIL_DESTINATÁRIO no compartilhamento de notícias e conteúdo por email
function valida_share_email() {
	var nome = document.getElementById('share_nome');
	var email = document.getElementById('share_email');
	
	if (nome.value == '' || nome.value == 'Seu nome') {
		$.prompt('O campo NOME é obrigatório');
		return false;
	}
	if (validaEmail(email.value) == false) {
		$.prompt('O email informado está incorreto');
		return false;
	}
}

//exibe os campos de compartilhamento por email
function abre_shareEmail() {
	var div = document.getElementById('shareEmail');
	if (div.style.display == 'none') $(div).slideDown();
		else
	$(div).slideUp();
}

//função de validação do template de hotsites
function validaParticipacao() {
	var nome = document.getElementById('hot_nome');
	var empresa = document.getElementById('hot_empresa');
	var email = document.getElementById('hot_email');

	if (nome.value == '') {
		$.prompt('Qual é seu nome?');
		return false;
	}

	if (empresa.value == '') {
		$.prompt('O campo EMPRESA é obrigatório');
		return false;
	}

	if (validaEmail(email.value) == false) {
		$.prompt('O email está incorreto');
		return false;
	}
}
