//---------------------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;
		}
	}
}


function ajustarFone(input, evento){
	var tecla = evento.keyCode;
	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;
		}
	}
}	
	

	