//-------------------------------------Cria o objeto Ajax
function createXMLHTTP()
{
//Caso seja IE usa o código abaixo
if (navigator.appName=="Microsoft Internet Explorer")
{

	var arrSignatures = ["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i=0; i < arrSignatures.length; i++)
		{
			try
			{
				var oRequest = new ActiveXObject(arrSignatures[i]);
                return oRequest;
            }
			catch (oError)
			{
				throw new Error("Esse browser não tem recursos para uso do Ajax."+oError);
            }
        }

}

//Caso contrário utiliza este código
else
{
	try
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
			catch(ex)
			{
				try
				{
					ajax = new XMLHttpRequest();
				}
				catch(exc)
				{
					alert("Esse browser não tem recursos para uso do Ajax");
					ajax = null;
				}
			}
		return ajax;
	}
}
		   
}


//-----------------------------------------Posta e recebe as informações do menu principal
function ajax(Nome)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./ajax/execfunc.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('menu').innerHTML="<img src='./img/ajax3.gif' alt='Carregando menu' width='150'>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('menu').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("Nome=" + Nome);
//Chama a função de cotação de moedas
	promocao();

			if (document.getElementById('conteudo').offsetHeight>922)
			{
				document.getElementById('menu').style.height = (document.getElementById('conteudo').offsetHeight + 350) + "px";
			}

}

//------------------------------------------Exibe ou não os subitens do menu principal
function subItem(id)
{
	var id = id;
	var titulo = "subItem" + id;
	var estado = document.getElementById(titulo).style.display;

	if (estado=="none")
	{
		document.getElementById(titulo).style.display = "";
	}
	else
	{
		document.getElementById(titulo).style.display = "";
	}
}


//------------------------------------------Posta e recebe o conteudo da página de acordo com o item do menu selecionado
function conteudo(id)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "conteudo.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('meio').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('meio').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=" + id);
}


//------------------------------------------Posta e recebe o conteudo da página de acordo com o item do menu selecionado
function abreConteudo(id,aba)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "conteudo.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('meio').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('meio').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=" + id+"&aba="+aba);
}


//-------------------------------------------Recebe a cotação de moedas
function cotacaoMoedas()
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "Default.aspx", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('dolar').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('dolar').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=1");
}

//--------------------------------------------Gera o menu de acesso rápido
function topo()
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "menuTopo.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('menuTopo').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('menuTopo').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=1");
}


//--------------------------------------------Função para exibição dos subitens do menu de acesso rápido
function mostraSubMenu(id)
{
	document.getElementById('mostraSub'+id).style.display = "";
	document.getElementById('menuTopo').style.display = "";
}
function escondeSubMenu(id)
{
	document.getElementById('mostraSub'+id).style.display = "none";
	document.getElementById('menuTopo').style.display = "none";
}
function mostraTudo()
{
	document.getElementById('menuTopo').style.display = "";
}

function setVariables() {
if (navigator.appName == "Netscape") {
v=".top=";
dS="document.";
sD="";
y="window.pageYOffset";
}
else {
v=".pixelTop=";
dS="";
sD=".style";
y="document.body.scrollTop";
   }
}
function checkLocation() {
object="menuTopoTotal";
yy=eval(y);
eval(dS+object+sD+v+yy);
setTimeout("checkLocation()",10);
}

//--------------------------------------Função que exibe a lista de resorts do link do menu acesso rápido
function abreResorts()
{
document.getElementById('todosResorts').style.display = "";
}

function fecharResorts()
{
document.getElementById('todosResorts').style.display = "none";
}

//--------------------------------------Cria uma lista com todos os Resorts cadastrados
function listaResorts()
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "listaResorts.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('listaResortsBox').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('listaResortsBox').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=1");
}

//-----------------------------------------Preenche a div meio com conteudo da página inicial
function abrePagina(url)
{
	location.href = url;
}


//-------------------------------------------Recebe a promoção em destaque
function promocao()
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./ajax/promocao.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('promocao').innerHTML="<img src='./img/ajax3.gif' alt='Carregando menu' width='150'>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('promocao').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=1");
}

//-------------------------------------------Recebe a promoção em destaque
function busca()
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./ajax/busca.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('busca').innerHTML="<span style='color:#e9e9e9;font-size:11px'>Carregando...</span>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('busca').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=1");
}

//-------------------------------------------Escolha o seu detino
function buscaResultado(termo)
{
	window.open('./ajax/buscaResultado.asp?termo='+termo,'','width=500,height=500,scrollbars=1');
}

//-------------------------------------------Posiciona a janela no canto superior esquerdo
function posiciona()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}



//-------------------------------------------PopUp
function popUp(pagina,opcoes)
{
	if (opcoes="full")
	{
		medidas = "width="+screen.width+",height="+screen.height+",scrollbars=1";
		window.open(pagina,"",medidas);
	}
	else
	{
		window.open(pagina,'',opcoes);
	}
}


//-----------------------------------------Cadastra email no newsletter
function newsLetter(email)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./ajax/newsletter.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById("emailTextBox").value="Cadastrando e-mail";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById("emailTextBox").value = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("email=" + email);
}


//----------------------------------------Valida Email
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("E-mail inválido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("E-mail inválido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("E-mail inválido!")
		    return false
		 }
		 newsLetter(str);
		 return true
	}

function validaEmail(emailID){
		
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Por favor entre com o seu e-mail.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	newsLetter(emailID.value);
	return true
 }


function seuEmail(elemento)
{
	if (elemento.value=="")
	{
		elemento.value = "Seu email";
	}
}


//-----------------------------------------Carrega os destinos cadastrados no mapa interativo
function carregaDestinos(Nome)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./mapa/mapa.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('destinos').innerHTML="<img src='./img/ajax3.gif' alt='Carregando destinos' width='150'>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('destinos').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=" + Nome);
}

//-----------------------------------------Carrega mapa interativo
function carregaMapa(latitude,longitude,lugar)
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./mapa/mapaCompleto.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('mapa').innerHTML="<img src='./img/ajax3.gif' alt='Carregando mapa' width='150'>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('mapa').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("id=" + latitude);
}

//-----------------------------------------Busca Ajax div do index.htm
function buscaResultadoAjax(termo)
{
if (termo.length<3)
{
	alert("Sua consulta deve ter no mínimo 3 digitos");
}
else
{
	var oHTTPRequest = createXMLHTTP(); 
    oHTTPRequest.open("post", "./Ajax/buscaResultado.asp", true);
    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    document.getElementById('resultadobusca').innerHTML="<img src='./img/ajax3.gif' alt='Carregando mapa' width='150'>";
    oHTTPRequest.onreadystatechange=function()
	{
		if (oHTTPRequest.readyState==4)
		{
			document.getElementById('resultadobusca').innerHTML = oHTTPRequest.responseText;
        }
    }
    oHTTPRequest.send("termo=" + termo);
	
	//verifica o tamanho da tela

	  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//	document.getElementById('escurece').style.height = (myWidth*1.17) + "px";
	document.getElementById('escurece').style.display = "";
	document.getElementById('resultadobusca').style.display = "";
}
}

function bloqueaScroll()
{
var zxcMaxYScroll=500;

function zxcStopScroll(){
if (document.all){ zxcWS=document.body.scrollTop; }
else { zxcWS=window.pageYOffset; }
if (zxcWS>zxcMaxYScroll){ window.scroll(0,zxcMaxYScroll); }
}


window.onscroll=zxcStopScroll
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

//---------------------------------------- efeito fading out by Ricardo
	function fading(div)
	{
		var filtro = document.getElementById(div).style.filter;
		var opacidade = document.getElementById(div).style.opacity;
		opacidade = parseFloat(opacidade).toFixed(2)

			if (opacidade >= 0.10)
			{
				filtro = filtro.substr(14,2);
				filtro = filtro-5;
				filtro = "alpha(opacity=" + filtro + ")";
				document.getElementById(div).style.opacity = opacidade - 0.05;
				document.getElementById(div).style.filter = filtro;
				setTimeout("timer('"+div+"')",1);
			}
			else
			{
				document.getElementById('caixa').style.display = "none";
				document.getElementById(div).style.opacity = "0.99";
				document.getElementById(div).style.filter = "alpha(opacity=99)";
			}
	}
	function timer(div)
	{
		fading(div);
	}

//-----------------------------------------carrega subcategorias na página de cotação
function subcategoria(id)
{
	document.getElementById('nomeDestino').value = "";
	if (id=="americasul")
	{
		document.getElementById('subcategoria').innerHTML="";
		var oHTTPRequest = createXMLHTTP(); 
	    oHTTPRequest.open("post", "./ajax/subcategoria.asp", true);
	    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    document.getElementById('subcategoria').innerHTML="<select style='width:200px'><option>Carregando</option></select>";
	    oHTTPRequest.onreadystatechange=function()
		{
			if (oHTTPRequest.readyState==4)
			{
				document.getElementById('subcategoria').innerHTML = oHTTPRequest.responseText;
	        }
	    }
	    oHTTPRequest.send("id=" + id + "&lugar=americasul");
	}
	else
	{
		document.getElementById('nomeDestino').value = "";
		document.getElementById('subcategoria').innerHTML="";
		var oHTTPRequest = createXMLHTTP(); 
	    oHTTPRequest.open("post", "./ajax/subcategoria.asp", true);
	    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    document.getElementById('subcategoria').innerHTML="<select style='width:200px'><option>Carregando</option></select>";
	    oHTTPRequest.onreadystatechange=function()
		{
			if (oHTTPRequest.readyState==4)
			{
				document.getElementById('subcategoria').innerHTML = oHTTPRequest.responseText;
	        }
	    }
	    oHTTPRequest.send("id=" + id);
	}
}
