function CtrCombustivel() {

	var autoReferencia = this;
	this.setAutoReferencia(this);
	
	this.setId("CtrCombustivel");

	this.instanciarLimite = function() {
		return new LimCombustivel(this);
	}

	this.inicializa = function() {
		
	}
	

	this.montaEntCombustivel = function() {
		var entCombustivel = new EntCombustivel();
		var limite = this.getLimite();
		var num = new Numero(); 
		 
		entCombustivel.setAtivo(limite.getRadioSituacao());
		entCombustivel.setNome(limite.getCampoNome());
		entCombustivel.setUnidade(limite.getCampoUnidade());
		entCombustivel.setCusto(num.formataNumeroParaServidor(limite.getCampoCusto()));
		
		return entCombustivel;
	}
	this.altera = function(codigo) {
		var entCombustivel = this.montaEntCombustivel();
		entCombustivel.setCodigo(codigo);

		new DeptoVeiculos().altera(entCombustivel, this.retornoCadastro);
	}

	
	this.salva = function() {
		var entCombustivel = this.montaEntCombustivel();

		new DeptoVeiculos().cadastra(entCombustivel, this.retornoCadastro); 
	}
	
	this.retornoCadastro = function(resposta) {
		if (autoReferencia.trataRespostaServidor(resposta.codErro, resposta.mensagem, true)) {
			if (resposta.dados[0] != "") {
				autoReferencia.getLimite().limpaHtml();
			}  
		}
	}	
	
	// Implementacao utilizando a nova interface de pesquisa generica (PesquisaSimples). 
	this.pesquisaCombustivel = function() {
		var ctrPesquisaSimples = aplicativo.getControlador("CtrPesquisaSimples");
		ctrPesquisaSimples.setDepto("DeptoVeiculos()");
		ctrPesquisaSimples.setPesquisa("Combustivel");
		ctrPesquisaSimples.setControladorRequisitante("CtrCombustivel");
		ctrPesquisaSimples.abrirJanela();
	}
	
	// Todos as pesquisas genericas dessa interface devem usar sempre esse metodo como retorno das pesquisas. 
	this.retornoPesquisas = function(codigo, descricao, pesquisa) {
		if (pesquisa == "Combustivel") {
			var entCombustivel = new EntCombustivel();
			entCombustivel.setCodigo(codigo);
			new DeptoVeiculos().busca(entCombustivel, this.retornoBuscaCombustivel);	
			
		} else {
			this.getLimite().mostrarMensagem("alerta", PESQUISA_NAO_RECONHECIDA);
		}
	}
	
	this.retornoBuscaCombustivel = function(resposta) {
		var	limite = autoReferencia.getLimite()
		
		if (autoReferencia.trataRespostaServidor(resposta.codErro, resposta.mensagem, false)) {
			if (resposta.dados != undefined) {
				autoReferencia.mostraDadosCombustivel(resposta.dados[0]);
			}
			else {
				//limite.limpaColaborador();
			}
		}
	}

	this.mostraDadosCombustivel = function(resposta) {
		var limite = this.getLimite();
		
		limite.setCampoCodigoCombustivel(resposta.codigo);
		limite.setCampoNome(resposta.nome);
		limite.setCampoUnidade(resposta.unidade);
		limite.setCampoCusto(new Numero().formataNumeroParaCliente(resposta.custo, 2));
		limite.setRadioSituacao(resposta.ativo);
	}
	
}
CtrCombustivel.prototype = new Controlador;