// JavaScript Document

Ficha = {
	objform: null,
	veiculotipo: null,
	txtlabelspj: Array('Razão social', 'CNPJ', 'Data fundação', 'Faturam. mensal'),
	txtlabelspf: Array('Nome completo', 'CPF', 'Data admissão', 'Renda mensal'),
	__max: {},

	setMax: function (dsaCod, max) {
		// seta o valor para cada tipo de destaque
		this.__max[dsaCod] = max;
	},

	getMax: function (dsaCod) {
		return this.__max[dsaCod];
	},

	setObjForm: function ( id ) {
		this.objform = document.getElementById(id);
	},

	setVeiculoTipo: function ( val ) {
		this.veiculotipo = val;
	},

	getObjForm: function ( ) {
		return this.objform;
	},
	
	MontaLabelValor: function ( id ) {
		dsc = this.objform.veiculofincodigo.options[this.objform.veiculofincodigo.selectedIndex].text;
		dscvalor = dsc.substring( dsc.indexOf('R$') );
		document.getElementById('valorveiculo').innerHTML = dscvalor;
	},
	
	
	ExibeOcultaCampos: function ( tppes )
	{
		frm = this.objform;
		document.getElementById('tituloseusdados').innerHTML = 'Seus dados';
		document.getElementById('campoiestadual').style.display = 'block';
		document.getElementById('campotelcontador').style.display = 'block';
		document.getElementById('dadosproponentepfisica').style.display = 'block';
		document.getElementById('empresasanterior').style.display = 'block';
		document.getElementById('cartoescredito').style.display = 'block';
		document.getElementById('campocomempresa').style.display = 'block';
		document.getElementById('campocomcnpj').style.display = 'block';
		document.getElementById('tituloinfoprofissionais').style.display = 'block';
		frm.referencia.style.display = 'block';
		frm.inforesidencia.style.display = 'block';
		frm.dadosconjgue.style.display = 'block';
		if ( tppes == 'J' ) {
			document.getElementById('tituloseusdados').innerHTML = 'Dados da empresa';
			document.getElementById('dadosproponentepfisica').style.display = 'none';
			document.getElementById('empresasanterior').style.display = 'none';
			document.getElementById('cartoescredito').style.display = 'none';
			document.getElementById('campocomempresa').style.display = 'none';
			document.getElementById('campocomcnpj').style.display = 'none';
			document.getElementById('tituloinfoprofissionais').style.display = 'none';
			frm.referencia.style.display = 'none';
			frm.inforesidencia.style.display = 'none';
			frm.dadosconjgue.style.display = 'none';
		} else {
			document.getElementById('campoiestadual').style.display = 'none';
			document.getElementById('campotelcontador').style.display = 'none';
		}
		// trata labels especiais
		idlabels = new Array('lblnome', 'lblcpfcnpj', 'lblcomdata', 'lblrenda');
		txtlabels = ( tppes == 'J' ) ? this.txtlabelspj : this.txtlabelspf;
		for( i=0; i<idlabels.length; i++ ) {
			document.getElementById(idlabels[i]).innerHTML = txtlabels[i];
		}
	},
	
	
	ExibeVeiculoFinanciado: function () {
		frm = this.objform;
		if ( frm.veiculofinanciadoS.checked ) {
			document.getElementById('camposveiculofinanciado').style.display = 'block';
		} else {
			document.getElementById('camposveiculofinanciado').style.display = 'none';
		}
	},


	AlimentaComboMarcaModelo: function ( id, categoria, vlrDefault, combovlrDefault2, vlrDefault2 ) {
	
		// Recupera o objeto formulario
		frm = this.objform;
	
		// Desativa os dois combos
		frm.veiculomodelo.disabled = true;
	
		// Limpa combo de modelo
		frm.veiculomodelo.options.length = 0;
		frm.veiculomodelo.options[0] = new Option( 'Selecione o modelo', '0');
	
		txtCombo2 = '';
		id2 = '';
	
		if ( id == 'veiculomarca' ) {
			// Valor do filtro (igual ao parametro tipo neste caso)
			vlr = this.veiculotipo;
			txtCombo  = 'Selecione a marca';
			txtCombo2 = 'Selecione o modelo';
			id2 = 'veiculomodelo';
		} else if ( id == 'veiculomodelo' ) {
			// Valor do filtro (valor da marca)
			vlr = frm.veiculomarca.value;;
			txtCombo = 'Selecione o modelo';
		}
	
		// recupera valores de filtro
		cidade = 0;
	
		carregaCombosTipoMarcaModelo ( id, this.veiculotipo, categoria, vlr, vlrDefault, txtCombo, id2, txtCombo2, vlrDefault2, '', '', 0 );
	}
}

$( function(){
    // adiciona mascara aos campos
    // data
    $("input.date").setMask('date');
    $("#conjcpf").setMask('cpf');
    // valor
    $("input.valor").setMask('decimal');
    // cep
    $("input.cep").setMask('cep');
    // telefone
    $("input.tel").setMask({mask:'9999-9999'});

    $("#cpfcnpj").setMask('cpf').val('');
    $("#tipopessoa").change(function(){
        if ( $(this).val() == 'J' ) {
            $("#cpfcnpj").setMask('cnpj').val('');
        } else {
            $("#cpfcnpj").setMask('cpf').val('');
        }
    });
});

