// Menu Viagens

$(document).ready(function() {
    
	var cookie = $.cookie("tab"); 
	
	if ( typeof cookie !== "undefined" && cookie) {
		var position = cookie;
	} 
	
	else
	{
		var position = 0;
	}

	//Default Action
	$(".menuviagenscontent").hide(); //Hide all content
	$("div.menuviagens ul li:eq(" + position + ")").addClass("active").show(); //Activate first tab
	$(".menuviagenscontent:eq(" + position + ")").show(); //Show first tab content
	
	//On Click Event
	$("div.menuviagens ul li").click(function() {
		$("div.menuviagens ul li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".menuviagenscontent").hide(); //Hide all tab content
		var activeTab = $(this).find("span").attr("id"); //Find the rel attribute value to identify the active tab + content
		var currentIndex = $(this).parent().prevAll().length;
		$(activeTab).fadeIn(); //Fade in the active content
		$.cookie("tab",currentIndex);
		return false;
	});

});


// Menu Listar Viagens

$(document).ready(function() {

	//Default Action
	$(".viagenscontent").hide(); //Hide all content
	$("div.menuviagensitem ul li:first").addClass("active").show(); //Activate first tab
	$(".viagenscontent:first").show(); //Show first tab content
	
	//On Click Event
	$("div.menuviagensitem ul li").click(function() {
		$("div.menuviagensitem ul li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".viagenscontent").hide(); //Hide all tab content
		var activeTab = $(this).find("span").attr("id"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// Menu Cursos

$(document).ready(function() {

	//Default Action
	$(".menucursoscontent").hide(); //Hide all content
	$("div.menucursos ul li:first").addClass("active").show(); //Activate first tab
	$(".menucursoscontent:first").show(); //Show first tab content
	
	//On Click Event
	$("div.menucursos ul li").click(function() {
		$("div.menucursos ul li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".menucursoscontent").hide(); //Hide all tab content
		var activeTab = $(this).find("span").attr("id"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// Menu Listar Cursos

$(document).ready(function() {

	//Default Action
	$(".cursoscontent").hide(); //Hide all content
	$("div.menucursositem ul li:first").addClass("active").show(); //Activate first tab
	$(".cursoscontent:first").show(); //Show first tab content
	
	//On Click Event
	$("div.menucursositem ul li").click(function() {
		$("div.menucursositem ul li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".cursoscontent").hide(); //Hide all tab content
		var activeTab = $(this).find("span").attr("id"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// Menu Listar Eventos

$(document).ready(function() {

	//Default Action
	$(".eventoscontent").hide(); //Hide all content
	$("div.menueventositem ul li:first").addClass("active").show(); //Activate first tab
	$(".eventoscontent:first").show(); //Show first tab content
	
	//On Click Event
	$("div.menueventositem ul li").click(function() {
		$("div.menueventositem ul li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".eventoscontent").hide(); //Hide all tab content
		var activeTab = $(this).find("span").attr("id"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// Banner Home




 function validaCupom()
               {
                  var vCodCupom = createXMLHTTP();
                     
                  var objeto = document.getElementById('validaCupom');
                  
                  vCodCupom.open('post', '/modulos/ajax/cupom_ajax.asp', true);
                  
                  vCodCupom.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                  
                  vCodCupom.onreadystatechange=function(){
                     
                     if (vCodCupom.readyState==4){
                        
                        objeto.innerHTML = vCodCupom.responseText;
                        
                     }
                     
                  }
                  
                  vCodCupom.send('cupomCodigo=' + document.frmReserva.cupomCodigo.value + '&eventoId=<% = eventoId %>&idiomaId=<% = eventoIdiomaId %>');
               }
               
               function mostraAcompanhantes(quantidade)
               {
                  ultimo = 6;
                  for (i = 1; i <= ultimo; i ++)
                  {
                     if (i <= quantidade)
                     {
                        document.getElementById("divAcompanhante" + i).style.display="inline";
                     }
                     else
                     {
                        document.getElementById("divAcompanhante" + i).style.display="none";
                        document.getElementById("agendaReservaAcompNome" + i).value="";
                        document.getElementById("acompanhanteDataNascimento" + i).value="";
                     }
                  }
               }
			   
               function desabilitaAcompanhantes(pacotes, qnt)
               {
				   for(i = 1; i <= pacotes; i++)
				   {
					   if(i == qnt)
					   {
						   document.getElementById("quantidade" + i).disabled=false;
						   document.getElementById("quantidade" + i).style.display="inline";
					   }
					   
					   else
					   {
						   document.getElementById("quantidade" + i).disabled=true;
						   document.getElementById("quantidade" + i).style.display="none";
					   }
				   }
               }
			   
			   function getRadioValue(radioObj)
			   {
				   var radio = document.getElementsByName(radioObj);
				   
				   for(i = 0; i < radio.length; i++)
				   {
					   if(radio[i].checked == true) 
					   {
						   return radio[i].value;
					   }
				   }
			   }
			   
			   function pegaValor(selObj)
			   {
				   var x = selObj.selectedIndex;
				   var show = mostraAcompanhantes(selObj.options[x].value);
				   document.frmReserva.agendaReservaPessoas.value = selObj.options[x].value;
				   var num = parseInt(selObj.options[x].value) + 1;
				   var valor = getRadioValue('pacoteId');
				   var test = float2moeda(num * parseFloat(valor.replace('.','')));
				   document.getElementById('total').innerHTML = 'Total: R$ ' + test;
				   document.frmReserva.pacoteTotal.value = test;
			   }
			   
			   function setValue(radioObj)
			   {
				   var valor = radioObj.value;
				   document.getElementById('total').innerHTML = 'Total: R$ ' + valor;
				   document.frmReserva.pacoteTotal.value = valor;
			   }
               
			   function validaCupom()
               {
                  var vCodCupom = createXMLHTTP();
                     
                  var objeto = document.getElementById('validaCupom');
                  
                  vCodCupom.open('post', '/modulos/ajax/cupom_ajax.asp', true);
                  
                  vCodCupom.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                  
                  vCodCupom.onreadystatechange=function(){
                     
                     if (vCodCupom.readyState==4){
                        
                        objeto.innerHTML = vCodCupom.responseText;
                        
                     }
                     
                  }
                  
                  vCodCupom.send('cupomCodigo=' + document.frmReserva.cupomCodigo.value + '&eventoId=<% = eventoId %>&idiomaId=<% = eventoIdiomaId %>');
               }
			   
			   
               function validaForm() {
                  var ok        = true;
                  var erro      = ""
                  var qerro     = 0;
                  var mensagem  = ""
                  var passou    = false;
                  
                  if (document.frmReserva.agendaReservaNome.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo NOME deve ser preenchido.\n");
                     document.frmReserva.agendaReservaNome.focus();
                     ok = false;
                  } 
                  
                  if (document.frmReserva.agendaReservaDataNascimento.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo DATA DE NASCIMENTO deve ser preenchido.\n");
                     document.frmReserva.agendaReservaDataNascimento.focus();
                     ok = false;
                  }
                 
                  if (document.frmReserva.agendaReservaEmail.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo Email deve ser preenchido.\n");
                     ok = false;
                  } else {
                     if (valida_EMAIL(document.frmReserva.agendaReservaEmail.value) == false){
                        qerro = qerro + 1
                        mensagem += (qerro + ". E-mail Inválido.\n");
                        ok = false;
                     }
                  }
                  
                  if (document.frmReserva.agendaReservaTelefoneDDD.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo DDD deve ser preenchido.\n");
                     document.frmReserva.agendaReservaTelefoneDDD.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaTelefone.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo TELEFONE deve ser preenchido.\n");
                     document.frmReserva.agendaReservaTelefone.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaCelularDDD.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo DDD deve ser preenchido.\n");
                     document.frmReserva.agendaReservaCelularDDD.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaCelular.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo CELULAR deve ser preenchido.\n");
                     document.frmReserva.agendaReservaCelular.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaEndereco.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo ENDEREÇO deve ser preenchido.\n");
                     document.frmReserva.agendaReservaEndereco.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaCep.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo CEP deve ser preenchido.\n");
                     document.frmReserva.agendaReservaCep.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaNumero.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo NÚMERO deve ser preenchido.\n");
                     document.frmReserva.agendaReservaNumero.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaEstado.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo ESTADO deve ser preenchido.\n");
                     document.frmReserva.agendaReservaEstado.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaCidade.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo CIDADE deve ser preenchido.\n");
                     document.frmReserva.agendaReservaCidade.focus();
                     ok = false;
                  }
                  
                  if (document.frmReserva.agendaReservaBairro.value == "") {
                     qerro = qerro + 1
                     mensagem += (qerro + ". O Campo BAIRRO deve ser preenchido.\n");
                     document.frmReserva.agendaReservaBairro.focus();
                     ok = false;
                  }
                  
                  
                           if (document.frmReserva.pacoteId.value == undefined) 
                           {
                              for (i=0; i < document.frmReserva.pacoteId.length; i++){
                                 if (document.frmReserva.pacoteId[i].checked == true){
                                    passou = true
                                 }
                              }
                           } 
                           else
                           {
                              if (document.frmReserva.pacoteId.checked == true){
                                 passou = true
                              }
                           }
                           
                           if (!passou){
                              qerro = qerro + 1
                              mensagem += (qerro + ". Selecione um PACOTE.\n");
                              ok = false;
                           }
                        
				  
                 
                  if (ok == false) {
                     if (qerro > 1) {
                        alert("Atenção: Ocorreram " + qerro + " erros\n------------------------------------------------------------------------------------------------------------------------\n" + mensagem + "------------------------------------------------------------------------------------------------------------------------\nClique OK e tente novamente.");
                     } else {
                        alert("Atenção: Ocorreu " + qerro + " erro\n------------------------------------------------------------------------------------------------------------------------\n" + mensagem + "------------------------------------------------------------------------------------------------------------------------\nClique OK e tente novamente.");
                     }
                     return false;
                     
                  } else if (ok == true) {
                     
                     return true;
                  }
               }	  
				  
function Data(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00/00/0000 00:00:00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '/';
	separacao2 = ' ';
	separacao3 = ':';
	conjunto1 = 2;
	conjunto2 = 5;
	conjunto3 = 10;
	conjunto4 = 13;
	conjunto5 = 16;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (10))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao2;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao3;
		else if (campo.value.length == conjunto5)
		campo.value = campo.value + separacao3;
	}
	else
		event.returnValue = false;
}

function Hora(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00:00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = ':';
	conjunto1 = 2;
	conjunto2 = 5;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (5))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;

	}
	else
		event.returnValue = false;
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

  function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }



    function Telefone(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
        v=v.replace(/(\d{4})(\d)/,"$1-$2")    
        return v
    }

   // Função para validar e-mail
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 24 de abril de 2003 - 19h40

   function valida_EMAIL(campo) {
      var goodEmail = campo.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
      if (goodEmail) {
         return true;
      } else {
         return false;
      }
   }


   // Função para entrar somente números num campo do formulário
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 24 de abril de 2003 - 17h20

   function filtro_SoNumeros() {
      if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;
   }


   // Função para mascarar Telefone 9999-9999
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 25 de abril de 2003 - 11h40

   function mascara_FONEFAX(Campo, teclapres){
   
   	var tecla = teclapres.keyCode;
   
   	var vr = new String(Campo.value);
   	vr = vr.replace(".", "");
   	vr = vr.replace(".", "");
   	vr = vr.replace("/", "");
   	vr = vr.replace("-", "");
   
   	tam = vr.length + 1 ;
   
      if (tam > 4)
         Campo.value = vr.substr(0, 4) + '-' + vr.substr(4, tam);
   }


   // Função para mascarar CEP 99999-999
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 21 de maio de 2004 - 13h04

   function mascara_CEP(Campo, teclapres){
   
   	var tecla = teclapres.keyCode;
   
   	var vr = new String(Campo.value);
   	vr = vr.replace(".", "");
   	vr = vr.replace(".", "");
   	vr = vr.replace("/", "");
   	vr = vr.replace("-", "");
   
   	tam = vr.length + 1 ;
   
      if (tam > 5)
         Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, tam);
   }


   // Função para mascarar DATA DD/MM/AAAA
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 24 de abril de 2003 - 17h20

   function mascara_DATA(Campo, teclapres){
   	var tecla = teclapres.keyCode;
   	
   	var vr = new String(Campo.value);
   	vr = vr.replace(".", "");
   	vr = vr.replace("/", "");
   	vr = vr.replace("-", "");
   
   	tam = vr.length + 1;
   	
   	if (tecla != 9 && tecla != 8){
   		if (tam > 2 && tam < 4)
   			Campo.value = vr.substr(0, 2) + '/' + vr.substr(3, tam);
   		if (tam > 4 && tam < 11)
   			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(5,tam-4);
   		}
   }


   // Função para mascarar CNPJ
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 24 de abril de 2003 - 17h20

   function mascara_CNPJ(Campo, teclapres){
   
   	var tecla = teclapres.keyCode;
   
   	var vr = new String(Campo.value);
   	vr = vr.replace(".", "");
   	vr = vr.replace(".", "");
   	vr = vr.replace("/", "");
   	vr = vr.replace("-", "");
   
   	tam = vr.length + 1 ;
   
   	if (tecla != 9 && tecla != 8){
   		if (tam > 2 && tam < 6)
   			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
   		if (tam >= 6 && tam < 9)
   			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
   		if (tam >= 9 && tam < 13)
   			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
   		if (tam >= 13 && tam < 15)
   			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
   		}
   }

   // Função para mascarar CPF
   // Criado por: Eduardo Y. Palomba (eduardo@linkecerebro.com.br)
   // Criado em : 24 de abril de 2003 - 17h20

   function mascara_CPF(Campo, teclapres){
   	var tecla = teclapres.keyCode;
   	
   	var vr = new String(Campo.value);
   	vr = vr.replace(".", "");
   	vr = vr.replace(".", "");
   	vr = vr.replace("-", "");
   
   	tam = vr.length + 1;
   	
   	if (tecla != 9 && tecla != 8){
   		if (tam > 3 && tam < 7)
   			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
   		if (tam >= 7 && tam <10)
   			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
   		if (tam >= 10 && tam < 12)
   			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
   		}
   }





function Mascara(tipo, campo, teclaPress) {
        if (window.event)
        {
                var tecla = teclaPress.keyCode;
        } else {
                tecla = teclaPress.which;
        }
 
        var s = new String(campo.value);
        // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
        s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
        tam = s.length + 1;
 
        if ( tecla != 9 && tecla != 8 ) {
                switch (tipo)
                {
                case 'CPF' :
                        if (tam > 3 && tam < 7)
                                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
                        if (tam >= 7 && tam < 10)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
                        if (tam >= 10 && tam < 12)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
                break;
 
                case 'CNPJ' :
 
                        if (tam > 2 && tam < 6)
                                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
                        if (tam >= 6 && tam < 9)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
                        if (tam >= 9 && tam < 13)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
                        if (tam >= 13 && tam < 15)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
                break;
 
                case 'TEL' :
                        if (tam > 2 && tam < 4)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
                        if (tam >= 7 && tam < 11)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
                break;
 
                case 'DATA' :
                        if (tam > 2 && tam < 4)
                                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
                        if (tam > 4 && tam < 11)
                                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
                break;
                
                case 'CEP' :
                        if (tam > 5 && tam < 7)
                                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
                break;
                }
        }
}



/*
Descrição.: formata um campo do formulário de
acordo com a máscara informada...
Parâmetros: - objForm (o Objeto Form)
- strField (string contendo o nome do textbox)
 
* - sMask (mascara que define o
* formato que o dado será apresentado,
* usando o algarismo "9" para
* definir números e o símbolo "!" para
* qualquer caracter...
* - evtKeyPress (evento)
* Uso.......: <input type="textbox"
* name="xxx".....
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observação: As máscaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por aí vai...
***/
 
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
 
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
 
if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}
 
sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;
 
i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;
 
while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
 
if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
} else {
    sCod += sValue.charAt(nCount);
    nCount++;
}
i++;
}
 
objForm[strField].value = sCod;
if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
    return true;
}
} else {
    return true;
}
}


	function validaF(){
		//validar nome
		d = document.reservaAereo;
		if (d.nomeReserva.value == ""){
			alert("O campo Nome deve ser preenchido!");
			d.nomeReserva.focus();
			return false;
		}

		//validar email
		if (d.emailReserva.value == ""){
			alert("O campo E-mail deve ser preenchido!");
			d.emailReserva.focus();
			return false;
		}
		//validar telefone
		if (d.telReserva.value == ""){
			alert("O campo Telefone deve ser preenchido!");
			d.telReserva.focus();
			return false;
		}
		if (d.trechodesReserva.value == ""){
			alert("O campo Trecho aéreo desejado deve ser preenchido!");
			d.trechodesReserva.focus();
			return false;
		}
		if (d.idaDia.value == ""){
			alert("O campo ida dia deve ser preenchido!");
			d.idaDia.focus();
			return false;
		}
		if (d.idaHora.value == ""){
			alert("O campo ida hora deve ser preenchido!");
			d.idaHora.focus();
			return false;
		}
		
		alert('Heitah');
		return true;
	}
	
function float2moeda(num) {

x = 0;

if(num<0) {
num = Math.abs(num);
x = 1;
} if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);

num = Math.floor((num*100+0.5)/100).toString();

if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'
+num.substring(num.length-(4*i+3)); ret = num + ',' + cents; if (x == 1) ret = ' - ' + ret;
return ret;
}

function abreFichaInscricao(URL)
{
	window.open(URL,'ficha','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=700'); 
}

var navegador = navigator.userAgent.toLowerCase(); //Cria e atribui à variável global 'navegador' (em caracteres minúsculos) o nome e a versão do navegador

//Cria uma variável global chamada 'xmlhttp'
var xmlhttp; 



//Função que inicia o objeto XMLHttpRequest

function objetoXML() {

	if (navegador.indexOf('msie') != -1) { //Internet Explorer

		var controle = (navegador.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; //Operador ternário que adiciona o objeto padrão do seu navegador (caso for o IE) à variável 'controle'

		try {

			xmlhttp = new ActiveXObject(controle); //Inicia o objeto no IE

		} catch (e) { }

	} else { //Firefox, Safari, Mozilla

		xmlhttp = new XMLHttpRequest(); //Inicia o objeto no Firefox, Safari, Mozilla

	}

}

//Função que envia o formulário

function enviarForm(url, campos, destino) {

	//Atribui à variável 'elemento' o elemento que irá receber a página postada
	var elemento = document.getElementById(destino); 

	//Executa a função objetoXML()
	objetoXML(); 

	//Se o objeto de 'xmlhttp' não estiver true
	if (!xmlhttp) {

		//Insere no 'elemento' o texto atribuído
		elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.'; 

		return;

	} else { 

		//Insere no 'elemento' o texto atribuído
		elemento.innerHTML = 'Carregando...'; 

	}

	xmlhttp.onreadystatechange = function () {

		//Se a requisição estiver completada
		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { 

			//Se o status da requisição estiver OK
			if (xmlhttp.status == 200) {

				//Insere no 'elemento' a página postada
				elemento.innerHTML = xmlhttp.responseText; 

			} else { 

				//Insere no 'elemento' o texto atribuído
				elemento.innerHMTL = 'Página não encontrada!'; 

			}

		}

	}

	//Abre a página que receberá os campos do formulário
	xmlhttp.open('POST', url+'?'+campos, true);

	//Envia o formulário com dados da variável 'campos' (passado por parâmetro)
	xmlhttp.send(campos); 

}
	

