elemento = document.getElementById;
function Muda(id, estado, menu, imagem) // Muda o CSS do menu destinos
//Função que muda o estido do botão
// parametros:
// id     -> qual botão ta sendo trocado
// estado -> qual className que o botão vai receber over / out
// imagem -> Qual imagem vai ser trocada
	{
		elemento(id).className = estado;
		elemento(menu).src = "imagens/"+imagem;
	}
function ChecaPesquisa()
	{
	if (elemento('destino').options[elemento('destino').selectedIndex].value == '')
		{
		alert('Por favor\nSelecione um destino');
		return false;
		}
	if (elemento('atividade').options[elemento('atividade').selectedIndex].value == '')
		{
		alert('Por favor\nSelecione uma atividade');
		return false;
		}

	}
function Exibir(foto)
		{
		JanelaPop('/exibe_foto.asp?foto='+foto,'foto','600','444','no')
		}
function ValidaNumero(objeto)
		{
			campo = eval(objeto)
			if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))event.returnValue = true;
			else
				{
					alert ('O campo só aceita valores numéricos!');
					eval(campo).focus();
					event.returnValue = false;
				}
		}
		
	function ValidaMoeda(objeto)
		{
			input = eval(objeto)
			if(((event.keyCode > 47) && (event.keyCode < 58)) ||
			((event.keyCode == 13) || (event.keyCode == 44) || (event.keyCode == 46)))event.returnValue = true;
			else
				{
					alert ('O campo só aceita valores numéricos!');
					eval(input).focus();
					event.returnValue = false;
				}
		}
		
	function Mascaradata(formato, objeto)
		{
			input = eval(objeto)
			if(formato == 'data')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 2)input.value += '/';
							else if (input.value.length == 5)input.value += '/';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
	        	}
		}
	
	function validadatanumero(S)
		{
			var temp = '';
			for(var i = 0; i < S.length; i++)
				{
					if(S.charAt(i) != '/')temp += S.charAt(i);
				}
			return temp
		}
	
	function validadata(objeto, anoatual)
		{
			input = eval(objeto)
			if(isNaN(validadatanumero(input.value)))
				{
					alert('O campo só aceita valores numéricos!')
					eval(input).select()
					return (false)
				}
			else
				{
					var dia = input.value.slice(0, 2)
					var mes = input.value.slice(3, 5)
					var ano = input.value.slice(6, 10)
					
					var bissexto = ((ano % 4 == 0) && ((ano % 100 != 0) || (ano % 400 == 0)));
					if(input.value.length < 10)
						{
							alert('Data inválida. A data deve estar no formato: dd/mm/yyyy!')
							eval(input).select()
							return false
						}
					else if(ano < 1900)
						{
							alert('Ano inválido. O ano deve ser maior 1900!')
							eval(input).select()
							return false
						}
					else if(ano > anoatual)
						{
							alert('Ano inválido. O ano deve ser menor ou igual a '+ anoatual +'!')
							eval(input).select()
							return false
						}
					else if((mes <= 0) || (mes > 12))
						{
							alert('Mês inválido.!')
							eval(input).select()
							return false
						}
					else if((mes == 2) && ((dia > 29) || ((dia == 29) && (!bissexto))))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else if(((mes == 1) || (mes == 3) || (mes == 5) || (mes == 7) || (mes == 8) || 
					(mes == 10) || (mes == 12)) && ((dia <= 0) || (dia > 31)))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else if(((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && 
					((dia <= 0) || (dia > 30)))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else return true;
				}
		}
	
	function createNewDate(d)
		{
			var dia = d.slice(0, 2)
			var mes = d.slice(3, 5)
			ano = d.slice(6, 10)
			data = new Date(ano +'/'+ mes +'/'+ dia)
			return (data)
		}
	
	function MascaraCNPJ(formato, objeto)
		{
			input = eval(objeto);
			if(formato == 'cnpj')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if(input.value.length == 2)input.value += '.';
							else if(input.value.length == 6)input.value += '.';
							else if (input.value.length == 10)input.value += '/';
							else if (input.value.length == 15)input.value += '-';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}

	function Mascaracpf (formato, objeto)
		{
			input = eval(objeto);
			if(formato == 'cpf')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 3)input.value += '.';
							else if (input.value.length == 7)input.value += '.';
							else if (input.value.length == 11)input.value += '-';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}
	
	function Mascaracep (formato, objeto)
		{
			input = eval (objeto);
			if(formato == 'cep')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 5)input.value += '-';
						}
					else 
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}
	
	function validacpf(objeto)
		{
			input = eval(objeto)
			var invalidos = new Array('000.000.000-00', '111.111.111-11', '222.222.222-22', '333.333.333-33', '444.444.444-44', '555.555.555-55', '666.666.666-66', '777.777.777-77', '888.888.888-88', '999.999.999-99');
			var valida = false;
			for(i = 0; i < invalidos.length; i++)
				{
					if(input.value == invalidos[i])
						{
							valida = true;
							break;
						}
				}
			if(valida)
				{
					alert ('CPF inválido. Favor verificar!');
					eval(input).focus();
					return false;
				}
			else
				{
					var s = limpa_string(input.value)
					var dv1 = dv2 = cpf = soma = p1 = 0;
					var d1 = '098765432';
					var d2 = '1098765432';
					var c1 = parseInt(s.slice(9, 10))
					var c2 = parseInt(s.slice(10, 11))
					var pri1 = s.slice(0, 9)
					var pri2 = s.slice(0, 10)
					
					for(i = 0; i < 9; i++)
						{
							if(d1.slice(i, (i + 1)) == '0')cpf = (10 * parseInt(pri1.slice(i, (i + 1))));
							else cpf = (parseInt(d1.slice(i, (i + 1))) * parseInt(pri1.slice(i, (i + 1))));
							soma += cpf;
						}
					
					dv1 = parseInt((soma % 11));
					if((dv1 == 0) || (dv1 == 1))dv1 = 0;
					else dv1 = (11 - dv1);
					
					if(c1 != dv1)
						{
							alert ('O primeiro dígito verificador do seu CPF não é válido. Favor verificar!');
							eval(input).focus();
							return false;
						}
					
					cpf = soma = 0;
					for(i = 0; i < 10; i++)
						{
							if(d2.slice(i, (i + 1)) == '1')cpf = (11 * parseInt(pri2.slice(i, (i + 1))));
							else if(d2.slice(i, (i + 1)) == '0')cpf = (10 * parseInt(pri2.slice(i, (i + 1))));
							else cpf = (parseInt(d2.slice(i, (i + 1))) * parseInt(pri2.slice(i, (i + 1))));
							soma += cpf;
						}
					
					dv2 = parseInt((soma % 11));
					if ((dv2 == 0) || (dv2 == 1))dv2 = 0;
					else dv2 = (11 - dv2);
					
					if (c2 != dv2)
						{
							alert ('O segundo dígito verificador do seu CPF não é válido. Favor verificar!');
							eval(input).focus();
							return false;
						}
				}
		}
	
	function limpa_string(S)
		{
			var Digitos = '0123456789';
			var temp = '';
			var digitos = '';
		
			for(var i = 0; i < S.length; i++)
				{
					digitos = S.charAt(i);
					if(Digitos.indexOf(digitos) >= 0)
						{
							temp = temp + digitos
						}
				}
			return temp
		}
	
	function valida_CNPJ(s)
		{
			var i;
			input = eval(s);
			s = limpa_string(input.value);
			var c = s.substr(0, 12);
			var dv = s.substr(12, 2);
			var d1 = 0;
			
			for (i = 0; i < 12; i++)
				{
					d1 += c.charAt(11 - i) * (2 + (i % 8));	
				}
			if(d1 == 0) return false;
			d1 = 11 - (d1 % 11);
			if(d1 > 9) d1 = 0;
			if(dv.charAt(0) != d1)
				{
					alert ('Primeiro dígito verificador inálido!');
					eval(input).focus();
					return false
				}
			d1 *= 2;
		
			for(i = 0; i < 12; i++)
				{
					d1 += c.charAt(11-i) * (2 + ((i + 1) % 8));
				}
			d1 = 11 - (d1 % 11);
			if(d1 > 9) d1 = 0;
			if(dv.charAt(1) != d1)
				{
					alert ('Segundo dígito verificador inálido!');
					eval(input).focus();
					return false
				}
			return true;
		}
	
	function PG(n)
		{
			var form = window.document.nav;
			form.CurrentPage.value = n;
			form.submit();
		}
	
	function validamail(obj)
		{
			input = eval(obj)
			if(input.value != '')
				{
					if((input.value.indexOf('@') < 0) || (input.value.indexOf('@') == 0) ||
					(input.value.substring((input.value.indexOf('@') + 1), input.value.length).indexOf('.') < 0) ||
					(input.value.charAt(input.value.indexOf('@') + 1) == '.'))
						{
							alert('E-mail inválido. Exemplo de um e-mail válido: jph@jph.com.br!')
							eval(input).focus()
							return false
						}
					else return true;
				}
		}
	
	function insereQuebraLinha(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if(fe[i].type == 'textarea') fe[i].value = fe[i].value.replace(/\n/g, '<br />');
				}
		}
	
	function insereContraBarran(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if(fe[i].type == 'textarea')
						{
							do
								fe[i].value = fe[i].value.replace('<br />', '\n');
							while(fe[i].value.indexOf('<br />') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<br>', '\n');
							while(fe[i].value.indexOf('<br>') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<BR>', '\n');
							while(fe[i].value.indexOf('<BR>') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<Br>', '\n');
							while(fe[i].value.indexOf('<Br>') > -1);
						}
				}
		}
	
	function TrimReplace(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if((fe[i].type == 'text') || (fe[i].type == 'textarea'))
						fe[i].value = fe[i].value.Trim();
				}
		}
	function JanelaPop(pagina, nome, w, h, scroll)
		{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		propriedades = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
		win = window.open(pagina, nome, propriedades)
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
		}
		
	function MostraHotel(id)
		{
		var h = 478;
		var w = 500;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		propriedades = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no'
		hotel = window.open('/hoteis.asp?id='+id, 'hoteis', propriedades)
		if (parseInt(navigator.appVersion) >= 4) { hotel.window.focus();}
		}
		
	function Imprime(id)
		{
		JanelaPop('/impressao.asp?produto='+id,'impressao','550','400','yes')
		}
	function Exibir(foto)
		{
		JanelaPop('/exibe_foto.asp?foto='+foto,'foto','600','444','no')
		}
	function EnviarFotoHotel()
		{
		JanelaPop('EnviarFotoHotel.asp','foto','100','100','no')
		}

	function Mapa(foto)
		{
		JanelaPop('/exibe_foto.asp?foto='+foto,'foto','600','444','no')
		}
	function Enviar(id, caminho)
		{
		JanelaPop('/email.asp?link='+caminho,'email','350','320','no')
		}
	function popTarifario(id)
		{		
		JanelaPop('/popTarifario.asp?id='+id,'email','350','320','no')
		}		
	function ValidarFRM()
		{
		if (document.getElementById('paises').options[document.getElementById('paises').selectedIndex].value=="")
			{
			alert('Ops!\nÉ necessário selecionar um destino e uma atividade');
			return false;
			}
		if (document.getElementById('atividades').options[document.getElementById('atividades').selectedIndex].value=="")
			{
			alert('Ops!\nÉ necessário selecionar um destino e uma atividade');
			return false;
			}
		document.pesquisa.submit()
		}
	function SendEmail(id)
		{
		JanelaPop('/enviarEmail.asp?email='+id,'email','350','280','no')
		}
	function Imprimir(id, secao)
		{
		JanelaPop('/impressao.asp?id='+id+"&idsecao="+secao+'&list=1','imprimir','600','500','yes')
		}
	function Preenche(texto, valor, campo)
		{
		posicao=document.getElementById(campo).length++
		document.getElementById(campo).options[posicao] = new Option(texto,valor)
		document.getElementById(campo).selectedIndex = posicao
		}
	function PegaTecla()
		{
		return (document.all ? event.keyCode : -1);
		}
	function Deleta(campo, destino)
		{
		if (document.getElementById(campo).selectedIndex >= 0)
			{
			valor = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value
			window.location = destino+".asp?id=" + valor;
			document.getElementById(campo).options[document.geElementById(campo).selectedIndex]=null;
			document.getElementById(campo).selectedIndex=0;
			}
		}
	function Insere(campo, destino)
		{
		if (document.getElementById(campo).selectedIndex >= 0)
			{
			valor = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value
			window.location = destino+".asp?id=" + valor;
			document.getElementById(campo).options[document.geElementById(campo).selectedIndex]=null;
			document.getElementById(campo).selectedIndex=0;
			}
		}
		function validarLogin()
			{
			if (document.getElementById('txtlogin').value == '')
				{
				alert('Por favor Informe seu login');
				document.getElementById('txtlogin').focus();
				return false;
				}
			if (document.getElementById('txtsenha').value == '')
				{
				alert('Por favor Informe sua senha');
				document.getElementById('txtsenha').focus();
				return false;
				}	
				return true;
			}