$(document).ready(function(){
	$("#botaoEnviar").click(function()
	{
		verificarCamposDepoimentos();
	});
});


function verificarCamposDepoimentos()
{
	var nome = $("#nome");
	vNome = $.trim(nome.val());
	var texto = $("#texto");
	vTexto = $.trim(texto.val());

	if(!vNome)
	{
		alert('Preencha o nome!');
		nome.val('');
		nome.focus();
	}
	else if(!vTexto)
	{
		alert('Preencha o texto!');
		texto.val('');
		texto.focus();
	}
	else
	{
		$.ajax({
			type: "POST",
			dataType: 'json',
			data: {nome: vNome, texto: vTexto},
			url: "depoimentos-cadastrar.php",
			success: function(data)
			{
				alert(data.resposta);
			}
		});
	}
	
}

function validaContato(){

	if ($("#nome").val() == ''){
		alert('Informe o nome!');
		$("#nome").focus();
		return false;
	}

	if ($("#from").val() == ''){
		alert('Informe o e-mail!');
		$("#from").focus();
		return false;
	} else {
		if (!checkMail($("#from").val()))	{
			alert('O e-mail informado parece estar errado!');
			$("#from").focus();
			return false;
		}
	}

	if ($("#assunto").val() == ''){
		alert('Informe o assunto!');
		$("#assunto").focus();
		return false;
	}

	if ($("#mensagem").val() == ''){
		alert('Digite sua mensagem!');
		$("#mensagem").focus();
		return false;
	}
	
	return true;

}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){ 
					return true; 
				}
	}else{
		return false;
		}
}

