//------------------------------------
//FUNÇÃO MUDA VALOR
//------------------------------------

function mudaValor(plano) 
{
	switch(plano)
	{

		case '00000000000' :
			var adesao = document.getElementById('grupoLimpaAdesao').value.replace(",",".");
			var mensal = document.getElementById('grupoLimpaValor').value.replace(",",".");
			var numero = document.getElementById('titulo_numero').value.replace(",",".");
		
		        document.getElementById('valor_adesao_unitario').innerHTML = 'R$ ' + adesao +',00';
		        document.getElementById('valor_adesao_total').innerHTML = 'R$ ' + adesao*numero +',00';
			document.getElementById('valor_mensalidade_unitario').innerHTML = 'R$ '+ mensal +',00';
			document.getElementById('valor_mensalidade_total').innerHTML = 'R$ '+ mensal*numero +',00';
		break;
		case '00000000001' :
			var adesao = document.getElementById('grupoFacilAdesao').value.replace(",",".");
			var mensal = document.getElementById('grupoFacilValor').value.replace(",",".");
			var numero = document.getElementById('titulo_numero').value.replace(",",".");
		
		        document.getElementById('valor_adesao_unitario').innerHTML = 'R$ ' + adesao +',00';
		        document.getElementById('valor_adesao_total').innerHTML = 'R$ ' + adesao*numero +',00';
			document.getElementById('valor_mensalidade_unitario').innerHTML = 'R$ '+ mensal +',00';
			document.getElementById('valor_mensalidade_total').innerHTML = 'R$ '+ mensal*numero +',00';
		break;
		case '00000000002' :
			var adesao = document.getElementById('grupoMaisAdesao').value.replace(",",".");
			var mensal = document.getElementById('grupoMaisValor').value.replace(",",".");
			var numero = document.getElementById('titulo_numero').value.replace(",",".");
		
		        document.getElementById('valor_adesao_unitario').innerHTML = 'R$ ' + adesao +',00';
		        document.getElementById('valor_adesao_total').innerHTML = 'R$ ' + adesao*numero +',00';
			document.getElementById('valor_mensalidade_unitario').innerHTML = 'R$ '+ mensal +',00';
			document.getElementById('valor_mensalidade_total').innerHTML = 'R$ '+ mensal*numero +',00';
		break;
		case '00000000003' :
			var adesao = document.getElementById('grupoMegaAdesao').value.replace(",",".");
			var mensal = document.getElementById('grupoMegaValor').value.replace(",",".");
			var numero = document.getElementById('titulo_numero').value.replace(",",".");
		
		        document.getElementById('valor_adesao_unitario').innerHTML = 'R$ ' + adesao +',00';
		        document.getElementById('valor_adesao_total').innerHTML = 'R$ ' + adesao*numero +',00';
			document.getElementById('valor_mensalidade_unitario').innerHTML = 'R$ '+ mensal +',00';
			document.getElementById('valor_mensalidade_total').innerHTML = 'R$ '+ mensal*numero +',00';
		break;
   		case '00000000004' :
		      var adesao = document.getElementById('grupoFTBAdesao').value.replace(",",".");
		      var mensal = document.getElementById('grupoFTBValor').value.replace(",",".");
		      var numero = document.getElementById('titulo_numero').value.replace(",",".");
		    
		        document.getElementById('valor_adesao_unitario').innerHTML = 'R$ ' + adesao +',00';
		        document.getElementById('valor_adesao_total').innerHTML = 'R$ ' + adesao*numero +',00';
			document.getElementById('valor_mensalidade_unitario').innerHTML = 'R$ '+ mensal +',00';
			document.getElementById('valor_mensalidade_total').innerHTML = 'R$ '+ mensal*numero +',00';
   		break;  
	}
}

//------------------------------------
//FUNÇÃO FORMATA CAMPOS
//------------------------------------

function formatar(src, mask){
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida)
  {
    src.value += texto.substring(0,1);
  }
}

//------------------------------------
//FUNÇÃO FORMATA MOEDAS
//------------------------------------

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 ValidarCPF(Objcpf){
        var cpf = Objcpf.value;
        exp = /\.|\-/g
        cpf = cpf.toString().replace( exp, "" );
        var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
        var soma1=0, soma2=0;
        var vlr =11;

        for(i=0;i<9;i++){
                soma1+=eval(cpf.charAt(i)*(vlr-1));
                soma2+=eval(cpf.charAt(i)*vlr);
                vlr--;
        }
        soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
        soma2=(((soma2+(2*soma1))*10)%11);

        var cpf = cpf.toString().replace( exp, "" );
        if(cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
                        alert('CPF Invalido!');

        var digitoGerado=(soma1*10)+soma2;
        if(digitoGerado!=digitoDigitado)
                        alert('CPF Invalido!');
}

//------------------------------------
//VALIDA BUSCA HOTEIS
//------------------------------------

	function validarBusca(form){

	var analise;
	analise=false;
	var tipo = 0;
	var mensagem = "Você deve preencher todos o(s) campo(s): \n";

	if (document.buscahoteis.cidade.value=="")
	{
	  tipo++;
	  mensagem = mensagem + "\n";
	  analise=true
	}
	if (document.buscahoteis.grupo.value=="")
	{
	  tipo++;
	  mensagem = mensagem + "\n";
	  analise=true
	}
	if (document.buscahoteis.periodo.value=="")
	{
	  tipo++;
	  mensagem = mensagem + "\n";
	  analise=true
	}
	if (tipo != 0)
	{
	  alert(mensagem);
	   
	}
	if (tipo == 0)
	{
		frm = document.buscahoteis;
		frm.submit();
	}  
}

//------------------------------------
//MUDA ESTADO
//------------------------------------

	function trocaEstado(value){
	document.getElementById('estadohotel').setAttribute( 'action', '/hoteisconveniados-'+value+'' );
}
