try{
   xmlhttp = new XMLHttpRequest();
}
catch(ee){
   
   try{
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
       
       try{
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch(E){
          xmlhttp = false;
       }
       
       
    }
    
    
}


// URLs Simples
function processar(url,div){
   
   var conteudo=document.getElementById(div);
   
   if(!xmlhttp) { 
      conteudo.innerHTML = '<center><font face="verdana" size="2">Processo indisponível no momento!</font></center><br>';
      return;
   }
   else{
      conteudo.innerHTML = '<center><table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#F7F7F7" id="table1" style="border-collapse: collapse">';
      conteudo.innerHTML += '<tr><td width="100%" height="100%"><center class="style1"><img border="0" src="imgs/loader.gif"></center>';
      conteudo.innerHTML += '<center><font size="2" class="fonteload">Carregando...</font></center></td></tr></table></center>';
   }
   
   
   xmlhttp.open("GET", url,true);
   xmlhttp.onreadystatechange=function() {
      
      if(xmlhttp.readyState == 4){
         
         if(xmlhttp.status == 200){
            
            //Exibe o texto no div conteúdo
            conteudo.innerHTML = xmlhttp.responseText;
            
         }
         
         if(xmlhttp.status == 404){
            conteudo.innerHTML = '<center><font face="verdana" size="2">Página não encontrada!</font></center><br>';
         }
         
         if(xmlhttp.status == 500){
            conteudo.innerHTML = '<center><font face="verdana" size="2">Falha de execução: 500</font></center><br>';
         }
         
      }
      
   }
   xmlhttp.send(null);
   
   
}


// Com Formulario
function enviarForm(url,campos,destino) {
   
   var elemento = document.getElementById(destino);
   
   if(!xmlhttp) { 
      elemento.innerHTML = '<center><font face="verdana" size="2">Processo indisponível no momento!</font></center><br>';
      return;
   }
   else{
      elemento.innerHTML = '<center><table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#F7F7F7" id="table1" style="border-collapse: collapse">';
      elemento.innerHTML += '<tr><td width="100%" height="100%"><center class="style1"><img border="0" src="imgs/loader.gif"></center>';
      elemento.innerHTML += '<center><font size="2" class="fonteload">Carregando...</font></center></td></tr></table></center>';
   }
   
   
   xmlhttp.open("GET", url+'?'+campos,true);
   xmlhttp.onreadystatechange=function() {
      
      if(xmlhttp.readyState == 4){
         
         if(xmlhttp.status == 200){
            elemento.innerHTML = xmlhttp.responseText;
         }
         
         if(xmlhttp.status == 404){
            elemento.innerHTML = '<center><font face="verdana" size="2">Página não encontrada!</font></center><br>';
         }
         
         if(xmlhttp.status == 500){
            elemento.innerHTML = '<center><font face="verdana" size="2">Falha de execução: 500</font></center><br>';
         }
         
      }
      
   }
   xmlhttp.send(null);
   
}



function setarCampos() {
   campos = "consultar=&pagina=0&de="+ encodeURI(document.getElementById('de').value) +
   "&ate="+ encodeURI(document.getElementById('ate').value) +
   "&cidade="+ encodeURI(document.getElementById('cidade').value) +
   "&ordem="+ encodeURI(document.getElementById('ordem').value);
}



function fcadastrar() {
   campos = "nome="+ encodeURI(document.getElementById('nome').value) + 
   "&email="+ encodeURI(document.getElementById('email').value) +
   "&senha="+ encodeURI(document.getElementById('senha').value) +
   "&ddd="+ encodeURI(document.getElementById('ddd').value) +
   "&tel="+ encodeURI(document.getElementById('tel').value) +
   "&nasc="+ encodeURI(document.getElementById('nasc').value) +
   "&enderec="+ encodeURI(document.getElementById('enderec').value) +
   "&compl="+ encodeURI(document.getElementById('compl').value) +
   "&pais="+ encodeURI(document.getElementById('pais').value) +
   "&estado="+ encodeURI(document.getElementById('estado').value) +
   "&cidade="+ encodeURI(document.getElementById('cidade').value) +
   "&acao="+ encodeURI(document.getElementById('acao').value);
   
}



function flogarse() {
   campos = "acao=logar"+
   "&usuario="+ encodeURI(document.getElementById('email').value) +
   "&senha="+ encodeURI(document.getElementById('senha').value);
}



function reservar() {
   campos = "&acao="+ encodeURI(document.getElementById('acao').value) +
   "&idh="+ encodeURI(document.getElementById('idh').value) +
   "&nmhotel="+ encodeURI(document.getElementById('nmhotel').value) +
   "&tarifa="+ encodeURI(document.getElementById('tarifa').value) +
   "&de="+ encodeURI(document.getElementById('de').value) +
   "&ate="+ encodeURI(document.getElementById('ate').value) +
   "&rooms="+ encodeURI(document.getElementById('rooms').value) +
   "&adts="+ encodeURI(document.getElementById('adts').value) +
   "&chds="+ encodeURI(document.getElementById('chds').value) +
   "&obs="+ encodeURI(document.getElementById('obs').value) +
   "&hospedes="+ encodeURI(document.getElementById('hospedes').value);
}


///////////////////////////////////////////////////////////////////////////
//  FUNÇÔES GOOGLE MAPS
///////////////////////////////////////////////////////////////////////////

var map = null;
var geocoder = null;

function initialize() {
   
   if (GBrowserIsCompatible()) {
      
      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(37.4419, -122.1419), 16);
      geocoder = new GClientGeocoder();

      GEvent.addListener(map,"click", function(overlay,latlng) {
         // var myHtml = "The GLatLng value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom();
         map.openInfoWindow(latlng, myHtml);
      });

      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
   
   }
   
}



function showAddress(address) {
   
   if (geocoder) {
      
      geocoder.getLatLng(
         address,
         function(point) {
            
            if (!point) { alert(address + " not found"); }
            else {
               map.setCenter(point, 16);
               var marker = new GMarker(point);
               map.addOverlay(marker);
               marker.openInfoWindowHtml(address);
            }
            
         }
         
      );
      
   }
   
}




///////////////////////////////////////////////////////////////////////////
// OUTRAS FUNÇÕES
///////////////////////////////////////////////////////////////////////////

function linkhotel(id){
   document.getElementById('div_mapa').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:abrir(\'?consultar=' +id+ '&width=400&height=350&tipomapa=regiao\');">[ + ] Ampliar Mapa</a>';
}



function nomecidade(id){
   document.getElementById('cidade').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:abrir(\'?consultar=' +id+ '&width=400&height=350&tipomapa=regiao\');">[ + ] Ampliar Mapa</a>';
}



function abrir(URL) {
   
   var width = 400;
   var height = 350;
   
   var left = 200;
   var top = 200;
   
   window.open(URL,'googlemap', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
   
}



function chegar(URL) {
   
   var width = 780;
   var height = 450;
   
   var left = 50;
   var top = 50;
   
   window.open(URL,'comochegar', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
   
}



function detalhes(URL) {
   
   var width = 505;
   var height = 450;
   
   var left = 50;
   var top = 50;
   
   window.open(URL,'comochegar', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
   
}



function mostrardiv(nmdiv){
   document.getElementById(nmdiv).style.visibility='visible';
}



function ocultardiv(nmdiv){
   document.getElementById(nmdiv).style.visibility='hidden';
}



function iframe(url,div,width,height){
   
   var conteudo=document.getElementById(div);
   conteudo.innerHTML = '<iframe width="'+ width +'" height="'+ height +'" src="'+ url +'" scrolling="no" border="0" frameborder="0"></iframe>';
   
}


// Verifica se os campos foram preenchidos na busca do HOTEL  
function validabusca(){
   
   if(document.getElementById('cidade').value == "" || document.getElementById('cidade').value == "-1"){
      alert("Selecione uma cidade!\nSelect the city!");
      document.getElementById('cidade').focus();
      fok = 0;   return false;
   }
   
   if(document.getElementById('de').value == ""){
      alert("Informe a data do Check-IN!\nType the Check-IN date!");
      document.getElementById('de').focus();
      fok = 0;   return false;
   }
   
   if(document.getElementById('ate').value == ""){
      alert("Informe a data do Check-OUT!\nType the Check-OUT date!");
      document.getElementById('ate').focus();
      fok = 0;   return false;
   }
   
   if(document.getElementById('de').value == document.getElementById('ate').value){
      alert("Check-IN & Check-OUT Nao podem ser iguais!\nCheck-IN & Check-OUT can't be the same date!");
      document.getElementById('ate').focus();
      fok = 0;   return false;
   }
   
   fok = 1;
   
   //return true;
   
}


// Formata o campo de data
function barra(objeto){
   if(objeto.value.length == 2 || objeto.value.length == 5 ){ objeto.value = objeto.value+"/"; }
}


// NAO USANDO / NAO FUNCIONANDO
function exibefoto(div,url){
   
   document.getElementById(div).innerHTML = '<img src="'+ url +'" border="0" width="120" height="105">';
   
}

