//---------------------ATENÇÃO-----------------------//
//-----TODOS OS CÓDIGOS UTILIZADOS NESSA PÁGINA------//
//----SÃO DE AUTORIA DA GENIART E DEMAIS AUTORES-----//
//-------DEVIDAMENTE IDENTIFICADOS PELO NOME.--------//
//------A UTILIZAÇÃO INDEVIDA DOS CÓDIGOS SEM O------//
//------CONSENTIMENTO POR PARTE DA GENIART SERÁ------//
//---TRATADO SEGUNDO AS LEIS DE DIREITOS AUTORAIS----//
//---------------------------------------------------//

function validaCampos(qual){
	if(qual == "2"){
		with (document.frm_cadastro){
			if(txt_nome.value == ""){
				alert('Por favor informe seu nome');
				txt_nome.focus();
				return false;
			}
			if(txt_email.value == ""){
				alert('Por favor informe seu e-mail');
				txt_email.focus();
				return false;
			}else if (!validaEmail(txt_email, "frm_contato", 2)){
				txt_email.focus();
				txt_email.select();
				return false;
			}else{
				submit();
				return true;
			}
		}
	}else if(qual == "1"){
		with (document.frm_contato){
			if(txt_nome.value == ""){
				alert('Por favor informe seu nome');
				txt_nome.focus();
				return false;
			}
			if(txt_email.value == ""){
				alert('Por favor informe seu e-mail');
				txt_email.focus();
				return false;
			}else if (!validaEmail(txt_email, "frm_contato", 2)){
				txt_email.focus();
				txt_email.select();
				return false;
			}
			if(ls_assunto.value == "NM"){
				alert('Por favor selecione o assunto');
				ls_assunto.focus();
				return false;
			}
			if(txt_mensagem.value == ""){
				alert('Por favor digite uma mensagem');
				txt_mensagem.focus();
				return false;
			}
			
			if(ls_conheceu.value == "NM"){
				alert('Por favor informe como nos conheceu');
				ls_conheceu.focus();
				return false;
			}else{
				var indic = document.getElementById("cont_indique");
				if(indic.style.display == ""){
					if (txt_indicacao.value == ""){
						alert('O campo ESPECIFIQUE é de preenchimento obrigatório.');
						txt_indicacao.focus();
						return false;
					}
				}
			}
			submit();
			return true;
		}
	}else if(qual == "3"){
		with (document.frm_opniao){
			if(ls_pousada.value == "NM"){
				alert('Por favor informe o nome da pousada que você está avaliando');
				ls_pousada.focus();
				return false;
			}else{
				submit();
				return true;
			}
		}
	}
}

function validaExcursao() {
	with (document.frm_cadastro) {
		
		if (ls_evento.value == "0"){
			alert('O campo evento é de preenchimento obrigatório');
			ls_evento.focus();
			return false;
		}else
		
		if (st_coodernador.value == ""){
			alert('O campo coordenador é de preenchimento obrigatório');
			st_coodernador.focus();
			return false;
		}else
		
		if (estado.value == "0"){
			alert('O campo estado é de preenchimento obrigatório');
			estado.focus();
			return false;
		}else
		if (st_cidade.value == "0"){
			alert('O campo cidade é de preenchimento obrigatório');
			st_cidade.focus();
			return false;
		}else
		if (st_telefone.value == ""){
			alert('O campo telefone é de preenchimento obrigatório');
			st_telefone.focus();
			return false;
		}else
		if (st_email.value == ""){
			alert('O campo e-mail preenchimento obrigatório');
			st_email.focus();
			return false;
		}else if (!validaEmail(st_email, "frm_cadastro", 2)){
			st_email.focus();
			st_email.select();
			return false;
		}else
		if (dt_dia_partida.value == ""){
			alert('O campo Dia da partida é de preenchimento obrigatório');
			dt_dia_partida.focus();
			return false;
		}else
		if (dt_dia_chegada.value == ""){
			alert('O campo Dia da chegada é de preenchimento obrigatório');
			dt_dia_chegada.focus();
			return false;
		}else
		{
			submit();
			return true;
		}
	}
}


		

function criaLista(p, l){
// 	if(l == "bairro"){
// 		with(document.frm_busca){
// 			for(var i = 0; i < ls_bairro.options.length; i++){
// 				ls_bairro.options[i] = '';
// 			}
// 		}
// 	}
	window.open('cria_lista.php?listar=' + l + '&p=' + p, 'ifr_executa');
}

function mostraImagem(a,l,f){
	l = eval(l) + 17;
	a = eval(a) + 4;
	pg = f;
	if(a > 520) a = 520
	if(l > 650) l = 650
	nova_janela = window.open('','mostra_imagem','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width=' +l+ ',height=' + a);
	nova_janela.document.writeln('<HTML><HEAD><TITLE></TITLE></HEAD><BODY style="margin=0px;text-align=center;"><IMG style="cursor=hand;" src="'+pg+'" onClick="window.close()" alt="Clique na imagem para fechar"></BODY></HTML>');
	nova_janela.document.close();
}

function validaEmail(email, formu, tipo){
	var sMail = new String(email.value)
	var index = sMail.indexOf("@");
	if (index > 0){
		var pindex = sMail.indexOf(".",index);
		if ((pindex > index+1) && (sMail.length > pindex+1)){
			result = true;
		}else{
			result = false;
		}
	}else{
		result = false;
	}
	if(!result){
		alert('EMAIL inexistente, por favor insira um e-mail válido.');
		if(tipo == 1){
			formu.elements[0].focus();
			formu.elements[0].select();
		}
	}else{
		if(tipo == 1){
			formu.submit();
		}else{
			return result;
		}
	}
}


//Formata CEP
function ajustarCep(input, evento){
	if(!soNumero(evento)){
		return false;
	} else { 
		if (input.value.length == 5) {
		   input.value = input.value + "-";
		}
	}
	return true;
}


function ajustarFone(input, evento){
	var ie = (typeof window.ActiveXObject != 'undefined');  
	var tecla;  
	if (ie)
		tecla = evento.keyCode;
	else
		tecla = evento.which;
	valor = input.value;
	valor = valor.replace( "(", "" );
	valor = valor.replace( ")", "" );
	valor = valor.replace( " ", "" );
	valor = valor.replace( "-", "" );
	tamanhoMaximo = 10;
	tamanho = valor.length;
	if(!soNumero(evento)){
		return false;
	} else { 
		if (tamanho < tamanhoMaximo && tecla != 8) {
		tamanho = valor.length + 1 ;
		}
		if (tecla == 8 ) {
			tamanho = tamanho - 1 ;
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
			if ( tamanho <= 4 ) { 
				input.value = valor ;
			}
			if ( (tamanho > 4) && (tamanho <= 8) ) {
				input.value = valor.substr(0,tamanho-4) + '-' + valor.substr( tamanho - 4, tamanho ) ;
			}
			if ( (tamanho >= 9) && (tamanho <= 10) ) {
				input.value = '(' + valor.substr(0,2) + ') ' + valor.substr(2,tamanho-6) + '-' + valor.substr(tamanho-4,tamanho) ;			
			}
		}
	}
	return true;
}

//Completa a data com as barras "/"
function ajustarData(input, evento){
    if(!soNumero(evento)){
	    return false;
	} else { 
		if ((input.value.length == 2)||(input.value.length == 5)) {
		   input.value = input.value + "/" ;
		   }
	}
	return true;
}

function soNumero(evento){
	var BACKSPACE=  8; 
	var TAB= 9;
    var DEL=  46; 
    var FRENTE=  39; 
    var TRAS=  37; 
    var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
    
    if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)||(tecla == TAB)){
         return true; 
	}
    if ( tecla == 13 )     return false; 

	if ((tecla >= 48 && tecla <= 57) || (tecla == 44)) {
		return true;
	}else{
		evento.returnValue = false; 
		return false;
	}
}

function abreDigitacao(fim, tpCampos, sel){
	var campo1 = document.getElementById("tt_indique");
	var campo2 = document.getElementById("cont_indique");
	if(tpCampos == 2){
		if((sel != "Indicacao") && (sel != "Outros")){
			fim = 0;
		}
	}
	if(fim == 1){
		campo1.style.display="";
		campo2.style.display="";
	}else if(fim == 0){
		campo1.style.display="none";
		campo2.style.display="none";
	}
}

function abrePop(){
	window.open('', 'pop', 'width = 600, height = 500 ')
	}
	
	
function validaReserva(){
	with(frm_reserva){
		if (txt_nome.value == ""){
			alert('O campo nome preenchimento obrigatório');
			txt_nome.focus();
			return false;
		}else if (txt_email.value == ""){
			alert('O campo e-mail preenchimento obrigatório');
			txt_email.focus();
			return false;
		}else if (!validaEmail(txt_email, "frm_reserva", 2)){
			txt_email.focus();
			txt_email.select();
			return false;
		}else if (txt_chegada.value == ""){
			alert('O campo Data de Chegada preenchimento obrigatório');
			txt_chegada.focus();
			return false;
		}else if (txt_saida.value == ""){
			alert('O campo Data de saida preenchimento obrigatório');
			txt_saida.focus();
			return false;
		}else if (txt_fone.value == ""){
			alert('O campo Telefone preenchimento obrigatório');
			txt_fone.focus();
			return false;
		}else if (txt_qtde.value == ""){
			alert('O campo Qtde de adultos preenchimento obrigatório');
			txt_qtde.focus();
			return false;
		}else if (txt_fone.value == ""){
			alert('O campo Qtde de adultos preenchimento obrigatório');
			txt_fone.focus();
			return false;
		}else{
			submit();
			return true;
		}
	}
}	
	

function validaCadastroCoordenador(){
	with(document.frm_cadastro_coordenador){
		if (st_nome.value == ""){
			alert("Insira seu Nome.");
			st_nome.focus();
			return false;
		}else if (st_endereco.value == ""){
			alert("Insira seu Endereço.");
			st_endereco.focus();
			return false;
		}else if (st_cidade.value == ""){
			alert("Insira sua Cidade.");
			st_cidade.focus();
			return false;
		}else if (st_fone.value == ""){
			alert("Insira seu Telefone.");
			st_fone.focus();
			return false;
		}else if (st_email.value == ""){
			alert("Insira seu Email.");
			st_email.focus();
			return false;
		}else if (!validaEmail(st_email, "frm_cadastro_coordenador", 2)){
			st_email.focus();
			return false;
		}else{
			submit();
			return true;
		}	
	}
}

function validaLoginCoordenador(){
	with(document.frm_login){
		if (st_email.value == ""){
			alert("Insira o seu Email.");
			st_email.focus();
			return false;
		}else if (!validaEmail(st_email, "frm_login", 2)){
			st_email.focus();
			return false;
		}else if (st_senha.value == ""){
			alert("Insira a sua senha.");
			st_senha.focus();
			return false;
		}else{
			submit();
			return true;
		}
	}
}


function verificaExclusaoCaravana(id){
	if(confirm('Deseja realmente excluir esta Caravana?')){
		url = 'admin-lista-excursao.php?excluir=1&id=' + id;
		window.open(url,'_self');
	}
}	


function validaCaravanas(){
	with(document.frm_cadastro){
		if(dt_dia_partida.value == ""){
			alert("Insira a Data de Partida.");
			dt_dia_partida.focus();
			return false;
		}else if (dt_dia_chegada.value == ""){
			alert("Insira a Data de Partida.");
			dt_dia_chegada.focus();
			return false;
		}else if (st_cidade.value == ""){
			alert("Insira a Cidade.");
			st_cidade.focus();
			return false;
		}else{
			submit();
			return true;
		}
	}
}




function validaEditarCoordenador(){
	with(document.frm_cadastro_coordenador){
		if (st_nome.value == ""){
			alert("Insira seu Nome.");
			st_nome.focus();
			return false;
		}else if (st_endereco.value == ""){
			alert("Insira seu Endereço.");
			st_endereco.focus();
			return false;
		}else if (st_cidade.value == ""){
			alert("Insira sua Cidade.");
			st_cidade.focus();
			return false;
		}else if (st_fone.value == ""){
			alert("Insira seu Telefone.");
			st_fone.focus();
			return false;
		}else if (st_senha.value == ""){
			alert("Insira sua Senha.");
			st_senha.focus();
			return false;
		}else if (st_confirma.value == ""){
			alert("Insira a Confirmação de Senha.");
			st_confirma.focus();
			return false;
		}else if (st_senha.value != st_confirma.value){
			alert("As Senhas não conferem.");
			st_senha.focus();
			return false;		
		}else{
			submit();
			return true;
		}	
	}
}

function mudaCidade(evento){
	//if(evento > 0){
		var url = "ifr-altera-cidade.php?evento="+evento;
		window.open(url, 'ifr_atualiza')
	//}
}

function mudaEvento(evento){
	//if(evento > 0){
		//alert(evento);
		var url = "ifr-altera-evento.php?evento="+evento;
		window.open(url, 'ifr_atualiza')
	//}
}


function verificaBuscaCaravana(){
	with(document.frm_cadastro){
		if (ls_tipo_evento.value == "0" && ls_evento.value == "0" && st_cidade.value == "0" && ls_mes.value == "0"){
			alert("Para encontrar sua caravana utilize uma das buscas abaixo.");
			return false;
		}else{
			submit();
			return true;
		}
	}
}

function verificaEmailCadastrado(){
	email = document.frm_esqueci_senha.st_email.value;
	if (email == ""){
		alert("Digite seu email.");
		return false;
	}else if(!validaEmail(document.frm_esqueci_senha.st_email, "frm_esqueci_senha", 2)){
		return false;
	}else{
		document.frm_esqueci_senha.submit();
		return true;
	}
}

function excluirImg(figura, pasta, id, pg, nomePagina) {
	if(nomePagina != "undefined"){
		arquivo = pasta.substr(4,pasta.length);
	}else{
		arquivo = "imagem";
	}

	// essa linha não ta certa não
// 	confirmacao = window.confirm("Atenção! Você tem certeza que deseja retirar este " + arquivo + " deste registro?");
	confirmacao = window.confirm("Atenção! Você tem certeza que deseja retirar esta imagem deste registro?");

	if (confirmacao){
		dados = 'pasta=' + pasta + '&img='+ figura + "&id=" + id + "&pg=" + pg;
		if(nomePagina != "undefined") dados = dados + "&pagina=" + nomePagina;
		window.open("exclui_img.php?" + dados, "_self");
	}
}


function escondeDivSetor(id){
	document.getElementById("mostra_setores_"+id).style.display = 'none';
}

function mostraDivSetor(id){
	document.getElementById("mostra_setores_"+id).style.display = '';
}
