//---------------------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(txt_fone.value == ""){
				alert('Por favor digite o telefone');
				txt_fone.focus();
				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 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 abreServico(qual, topico){
	var strImagensIni = '<IMG src="figuras/';
	var strImagensFim = '" align="left" valign="middle">';
		
	// Fecha todos antes
	document.getElementById("serv_1_1").style.display = 'none';
	document.getElementById("serv_1_2").style.display = 'none';
	document.getElementById("serv_1_3").style.display = 'none';
	document.getElementById("serv_1_4").style.display = 'none';
	document.getElementById("serv_1_5").style.display = 'none';
	document.getElementById("serv_2_1").style.display = 'none';
	document.getElementById("serv_2_2").style.display = 'none';
	document.getElementById("serv_3_1").style.display = 'none';
	document.getElementById("serv_3_2").style.display = 'none';
	document.getElementById("serv_3_3").style.display = 'none';
	document.getElementById("serv_4_1").style.display = 'none';
	// Põe todas as figuras para o lado
	document.getElementById("img_serv_1_1").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_1_2").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_1_3").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_1_4").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_1_5").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_2_1").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_2_2").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_3_1").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_3_2").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_3_3").src = 'figuras/seta_dir.gif';
	document.getElementById("img_serv_4_1").src = 'figuras/seta_dir.gif';
	
	// Abre o serviço apenas se não estiver selecionado
	if(document.frm_servicos.qualServico.value != qual || document.frm_servicos.qualTopico.value != topico){
		
		// Abre o serviço
		qualCampo = "serv_" + qual.toString() + "_" + topico.toString();
		caixaServico = document.getElementById(qualCampo);
		caixaServico.style.display = '';
		
		// Muda cor do link
		qualLinkServ = "linkAbreServ_" + qual.toString() + "_" + topico.toString();
		linkServ = document.getElementById(qualLinkServ);
		linkServ.style.color = '#69b87b';
		
		// Muda a setinha para baixo
		qualIMG = "img_serv_" + qual.toString() + "_" + topico.toString();
		imgSeta = document.getElementById(qualIMG);
		imgSeta.src = 'figuras/seta_baixo.gif';
		
		if(document.frm_servicos.qualServico.value != qual)
			window.open('mostra-imagens.php?qual=serv_'+qual.toString(), 'ifr_atualiza');
		
		// Guarda o numero do seriço e do topico para a proxima chamada
		document.frm_servicos.qualServico.value = qual;
		document.frm_servicos.qualTopico.value = topico;
	}else{
		// Zera a variavel HTML
		document.frm_servicos.qualServico.value = 0;
		document.frm_servicos.qualTopico.value = 0;
		
		// Abre o serviço
		qualCampo = "servic";
		window.open('mostra-imagens.php?qual='+qualCampo, 'ifr_atualiza');
	}
	
	// Move a tela para cima
	if(qual < 3)
		window.scrollTo(0,210);
}

function abreLink(qual){
		
	// Fecha todos antes
	document.getElementById("link_1").style.display = 'none';
	document.getElementById("link_2").style.display = 'none';
	document.getElementById("link_3").style.display = 'none';
	document.getElementById("link_4").style.display = 'none';
	// Põe todas as figuras para o lado
	document.getElementById("img_link_1").src = 'figuras/seta_dir.gif';
	document.getElementById("img_link_2").src = 'figuras/seta_dir.gif';
	document.getElementById("img_link_3").src = 'figuras/seta_dir.gif';
	document.getElementById("img_link_4").src = 'figuras/seta_dir.gif';
	
	// Abre o serviço apenas se não estiver selecionado
	if(document.frm_servicos.qualImg.value != qual){
		
		// Abre o serviço
		qualCampo = "link_" + qual.toString();
		caixaServico = document.getElementById(qualCampo);
		caixaServico.style.display = '';
		
		// Muda a setinha para baixo
		qualIMG = "img_link_" + qual.toString();
		imgSeta = document.getElementById(qualIMG);
		imgSeta.src = 'figuras/seta_baixo.gif';
		
		// Guarda o numero do seriço para a proxima chamada
		document.frm_servicos.qualImg.value = qual;
	}else{
		// Zera a variavel HTML
		document.frm_servicos.qualImg.value = 0;
	}
	
	// Move a tela para cima
	window.scrollTo(0,210);
}

function carregaFilme(){
	var so = new SWFObject("topo.swf", "mymovie", "100%", "100%", "7", "#336699");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.addParam("salign", "t");
	so.write("animacao");
}



function validaForm(){
	with(document.frm_contato){
		if (nome.value == ""){
			alert('Preencha o campo nome');
			nome.focus();
			return false;
		}else if (!validaEmail(email, "frm_contato", 2)){
				email.focus();
				email.select();
				return false;
			}else{
				submit();
				return true;
			}
	}

}
