//////////////////////
// INICIA SHADOWBOX //
//////////////////////
function doInit(){
	Shadowbox.init();
}

$(document).ready(function(){

/////////// ARGOLAS
/////////// ARGOLAS
	/* MÁSCARAS */
	jQuery(function($){
		// _inscricao.php
		$("#exp_uf").mask("aa");
		$("#uf").mask("aa");
		$("#telefone").mask("(99) 9999.9999");
		//$(".resetaValor5").mask("99/99/9999");// data de nascimento do animal // não funciona para as linhas duplicadas
	});
	
	// função para duplicar o TR e todo seu conteúdo para adicionar novos animais
	duplicaLinha = function(obj){
		if(obj.value.length>0){
			$("tr#trRef").clone().appendTo("#dinForm");
			
			$(".resetaValor1:last").val('');
			$(".resetaValor2:last").val('');
			$(".resetaValor3:last").val('');
			$(".resetaValor4:last").val('');
			$(".resetaValor5:last").val('');
			$(".resetaValor6:last").val('');
			$(".resetaValor7:last").val('');
			$(".resetaValor8:last").val('');
			$(".resetaValor9:last").val('');
		}
	}
/* VEREFICA DADOS */
	validaInscricao = function(){// form_cadastro.php
		//NOME
		if ($("#exp_nome").val() == ""){
			alert("Por favor informe o nome do expositor!");
			$("#exp_nome").focus();
			return false;
		}
		//LOGRADOURO 
		if ($("#exp_endereco").val() == ""){
			alert("Por favor informe o endereço!");
			$("#exp_endereco").focus();
			return false;
		}
		
		//fazenda
		 if ($("#exp_fazenda").val() == ""){
			alert("Por favor informe o nome da fazenda!");
			$("#exp_fazenda").focus();
			return false;
		}
		//cidade
		if ($("#exp_cidade").val() == ""){
			alert("Por favor informe a cidade da fazenda!");
			$("#exp_cidade").focus();
			return false;
		}
		//uf
		if ($("#exp_uf").val() == "" || $("#exp_uf").val().length < 2){
			alert("Por favor informe o estado da fazenda!");
			$("#exp_uf").focus();
			return false;
		}
		//CIDADE
		if ($("#cidade").val() == ""){
			alert("Por favor informe o nome da cidade do endereço!");
			$("#cidade").focus();
			return false;
		}
		//ESTADO
		if ($("#uf").val() == "" || $("#uf").val().length < 2){
			alert("Por favor informe o estado do endereço!");
			$("#uf").focus();
			return false;
		}
		//TELEFONE
		if ($("#telefone").val() == "" || $("#telefone").val().length < 14){
			alert("Por favor informe o telefone!");
			$("#telefone").focus();
			return false;
		}
	};
/////////// FIM ARGOLAS
/////////// FIM ARGOLAS

////////// ESTANDES
////////// ESTANDES
	// CONFIGURA A VALIDACAO DO FORMULARIO DE CONTATO
	$("#form_estande").validate({
		rules: {
			empresa: {required: true, minlength: 5},
			contato: {required: true, minlength: 5},
			telefone: {required: true}
		},
		messages: {
			empresa: {
				required: "<br /><small>Informe o nome da empresa</small>",
				minlength:"<br /><small>Informe pelo menos 5 caracteres</small>"
			},
			contato:{
				required: "<br /><small>Informe o contato</small>",
				minlength:"<br /><small>Informe pelo menos 5 caracteres</small>"
			},
			telefone: {
				required: "<br /><small>Informe seu telefone</small>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_estande .formPreloader").css("display", "block");
			$("#form_estande .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("reserva/enviar/estandes", $(form).serializeArray(), getEstandes, "json");
			return false;
		}
	});

////////// FIM ESTANDES
////////// FIM ESTANDES


////////// CONTATO
////////// CONTATO
	// CONFIGURA A VALIDACAO DO FORMULARIO DE CONTATO
	$("#form_contato").validate({
		rules: {
			nome: {required: true, minlength: 5},
			email: {required: true, email: true},
			mensagem: {required: true, minlength: 10}
		},
		messages: {
			nome: {
				required: "<br /><small>Informe o seu nome</small>",
				minlength:"<br /><small>Informe pelo menos 5 caracteres</small>"
			},
			email:{
				required: "<br /><small>Informe o seu email</small>",
				email:"<br /><small>Informe um email válido</small>"
			},
			mensagem: {
				required: "<br /><small>Digite sua mensagem</small>",
				minlength:"<br /><small>Informe pelo menos 10 caracteres</small>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_contato .formPreloader").css("display", "block");
			$("#form_contato .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("contato/enviar", $(form).serializeArray(), getContato, "json");
			return false;
		}
	});

////////// FIM CONTATO
////////// FIM CONTATO
});

getEstandes = function(rs){
	if(rs.result == "ok"){
		$("#aguardeContato").text("Reserva enviada com sucesso.");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	if(rs.result == "erro"){
		$("#aguardeContato").text("Ocorreu um erro.");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_estande .formPreloader").css("display", "none");
	$("#form_estande .btSubmit").css("display", "");
}

getContato = function(data){
	if(data.rs == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso.");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	else
	{
		$("#aguardeContato").text("Ocorreu um erro.");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_contato .formPreloader").css("display", "none");
	$("#form_contato .btSubmit").css("display", "");
}

